Skip to content

Commit

Permalink
Added support for watching local script variables in version 372
Browse files Browse the repository at this point in the history
+ Added a start for Comms mod
+ Changed some default settings
+Made a memory watcher for local and global variables
+ Improved handling of memory variables
  • Loading branch information
Rayope committed May 22, 2021
1 parent 3ec4eee commit 03b075d
Show file tree
Hide file tree
Showing 26 changed files with 795 additions and 383 deletions.
7 changes: 5 additions & 2 deletions ImGTA/ImGTA.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ copy "$(SolutionDir)lua\lua53.dll" "E:\Grand Theft Auto V"</Command>
<ClCompile Include="anim_dict.cpp" />
<ClCompile Include="area_mod.cpp" />
<ClCompile Include="cheats_mod.cpp" />
<ClCompile Include="comms_mod.cpp" />
<ClCompile Include="cutscene_mod.cpp" />
<ClCompile Include="global_watch_mod.cpp" />
<ClCompile Include="gta_script.cpp" />
<ClCompile Include="handle_helper_mod.cpp" />
<ClCompile Include="imgui_extras.cpp" />
<ClCompile Include="lua_console_mod.cpp" />
<ClCompile Include="lua_engine.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="mem_watcher_mod.cpp" />
<ClCompile Include="mission_helper.cpp" />
<ClCompile Include="mission_mod.cpp" />
<ClCompile Include="mod.cpp" />
Expand All @@ -212,14 +213,16 @@ copy "$(SolutionDir)lua\lua53.dll" "E:\Grand Theft Auto V"</Command>
<ClInclude Include="area_mod.h" />
<ClInclude Include="audio_scenes.h" />
<ClInclude Include="cheats_mod.h" />
<ClInclude Include="comms_mod.h" />
<ClInclude Include="cutscene_mod.h" />
<ClInclude Include="cutscene_names.h" />
<ClInclude Include="global_watch_mod.h" />
<ClInclude Include="global_id.h" />
<ClInclude Include="gta_script.h" />
<ClInclude Include="handle_helper_mod.h" />
<ClInclude Include="imgui_extras.h" />
<ClInclude Include="input_controls.h" />
<ClInclude Include="lua_console_mod.h" />
<ClInclude Include="mem_watcher_mod.h" />
<ClInclude Include="mission_helper.h" />
<ClInclude Include="mission_mod.h" />
<ClInclude Include="script_infos.h" />
Expand Down
42 changes: 27 additions & 15 deletions ImGTA/ImGTA.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<Filter Include="ImGui">
<UniqueIdentifier>{428fc954-c067-4292-877f-75e68df3061d}</UniqueIdentifier>
</Filter>
<Filter Include="Mods\Global Watch">
<UniqueIdentifier>{0c2141f1-ad67-4e26-bf75-aee59af5e18a}</UniqueIdentifier>
</Filter>
<Filter Include="Mods\Cheats">
<UniqueIdentifier>{b2db65e6-29cc-4eec-9083-d3f6885a62f9}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -54,6 +51,12 @@
<Filter Include="Mods\Area">
<UniqueIdentifier>{e1967f6c-73e3-450c-ae1f-2cf74d20cdca}</UniqueIdentifier>
</Filter>
<Filter Include="Mods\Memory Watcher">
<UniqueIdentifier>{a8778da9-053a-49cd-9aef-c68360d37fbc}</UniqueIdentifier>
</Filter>
<Filter Include="Mods\Comms">
<UniqueIdentifier>{4659fcf2-47a9-42f1-9f30-8eeaa7a1f23c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand All @@ -68,12 +71,6 @@
<ClCompile Include="utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="global_watch_mod.cpp">
<Filter>Mods\Global Watch</Filter>
</ClCompile>
<ClCompile Include="watch_entry.cpp">
<Filter>Mods\Global Watch</Filter>
</ClCompile>
<ClCompile Include="cheats_mod.cpp">
<Filter>Mods\Cheats</Filter>
</ClCompile>
Expand Down Expand Up @@ -146,6 +143,15 @@
<ClCompile Include="..\imgui\backends\imgui_impl_win32.cpp">
<Filter>ImGui</Filter>
</ClCompile>
<ClCompile Include="watch_entry.cpp">
<Filter>Mods\Memory Watcher</Filter>
</ClCompile>
<ClCompile Include="mem_watcher_mod.cpp">
<Filter>Mods\Memory Watcher</Filter>
</ClCompile>
<ClCompile Include="comms_mod.cpp">
<Filter>Mods\Comms</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="script.h">
Expand All @@ -157,12 +163,6 @@
<ClInclude Include="utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="global_watch_mod.h">
<Filter>Mods\Global Watch</Filter>
</ClInclude>
<ClInclude Include="watch_entry.h">
<Filter>Mods\Global Watch</Filter>
</ClInclude>
<ClInclude Include="cheats_mod.h">
<Filter>Mods\Cheats</Filter>
</ClInclude>
Expand Down Expand Up @@ -253,6 +253,18 @@
<ClInclude Include="script_names.h">
<Filter>Mods\Scripts</Filter>
</ClInclude>
<ClInclude Include="global_id.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="watch_entry.h">
<Filter>Mods\Memory Watcher</Filter>
</ClInclude>
<ClInclude Include="mem_watcher_mod.h">
<Filter>Mods\Memory Watcher</Filter>
</ClInclude>
<ClInclude Include="comms_mod.h">
<Filter>Mods\Comms</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="lua_engine.h">
Expand Down
9 changes: 5 additions & 4 deletions ImGTA/audio_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "script.h"
#include "audio_scenes.h"
#include "music_events.h"
#include "global_id.h"


void AudioMod::Load()
Expand Down Expand Up @@ -38,10 +39,10 @@ void AudioMod::Think()

if (m_supportGlobals)
{
m_audioName = std::string((char *)getGlobalPtr(0x3BCF));
m_audioSource = std::string((char *)getGlobalPtr(0x3D92));
m_audio1 = std::string((char *)getGlobalPtr(0x4138));
m_audio2 = std::string((char *)getGlobalPtr(0x3B2A));
m_audioName = std::string((char *)getGlobalPtr(GlobalID::_15311));
m_audioSource = std::string((char *)getGlobalPtr(GlobalID::_15762));
m_audio1 = std::string((char *)getGlobalPtr(GlobalID::_16696));
m_audio2 = std::string((char *)getGlobalPtr(GlobalID::_15146));
}
}

