2023-04-11 21:36:43 +02:00
|
|
|
#include "gui/components/components.hpp"
|
|
|
|
#include "services/locals/locals_service.hpp"
|
2022-10-21 22:05:39 +02:00
|
|
|
#include "view_debug.hpp"
|
2023-04-20 21:07:16 +02:00
|
|
|
#include "widgets/imgui_bitfield.hpp"
|
2022-10-21 22:05:39 +02:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2023-04-11 21:36:43 +02:00
|
|
|
|
|
|
|
void render_local_creator_popup_content()
|
|
|
|
{
|
|
|
|
static int base_address = 0;
|
|
|
|
static bool freeze = false;
|
|
|
|
static char name[200] = "";
|
|
|
|
static char script_thread_name[200] = "";
|
2023-04-16 18:28:49 +00:00
|
|
|
static int offsets[10][2] = {};
|
2023-04-11 21:36:43 +02:00
|
|
|
static int offset_count = 0;
|
|
|
|
static int previous_offset_count = 0;
|
2023-10-20 12:24:44 -04:00
|
|
|
components::input_text("NAME"_T, name, sizeof(name));
|
|
|
|
components::input_text("VIEW_DEBUG_LOCALS_SCRIPT_NAME"_T, script_thread_name, sizeof(script_thread_name));
|
|
|
|
ImGui::Text("VIEW_DEBUG_LOCALS_BASE_ADDRESS"_T.data());
|
2023-04-11 21:36:43 +02:00
|
|
|
ImGui::InputInt("##local_base_address", &base_address);
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::Text("VIEW_DEBUG_LOCALS_OFFSET_COUNT"_T.data());
|
2023-04-11 21:36:43 +02:00
|
|
|
ImGui::InputInt("##modal_offset_count", &offset_count);
|
|
|
|
|
2023-04-16 18:28:49 +00:00
|
|
|
offset_count = std::clamp(offset_count, 0, 10);
|
2023-04-11 21:36:43 +02:00
|
|
|
|
|
|
|
ImGui::PushItemWidth(320.f);
|
|
|
|
for (int i = 0; i < offset_count; i++)
|
|
|
|
{
|
|
|
|
ImGui::PushID(i);
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
ImGui::Text("DEBUG_GLOBAL_OFFSET"_T.data(), i + 1);
|
|
|
|
ImGui::InputInt("##offset", &offsets[i][0]);
|
|
|
|
|
|
|
|
ImGui::Text("DEBUG_GLOBAL_SIZE"_T.data());
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::InputInt("##size", &offsets[i][1]);
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
static auto reset_values = []() -> void {
|
|
|
|
strcpy(name, "");
|
2023-04-16 18:28:49 +00:00
|
|
|
freeze = false;
|
2023-04-11 21:36:43 +02:00
|
|
|
offset_count = 0;
|
|
|
|
previous_offset_count = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (components::button("CANCEL"_T))
|
|
|
|
{
|
|
|
|
reset_values();
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (components::button("SAVE"_T))
|
|
|
|
{
|
|
|
|
if (locals_service::does_script_exist(script_thread_name))
|
|
|
|
{
|
|
|
|
auto new_local = local(script_thread_name, name, base_address, freeze, offsets, offset_count);
|
2023-04-20 21:07:16 +02:00
|
|
|
if (std::string(name).empty())
|
|
|
|
strcpy(name, new_local.get_local_chain_text());
|
2023-04-11 21:36:43 +02:00
|
|
|
g_locals_service.m_locals.push_back(new_local);
|
|
|
|
|
|
|
|
reset_values();
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
g_notification_service->push_error("DEBUG_TAB_LOCALS"_T.data(), "VIEW_DEBUG_LOCALS_SCRIPT_DOES_NOT_EXIST"_T.data());
|
2023-04-11 21:36:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-21 22:05:39 +02:00
|
|
|
void debug::locals()
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
if (ImGui::BeginTabItem("DEBUG_TAB_LOCALS"_T.data()))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
2023-04-11 21:36:43 +02:00
|
|
|
if (components::button("LOAD"_T))
|
|
|
|
g_locals_service.load();
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (components::button("SAVE"_T))
|
|
|
|
g_locals_service.save();
|
|
|
|
|
2023-10-20 12:24:44 -04:00
|
|
|
if (components::button("VIEW_DEBUG_LOCALS_ADD_LOCAL"_T))
|
2023-04-11 21:36:43 +02:00
|
|
|
{
|
|
|
|
ImGui::OpenPopup("##addlocal");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginPopupModal("##addlocal"))
|
|
|
|
{
|
|
|
|
render_local_creator_popup_content();
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& local_ : g_locals_service.m_locals)
|
|
|
|
{
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
ImGui::PushID(local_.get_id());
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
|
|
|
|
if (ImGui::TreeNode(strcmp(local_.m_name, "") == 0 ?
|
|
|
|
std::string(local_.m_script_thread_name + std::string(" ")).append(local_.get_local_chain_text()).data(): local_.m_name))
|
2023-04-11 21:36:43 +02:00
|
|
|
{
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::Text("%s : %s", local_.m_script_thread_name, local_.m_name);
|
|
|
|
if (ImGui::IsItemHovered())
|
2023-04-11 21:36:43 +02:00
|
|
|
{
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::BeginTooltip();
|
|
|
|
ImGui::Text(local_.get_local_chain_text());
|
|
|
|
ImGui::EndTooltip();
|
2023-04-11 21:36:43 +02:00
|
|
|
}
|
|
|
|
|
2023-04-20 21:07:16 +02:00
|
|
|
//Find the thread among the script threads
|
|
|
|
if (!local_.m_script_thread)
|
|
|
|
local_.m_script_thread = gta_util::find_script_thread(rage::joaat(local_.m_script_thread_name));
|
2023-04-11 21:36:43 +02:00
|
|
|
|
2023-04-20 21:07:16 +02:00
|
|
|
if (local_.m_script_thread && locals_service::is_script_thread_running(local_.m_script_thread))
|
2023-04-11 21:36:43 +02:00
|
|
|
{
|
2023-04-20 21:07:16 +02:00
|
|
|
//Check whether the address is found
|
|
|
|
if (local_.m_internal_address)
|
2023-04-11 21:36:43 +02:00
|
|
|
{
|
2023-04-20 21:07:16 +02:00
|
|
|
if (ImGui::RadioButton("Int", local_.m_edit_mode == 0))
|
|
|
|
local_.m_edit_mode = 0;
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::RadioButton("Float", local_.m_edit_mode == 1))
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::LabelText(local_.get_local_chain_text(), "VIEW_DEBUG_GLOBAL_VALUE"_T.data());
|
2023-04-20 21:07:16 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-07-23 13:54:01 -04:00
|
|
|
*(float*)local_.m_internal_address = local_.m_freeze_value_float;
|
2023-04-20 21:07:16 +02:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2023-07-23 12:38:22 -04:00
|
|
|
*local_.m_internal_address = local_.m_freeze_value_int;
|
2023-04-20 21:07:16 +02:00
|
|
|
}
|
|
|
|
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();
|
2023-10-20 12:24:44 -04:00
|
|
|
if (ImGui::Checkbox("VIEW_DEBUG_LOCALS_FREEZE"_T.data(), &local_.m_freeze))
|
2023-04-20 21:07:16 +02:00
|
|
|
{
|
|
|
|
local_.m_freeze_value_int = *local_.m_internal_address;
|
2023-07-23 13:54:01 -04:00
|
|
|
local_.m_freeze_value_float = *reinterpret_cast<float*>(local_.m_internal_address);
|
2023-04-20 21:07:16 +02:00
|
|
|
local_.m_freeze_value_vector3 = *local_.m_internal_address_vector3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
if (components::button("VIEW_DEBUG_LOCALS_FETCH"_T))
|
2023-04-20 21:07:16 +02:00
|
|
|
{
|
|
|
|
local_.fetch_local_pointer();
|
|
|
|
}
|
2023-04-11 21:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::Text(std::format("{} {}", local_.m_script_thread_name, "VIEW_DEBUG_LOCALS_SCRIPT_IS_NOT_RUNNING"_T).c_str());
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::PopStyleColor();
|
2023-04-11 21:36:43 +02:00
|
|
|
}
|
2023-10-20 12:24:44 -04:00
|
|
|
if (components::button("DELETE"_T))
|
2023-04-20 21:07:16 +02:00
|
|
|
std::erase_if(g_locals_service.m_locals, [local_](local l) {
|
|
|
|
return l.get_id() == local_.get_id();
|
|
|
|
});
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
ImGui::Separator();
|
2023-04-11 21:36:43 +02:00
|
|
|
|
2023-04-20 21:07:16 +02:00
|
|
|
ImGui::TreePop();
|
|
|
|
}
|
2023-04-11 21:36:43 +02:00
|
|
|
ImGui::EndGroup();
|
|
|
|
}
|
|
|
|
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|