Improved does_script_exist() and local editor (#1265)
This commit is contained in:
parent
99bbe9ae1c
commit
530a798d62
@ -19,13 +19,7 @@ namespace big
|
|||||||
|
|
||||||
bool locals_service::does_script_exist(std::string script_name)
|
bool locals_service::does_script_exist(std::string script_name)
|
||||||
{
|
{
|
||||||
// TODO: find a better way to check script validity
|
return SCRIPT::DOES_SCRIPT_WITH_NAME_HASH_EXIST(rage::joaat(script_name));
|
||||||
|
|
||||||
for (auto s : all_script_names)
|
|
||||||
if (script_name == s)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path locals_service::get_path()
|
std::filesystem::path locals_service::get_path()
|
||||||
@ -48,14 +42,15 @@ namespace big
|
|||||||
{
|
{
|
||||||
if (!l.key().empty())
|
if (!l.key().empty())
|
||||||
{
|
{
|
||||||
local new_local{"", "", 0, 0, 0, 0};
|
local new_local{"", "", 0, 0, 0, 0, 0};
|
||||||
new_local.m_base_address = j[l.key()]["base_address"];
|
new_local.m_base_address = j[l.key()]["base_address"];
|
||||||
std::string script_name = j[l.key()]["script_thread_name"];
|
std::string script_name = j[l.key()]["script_thread_name"];
|
||||||
strcpy(new_local.m_script_thread_name, script_name.data());
|
strcpy(new_local.m_script_thread_name, script_name.data());
|
||||||
new_local.m_freeze = j[l.key()]["freeze"];
|
new_local.m_freeze = j[l.key()]["freeze"];
|
||||||
std::string name = j[l.key()]["name"];
|
std::string name = j[l.key()]["name"];
|
||||||
strcpy(new_local.m_name, name.data());
|
strcpy(new_local.m_name, name.data());
|
||||||
new_local.m_value = j[l.key()]["value"];
|
new_local.m_value = j[l.key()]["value"];
|
||||||
|
new_local.m_edit_mode = j[l.key()].value<int>("editmode", 0);
|
||||||
if (!j[l.key()]["offsets"].is_null())
|
if (!j[l.key()]["offsets"].is_null())
|
||||||
{
|
{
|
||||||
for (const auto& offset : j[l.key()]["offsets"].items())
|
for (const auto& offset : j[l.key()]["offsets"].items())
|
||||||
@ -101,6 +96,7 @@ namespace big
|
|||||||
j[l.first]["freeze"] = l.second.m_freeze;
|
j[l.first]["freeze"] = l.second.m_freeze;
|
||||||
j[l.first]["name"] = l.second.m_name;
|
j[l.first]["name"] = l.second.m_name;
|
||||||
j[l.first]["value"] = l.second.m_value;
|
j[l.first]["value"] = l.second.m_value;
|
||||||
|
j[l.first]["editmode"] = l.second.m_edit_mode;
|
||||||
|
|
||||||
for (int i = 0; i < l.second.m_offsets.size(); i++)
|
for (int i = 0; i < l.second.m_offsets.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -33,10 +33,14 @@ namespace big
|
|||||||
char m_name[200];
|
char m_name[200];
|
||||||
std::vector<local_offset> m_offsets;
|
std::vector<local_offset> m_offsets;
|
||||||
int m_value;
|
int m_value;
|
||||||
int m_freeze_value;
|
int m_freeze_value_int;
|
||||||
|
float m_freeze_value_float;
|
||||||
|
Vector3 m_freeze_value_vector3;
|
||||||
int* m_internal_address;
|
int* m_internal_address;
|
||||||
|
Vector3* m_internal_address_vector3;
|
||||||
|
int m_edit_mode = 0;
|
||||||
|
|
||||||
local(const char* script_thread_name, const char* name, const int base_address, const bool freeze, const int (*offsets)[2], int offset_count)
|
local(const char* script_thread_name, const char* name, const int base_address, const bool freeze, const int (*offsets)[2], int offset_count, int edit_mode = 0)
|
||||||
{
|
{
|
||||||
m_internal_id = ++m_instance_count;
|
m_internal_id = ++m_instance_count;
|
||||||
|
|
||||||
@ -49,6 +53,8 @@ namespace big
|
|||||||
for (int i = 0; i < offset_count; i++)
|
for (int i = 0; i < offset_count; i++)
|
||||||
m_offsets.push_back(local_offset(offsets[i][0], offsets[i][1]));
|
m_offsets.push_back(local_offset(offsets[i][0], offsets[i][1]));
|
||||||
|
|
||||||
|
m_edit_mode = edit_mode;
|
||||||
|
|
||||||
fetch_local_pointer();
|
fetch_local_pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +79,28 @@ namespace big
|
|||||||
actual_local = actual_local.at(offset.m_offset);
|
actual_local = actual_local.at(offset.m_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_internal_address = actual_local.as<int*>();
|
m_internal_address = actual_local.as<int*>();
|
||||||
|
m_internal_address_vector3 = actual_local.as<Vector3*>();
|
||||||
|
|
||||||
return m_internal_address;
|
return m_internal_address;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* get_local_chain_text()
|
||||||
|
{
|
||||||
|
static char offsetschain[200] = "";
|
||||||
|
strcpy(offsetschain, "");
|
||||||
|
strcat(offsetschain, std::to_string(m_base_address).data());
|
||||||
|
for (auto o : m_offsets)
|
||||||
|
{
|
||||||
|
strcat(offsetschain, std::string(".f_" + std::to_string(o.m_offset)).data());
|
||||||
|
if (o.m_size)
|
||||||
|
strcat(offsetschain, std::string("/" + std::to_string(o.m_size)).data());
|
||||||
|
}
|
||||||
|
return offsetschain;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline static int m_instance_count;
|
inline static int m_instance_count;
|
||||||
int m_internal_id;
|
int m_internal_id;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "gui/components/components.hpp"
|
#include "gui/components/components.hpp"
|
||||||
#include "services/locals/locals_service.hpp"
|
#include "services/locals/locals_service.hpp"
|
||||||
#include "view_debug.hpp"
|
#include "view_debug.hpp"
|
||||||
|
#include "widgets/imgui_bitfield.hpp"
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
@ -60,6 +61,8 @@ namespace big
|
|||||||
if (locals_service::does_script_exist(script_thread_name))
|
if (locals_service::does_script_exist(script_thread_name))
|
||||||
{
|
{
|
||||||
auto new_local = local(script_thread_name, name, base_address, freeze, offsets, offset_count);
|
auto new_local = local(script_thread_name, name, base_address, freeze, offsets, offset_count);
|
||||||
|
if (std::string(name).empty())
|
||||||
|
strcpy(name, new_local.get_local_chain_text());
|
||||||
g_locals_service.m_locals.push_back(new_local);
|
g_locals_service.m_locals.push_back(new_local);
|
||||||
|
|
||||||
reset_values();
|
reset_values();
|
||||||
@ -99,66 +102,133 @@ namespace big
|
|||||||
{
|
{
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::PushID(local_.get_id());
|
ImGui::PushID(local_.get_id());
|
||||||
|
ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
|
||||||
ImGui::Text("%s : %s", local_.m_name, local_.m_script_thread_name);
|
if (ImGui::TreeNode(strcmp(local_.m_name, "") == 0 ?
|
||||||
if (ImGui::IsItemHovered())
|
std::string(local_.m_script_thread_name + std::string(" ")).append(local_.get_local_chain_text()).data(): local_.m_name))
|
||||||
{
|
{
|
||||||
ImGui::BeginTooltip();
|
ImGui::Text("%s : %s", local_.m_script_thread_name, local_.m_name);
|
||||||
char offsetschain[200] = "";
|
if (ImGui::IsItemHovered())
|
||||||
strcat(offsetschain, std::to_string(local_.m_base_address).data());
|
|
||||||
for (auto o : local_.m_offsets)
|
|
||||||
{
|
{
|
||||||
strcat(offsetschain, std::string(".f_" + std::to_string(o.m_offset)).data());
|
ImGui::BeginTooltip();
|
||||||
if (o.m_size)
|
ImGui::Text(local_.get_local_chain_text());
|
||||||
strcat(offsetschain, std::string("/" + std::to_string(o.m_size)).data());
|
ImGui::EndTooltip();
|
||||||
}
|
}
|
||||||
ImGui::Text(offsetschain);
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Find the thread among the script threads
|
//Find the thread among the script threads
|
||||||
if (!local_.m_script_thread)
|
if (!local_.m_script_thread)
|
||||||
local_.m_script_thread = gta_util::find_script_thread(rage::joaat(local_.m_script_thread_name));
|
local_.m_script_thread = gta_util::find_script_thread(rage::joaat(local_.m_script_thread_name));
|
||||||
|
|
||||||
if (local_.m_script_thread && locals_service::is_script_thread_running(local_.m_script_thread))
|
if (local_.m_script_thread && locals_service::is_script_thread_running(local_.m_script_thread))
|
||||||
{
|
|
||||||
//Check whether the address is found
|
|
||||||
if (local_.m_internal_address)
|
|
||||||
{
|
{
|
||||||
ImGui::Text("Value");
|
//Check whether the address is found
|
||||||
ImGui::SetNextItemWidth(200);
|
if (local_.m_internal_address)
|
||||||
if (ImGui::InputInt("##local_value", local_.m_internal_address))
|
|
||||||
{
|
{
|
||||||
local_.m_value = *local_.m_internal_address;
|
if (ImGui::RadioButton("Int", local_.m_edit_mode == 0))
|
||||||
}
|
local_.m_edit_mode = 0;
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Checkbox("Freeze", &local_.m_freeze))
|
if (ImGui::RadioButton("Float", local_.m_edit_mode == 1))
|
||||||
local_.m_freeze_value = *local_.m_internal_address;
|
local_.m_edit_mode = 1;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Bitfield", local_.m_edit_mode == 2))
|
||||||
|
local_.m_edit_mode = 2;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Vector3", local_.m_edit_mode == 3))
|
||||||
|
local_.m_edit_mode = 3;
|
||||||
|
|
||||||
if (local_.m_freeze)
|
|
||||||
*local_.m_internal_address = local_.m_freeze_value;
|
ImGui::LabelText(local_.get_local_chain_text(), "Value");
|
||||||
|
|
||||||
|
ImGui::SetNextItemWidth(200);
|
||||||
|
|
||||||
|
switch (local_.m_edit_mode)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
|
||||||
|
if (ImGui::InputInt("##local_value",
|
||||||
|
local_.m_freeze ? &local_.m_freeze_value_int : local_.m_internal_address))
|
||||||
|
{
|
||||||
|
local_.m_value = *local_.m_internal_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_.m_freeze)
|
||||||
|
{
|
||||||
|
*local_.m_internal_address = local_.m_freeze_value_int;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
if (ImGui::InputFloat("##local_value",
|
||||||
|
local_.m_freeze ? &local_.m_freeze_value_float : (float*)local_.m_internal_address))
|
||||||
|
{
|
||||||
|
local_.m_value = *local_.m_internal_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_.m_freeze)
|
||||||
|
{
|
||||||
|
*local_.m_internal_address = local_.m_freeze_value_int;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
|
||||||
|
if (ImGui::Bitfield("##local_value",
|
||||||
|
local_.m_freeze ? &local_.m_freeze_value_int : local_.m_internal_address))
|
||||||
|
{
|
||||||
|
local_.m_value = *local_.m_internal_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_.m_freeze)
|
||||||
|
{
|
||||||
|
*local_.m_internal_address = local_.m_freeze_value_float;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
ImGui::SetNextItemWidth(300);
|
||||||
|
if (ImGui::InputFloat3("##local_value",
|
||||||
|
local_.m_freeze ? (float*)&local_.m_freeze_value_vector3 : (float*)local_.m_internal_address))
|
||||||
|
{
|
||||||
|
local_.m_value = *local_.m_internal_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_.m_freeze)
|
||||||
|
{
|
||||||
|
*local_.m_internal_address_vector3 = local_.m_freeze_value_vector3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Checkbox("Freeze", &local_.m_freeze))
|
||||||
|
{
|
||||||
|
local_.m_freeze_value_int = *local_.m_internal_address;
|
||||||
|
local_.m_freeze_value_float = (float)*local_.m_internal_address;
|
||||||
|
local_.m_freeze_value_vector3 = *local_.m_internal_address_vector3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (components::button("Fetch"))
|
||||||
|
{
|
||||||
|
local_.fetch_local_pointer();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (components::button("Fetch"))
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||||
{
|
ImGui::Text("%s isn't running", local_.m_script_thread_name);
|
||||||
local_.fetch_local_pointer();
|
ImGui::PopStyleColor();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
if (components::button("Delete"))
|
||||||
else
|
std::erase_if(g_locals_service.m_locals, [local_](local l) {
|
||||||
{
|
return l.get_id() == local_.get_id();
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
});
|
||||||
ImGui::Text("%s isn't running", local_.m_script_thread_name);
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
}
|
|
||||||
if (components::button("Delete"))
|
|
||||||
std::erase_if(g_locals_service.m_locals, [local_](local l) {
|
|
||||||
return l.get_id() == local_.get_id();
|
|
||||||
});
|
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user