Expand Down
8 changes: 7 additions & 1 deletion ImGTA/cheats_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,13 @@ bool CheatsMod::Draw()
//DrawMissionMenu();
DrawHUDMenu();

ImGui::SameLine(ImGui::GetContentRegionAvailWidth() - 100);
if (m_supportGlobals)
ImGui::SameLine(ImGui::GetContentRegionAvailWidth() - 100);
else
{
ImGui::SameLine(ImGui::GetContentRegionAvailWidth() - 530);
ImGui::TextColored(ImVec4(255, 0, 0, 255), "Your game version (%d) does not support specific memory access.", getGameVersion());
}
ImGui::Checkbox("Debug", &m_showDebug);
if (ImGui::Checkbox("Show in game", &m_showInGame))
m_scriptVarNeedsUpdate = true;
Expand Down
2 changes: 1 addition & 1 deletion ImGTA/cheats_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CheatsMod : public Mod
bool m_explosiveBullets = false;
bool m_scriptVarNeedsUpdate = false;
bool m_showDebug = true;
bool m_floatingMenu = true;
bool m_floatingMenu = false;

float m_menuFontSize = 1.0f;
float m_contentFontSize = 1.0f;
Expand Down
105 changes: 105 additions & 0 deletions ImGTA/comms_mod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "comms_mod.h"
#include "natives.h"
#include "script.h"
#include "imgui.h"
#include "main.h"
#include "utils.h"
#include "watch_entry.h"
#include "imgui_extras.h"
#include "mission_mod.h"
#include "global_id.h"

void CommsMod::Load()
{

}

void CommsMod::Unload()
{

}

void CommsMod::Think()
{
if (m_constantUpdate || m_wantsUpdate)
{
UpdateLocationData();
m_wantsUpdate = false;
}
}

void CommsMod::UpdateLocationData()
{
if (m_supportGlobals)
{
int characterArrayOffset = m_characterArrayStartAddr + m_characterID * sizeof(MessageArray) / 8;
m_characterCount = *(int *)getGlobalPtr(m_characterArraySizeAddr);
m_characterArray = *(MessageArray *)getGlobalPtr(characterArrayOffset);
}
}

void CommsMod::DrawMenuBar()
{
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Menu"))
{
ImGui::MenuItem("Empty");
ImGui::EndMenu();
}

ImGui::EndMenuBar();
}
}

