Fix crashes with cloth picker and more fixes

This commit is contained in:
Grinch_ 2021-07-17 19:42:09 +06:00
parent c1c4951e85
commit acedf1a14c
11 changed files with 125 additions and 43 deletions

2
.gitignore vendored
View File

@ -68,3 +68,5 @@ Depend/x64/Debug/Depend.tlog/CL.command.1.tlog
Depend/x64/Debug/Depend.tlog/CL.read.1.tlog
Depend/x64/Debug/Depend.tlog/CL.write.1.tlog
Depend/x64/Debug/Depend.tlog/Depend.lastbuildstate
CheatMenu/CheatMenu/json/versioninfo.json
CheatMenu/CheatMenu/json/config.json

Binary file not shown.

View File

@ -4,7 +4,6 @@
"Stepsit_loop": "ATTRACTORS",
"Stepsit_out": "ATTRACTORS"
},
"All": {},
"BAR": {
"BARman_idle": "BAR",
"Barcustom_get": "BAR",

View File

@ -1,5 +1,4 @@
{
"All": {},
"Arena missions": {
"Beat the Cock!": "130",
"Blood Ring": "128",

View File

@ -1,5 +1,5 @@
{
"All": {
"Misc": {
"120": "People wasted by others",
"121": "People you've wasted",
"131": "Total number of wanted stars attained",

View File

@ -1,5 +1,4 @@
{
"All": {},
"Bribes": {
"Bribe 1": "0, 2743, 1316, 8",
"Bribe 10": "0, 1592.91, 2053.83, 10.26",

View File

@ -5,6 +5,29 @@
#include "Ui.h"
#include "Util.h"
// hardcoded cloth category names
const char* cloth_category[18] =
{
"Shirts", // 0
"Heads", // 1
"Trousers", // 2
"Shoes", //3
"Tattoos left lower arm", // 4
"Tattoos left upper arm", // 5
"Tattoos right upper arm", // 6
"Tattoos right lower arm", // 7
"Tattoos back", // 8
"Tattoos left chest", // 9
"Tattoos right chest", // 10
"Tattoos stomach", // 11
"Tattoos lower back", // 12
"Necklaces", // 13
"Watches", // 13
"Glasses", // 15
"Hats", // 16
"Extras" // 17
};
inline static void PlayerModelBrokenFix()
{
CPlayerPed* pPlayer = FindPlayerPed();
@ -50,7 +73,7 @@ Player::Player()
if (!m_bImagesLoaded)
{
Util::LoadTextureDirectory(m_ClothData, PLUGIN_PATH((char*)"CheatMenu\\clothes.txd"));
Util::LoadTextureDirectory(m_ClothData, PLUGIN_PATH((char*)"CheatMenu\\clothes.txd"), true);
m_bImagesLoaded = true;
}
@ -383,7 +406,7 @@ void Player::Draw()
getline(ss, temp, '$');
return temp;
});
}, nullptr, cloth_category, sizeof(cloth_category)/ sizeof(const char*));
}
else
{

View File

@ -28,8 +28,6 @@ bool Ui::ListBoxStr(const char* label, std::vector<std::string>& all_items, std:
if (ImGui::BeginCombo(label, selected.c_str()))
{
for (std::string current_item : all_items)
{
if (current_item != label)
{
if (ImGui::MenuItem(current_item.c_str()))
{
@ -37,13 +35,39 @@ bool Ui::ListBoxStr(const char* label, std::vector<std::string>& all_items, std:
rtn = true;
}
}
}
ImGui::EndCombo();
}
return rtn;
}
bool Ui::ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* custom_names[], size_t length)
{
bool rtn = false;
std::string display_selected = (selected == "All") ? selected: custom_names[std::stoi(selected)];
if (ImGui::BeginCombo(label, display_selected.c_str()))
{
if (ImGui::MenuItem("All"))
{
selected = "All";
rtn = true;
}
for (size_t i = 0; i < length; ++i)
{
if (ImGui::MenuItem(custom_names[i]))
{
selected = std::to_string(i);
rtn = true;
break;
}
}
ImGui::EndCombo();
}
return rtn;
}
ImVec2 Ui::GetSize(short count, bool spacing)
{
if (count == 1)
@ -462,7 +486,7 @@ void Ui::DrawImages(std::vector<std::unique_ptr<STextureStructure>>& img_vec, Im
std::vector<std::string>& category_vec, std::string& selected_item, ImGuiTextFilter& filter,
std::function<void(std::string&)> on_left_click, std::function<void(std::string&)> on_right_click,
std::function<std::string(std::string&)> get_name_func,
std::function<bool(std::string&)> verify_func)
std::function<bool(std::string&)> verify_func, const char** custom_names, size_t length)
{
// scale image size
image_size.x *= screen::GetScreenWidth() / 1366.0f;
@ -480,7 +504,15 @@ void Ui::DrawImages(std::vector<std::unique_ptr<STextureStructure>>& img_vec, Im
imgPopup.function = nullptr;
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() / 2 - 5);
if (custom_names)
{
ListBoxCustomNames("##Categories", category_vec, selected_item, custom_names, length);
}
else
{
ListBoxStr("##Categories", category_vec, selected_item);
}
ImGui::SameLine();
FilterWithHint("##Filter", filter, "Search");

View File

@ -57,7 +57,8 @@ public:
std::function<void(std::string&)> on_left_click,
std::function<void(std::string&)> on_right_click,
std::function<std::string(std::string&)> get_name_func,
std::function<bool(std::string&)> verify_func = nullptr);
std::function<bool(std::string&)> verify_func = nullptr,
const char** custom_names = nullptr, size_t length = 0);
template <typename T>
static void EditAddress(const char* label, int address, int min = 0, int def = 0, int max = 100);
@ -79,6 +80,7 @@ public:
static bool ListBox(const char* label, std::vector<std::string>& all_items, int& selected);
static bool ListBoxStr(const char* label, std::vector<std::string>& all_items, std::string& selected);
static bool ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0);
static void RadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem);
static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val);

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "Util.h"
#include "../Depend/imgui/stb_image.h"
#include <CCutsceneMgr.h>
#include "psapi.h"
#include "CFileLoader.h"
@ -29,13 +28,16 @@ struct RwRasterEx : public RwRaster
RwD3D9Raster *renderResource;
};
void Util::LoadTextureDirectory(SSearchData& data, char *path)
void Util::LoadTextureDirectory(SSearchData& data, char *path, bool pass_full_name)
{
RwTexDictionary* pRwTexDictionary = &data.txd;
pRwTexDictionary = CFileLoader::LoadTexDictionary(path);
if (pRwTexDictionary)
{
// FIX ME
if (pass_full_name)
{
RwTexDictionaryForAllTextures(pRwTexDictionary, [](RwTexture* tex, void* data)
{
@ -47,6 +49,30 @@ void Util::LoadTextureDirectory(SSearchData& data, char *path)
std::stringstream ss(tex->name);
std::string str;
getline(ss, str, '$');
sdata->m_ImagesList.back().get()->m_CategoryName = str;
if (!std::count(sdata->m_Categories.begin(), sdata->m_Categories.end(), str))
{
sdata->m_Categories.push_back(str);
}
sdata->m_ImagesList.back().get()->m_FileName = tex->name;
return tex;
}, &data);
}
else
{
RwTexDictionaryForAllTextures(pRwTexDictionary, [](RwTexture* tex, void* data)
{
SSearchData* sdata = reinterpret_cast<SSearchData*>(data);
sdata->m_ImagesList.push_back(std::make_unique<STextureStructure>());
sdata->m_ImagesList.back().get()->m_pRwTexture = tex;
sdata->m_ImagesList.back().get()->m_pTexture = GetTextureFromRaster(tex);
std::stringstream ss(tex->name);
std::string str;
getline(ss, str, '$');
sdata->m_ImagesList.back().get()->m_CategoryName = str;
if (!std::count(sdata->m_Categories.begin(), sdata->m_Categories.end(), str))
{
@ -56,10 +82,10 @@ void Util::LoadTextureDirectory(SSearchData& data, char *path)
sdata->m_ImagesList.back().get()->m_FileName = str;
return tex;
}, &data);
}
}
}
void* Util::GetTextureFromRaster(RwTexture *pTexture)
{

View File

@ -22,6 +22,6 @@ public:
static void GetCPUUsageInit();
static double GetCurrentCPUUsage();
static void* GetTextureFromRaster(RwTexture* pTexture);
static void LoadTextureDirectory(SSearchData& data, char* path);
static void LoadTextureDirectory(SSearchData& data, char* path, bool pass_full_name = false);
static RwTexture* LoadTextureFromMemory(char* data, unsigned int size);
};