bool CommsMod::Draw()
{
ImGui::SetWindowFontScale(m_menuFontSize);
DrawMenuBar();

ImGui::SetWindowFontScale(m_contentFontSize);

ImGui::Checkbox("Constant Updates?", &m_constantUpdate);
if (!m_constantUpdate)
if (ImGui::Button("Update"))
m_wantsUpdate = true;

if (m_supportGlobals)
{
if (ImGui::TreeNode("Messages"))
{
if (ImGui::InputInt("Message ID", &m_characterID))
{
ClipInt(m_characterID, 0, m_characterCount - 1);
m_wantsUpdate = true;
}

ImGui::Text("Hash: %d", m_characterArray.field_0);
ImGui::Text("Field 1: %d", m_characterArray.field_1);
ImGui::Text("Field 2: %d", m_characterArray.field_2);
ImGui::Text("Field 3: %s", m_characterArray.field_3);
ImGui::Text("Field 7: %s", m_characterArray.field_7);
ImGui::Text("Field B: %d", m_characterArray.field_B);
ImGui::Text("Field C: %d", m_characterArray.field_C_size);
std::string field_C = "Field C: ";
for (int i = 0; i < m_characterArray.field_C_size; ++i)
field_C += std::to_string(m_characterArray.field_C[i].val) + ", ";
ImGui::Text(field_C.c_str());
ImGui::Text("Field 11: %d", m_characterArray.field_11);
ImGui::Text("Field 12: %d", m_characterArray.field_12);
ImGui::Text("Field 13: %d", m_characterArray.field_13_size);
std::string field_13 = "Field 13: ";
for (int i = 0; i < m_characterArray.field_13_size; ++i)
field_13 += std::to_string(m_characterArray.field_13[i].val) + ", ";
ImGui::Text(field_13.c_str());
ImGui::Text("Field 18: %d", m_characterArray.field_18_size);
std::string field_18 = "Field 18: ";
for (int i = 0; i < m_characterArray.field_18_size; ++i)
field_18 += std::to_string(m_characterArray.field_18[i].val) + ", ";
ImGui::Text(field_18.c_str());
ImGui::TreePop();
}
}
return true;
}

72 changes: 72 additions & 0 deletions ImGTA/comms_mod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once
#include "mod.h"
#include "lua_engine.h"
#include "types.h"
#include "mission_mod.h"

struct MessageArray
{
// Global_127127 Global_17C49.f_744E
int field_0; // Hash example 'ig_devin' -> Look in standard_global_reg for correspondance
DWORD _padding0;
int field_1;
DWORD _padding1;
int field_2;
DWORD _padding2;
char field_3[32];
char field_7[32];
int field_B;
DWORD _paddingB;
int field_C_size; // 4?
DWORD _paddingC;
PaddedInt field_C[4];
int field_11;
DWORD _padding11;
int field_12;
DWORD _padding12;
int field_13_size = 4;
DWORD _padding13;
PaddedInt field_13[4];
int field_18_size; // 4?
DWORD _padding18;
PaddedInt field_18[4];
}; // Size 29 * 8 bytes

// TODO
/*struct MessageArray2 {
// Global_97
};*/ // Size


class CommsMod : public Mod
{
public:
CommsMod(bool supportGlobals) : Mod("Comms", true, supportGlobals)
{
m_windowFlags = ImGuiWindowFlags_MenuBar;
}

bool Draw() override;
void Think() override;
void Load() override;
void Unload() override;

private:
void DrawMenuBar();
void UpdateLocationData();

MessageArray m_characterArray;
int m_characterID = 0;
int m_characterCount = 0;
int m_characterArraySizeAddr = GlobalID::_127127;
int m_characterArrayStartAddr = m_characterArraySizeAddr + 1;

// ImGui inputs / internals
bool m_wantsUpdate = false;
int m_locationID = 0;
bool m_constantUpdate = true;
char m_animDictInput[256] = "";
char m_animNameInput[256] = "";
unsigned int m_animFlags = 0;
bool m_animLoop = false;
};
29 changes: 29 additions & 0 deletions ImGTA/global_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

namespace GlobalID
{
const int
_15311 = 15311,
_15762 = 15762,
_16696 = 16696,
_15146 = 15146,
_89962 = 89962,
_84544 = 84544,
_54748 = 54748,
_15692 = 15692,
_68477 = 68477,
_87299 = 87299,
_68507 = 68507,
_81155 = 81155,
_84353 = 84353,
_24748 = 24748,
_87300 = 87300,
_68623 = 68623, // Global_10BA2.f_6D
_75339 = 75339, // Global_10BA2.f_1AA9
_104696 = 104696, // Global_17C49.f_1CAD.f_2
_85405 = 85405,
_127127 = 127127, // Global_17C49.f_744E
_68523 = 68523, // 0x10BAB->Global_10BA2.f_9
_6580 = 6580, // Global_17C49.f_6C1.f_21B.f_C8F
_102834 = 102834; // Global_17C49.f_6C1.f_21B.f_C8D
}
Loading

0 comments on commit 03b075d

Please sign in to comment.