Skip to content

Commit

Permalink
Merge pull request #447 from pas-de-2/idInspector
Browse files Browse the repository at this point in the history
Trainer: added ID Inspector tool for HUD objects
  • Loading branch information
nipkownix committed Mar 3, 2023
2 parents 0821451 + 17df959 commit 9a5cb13
Show file tree
Hide file tree
Showing 12 changed files with 705 additions and 89 deletions.
9 changes: 9 additions & 0 deletions dllmain/EndSceneHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ void UI_NewGlobalsViewer()
bImGuiUIFocus = true;
}

void UI_NewIDInspector()
{
static int id = 0;
std::string windowTitle = "ID Inspector " + std::to_string(id++);
NewWindows.push_back(new UI_IDInspector(windowTitle));

bImGuiUIFocus = false;
}

void UI_NewAreaJump()
{
static int id = 0;
Expand Down
55 changes: 31 additions & 24 deletions dllmain/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ LifeMeter__roomInit_Fn LifeMeter__roomInit = nullptr;
BulletInfo__roomInit_Fn BulletInfo__roomInit = nullptr;

// message.h externs
MessageControl* cMes = nullptr;
MessageControl__setFontSize_Fn MessageControl__setFontSize = nullptr;
MessageControl__setLayout_Fn MessageControl__setLayout = nullptr;

Expand Down Expand Up @@ -533,10 +532,28 @@ TITLE_WORK* TitleWorkPtr()
return TitleWork_ptr;
}

IDSystem* IDSystem_ptr = nullptr;
IDSystem* IDSystemPtr()
MessageControl* cMes_ptr = nullptr;
MessageControl* MessageControlPtr()
{
return IDSystem_ptr;
return cMes_ptr;
}

IDSystem* IdSys_ptr = nullptr;
IDSystem* IdSysPtr()
{
return IdSys_ptr;
}

IDSystem* IdSub_ptr = nullptr;
IDSystem* IdSubPtr()
{
return IdSub_ptr;
}

IDSystem* IdNum_ptr = nullptr;
IDSystem* IdNumPtr()
{
return IdNum_ptr;
}

MercID* mercId_ptr = nullptr;
Expand Down Expand Up @@ -992,40 +1009,30 @@ bool re4t::init::Game()
pattern = hook::pattern("E8 ? ? ? ? 83 C4 08 E8 ? ? ? ? 8B 0D ? ? ? ? F7 81 ? ? ? ? ? ? ? ? 74");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint32_t>(0)).as_int(), bio4::KeyStop);

// Pointer to IDSystem
// IDSystem ptrs
pattern = hook::pattern("B9 ? ? ? ? E8 ? ? ? ? 8B ? ? ? ? ? 8B C8 D9");
IDSystem_ptr = *pattern.count(1).get(0).get<IDSystem*>(1);

// pointer to IDSystem::set
IdSys_ptr = *pattern.count(1).get(0).get<IDSystem*>(1);
pattern = hook::pattern("8D 48 FF 80 F9 01 77 ? C7 ? ? ? ? ? EB");
IdSub_ptr = *pattern.count(1).get(0).get<IDSystem*>(10);
pattern = hook::pattern("83 C4 08 B9 ? ? ? ? 39");
IdNum_ptr = *pattern.count(1).get(0).get<IDSystem*>(4);
pattern = hook::pattern("83 C4 18 6A 60 B9");
mercId_ptr = *pattern.count(1).get(0).get<MercID*>(6);
pattern = hook::pattern("E8 ? ? ? ? 6A 29 68 FE 00 00 00 B9");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), IDSystem__set);

// pointer to IDSystem::unitPtr
pattern = hook::pattern("E8 ? ? ? ? 8B ? ? ? ? ? 8B C8 D9 81 94 00 00 00 8B");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), IDSystem__unitPtr);

// pointer to IDSystem::unitPtr2
pattern = hook::pattern("E8 ? ? ? ? D9 ? ? ? ? ? D9 98 98 00 00 00 EB");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), IDSystem__unitPtr2);

// pointer to IDSystem::kill
pattern = hook::pattern("E8 ? ? ? ? 68 99 00 00 00 68 FF 00 00 00 B9 ? ? ? ? E8 ? ? ? ? 8B 46 20 8B");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), IDSystem__kill);

// pointer to IDSystem::setTime
pattern = hook::pattern("E8 ? ? ? ? FE 46 01 5F 5E 8B E5 ");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), IDSystem__setTime);

// pointer to mercId
pattern = hook::pattern("83 C4 18 6A 60 B9");
mercId_ptr= *pattern.count(1).get(0).get<MercID*>(6);

// pointer to cMes
// MessageControl ptrs
pattern = hook::pattern("51 52 6A 04 B9 ? ? ? ? 8B F0 E8");
cMes = *pattern.count(1).get(0).get<MessageControl*>(5);
// pointer to MessageControl::setFontSize
cMes_ptr = *pattern.count(1).get(0).get<MessageControl*>(5);
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(11)).as_int(), MessageControl__setFontSize);
// pointer to MessageControl::setLayout
pattern = hook::pattern("E8 ? ? ? ? 8B ? ? ? ? ? 53 53 52 C7");
ReadCall(injector::GetBranchDestination(pattern.count(1).get(0).get<uint8_t>(0)).as_int(), MessageControl__setLayout);

Expand Down
3 changes: 0 additions & 3 deletions dllmain/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ cPlayer* AshleyPtr();
uint8_t* GameSavePtr();
cEmMgr* EmMgrPtr();
TITLE_WORK* TitleWorkPtr();
IDSystem* IDSystemPtr();
MercID* mercIdPtr();
FADE_WORK* FadeWorkPtr(FADE_NO no);
IDSystem* IDSystemPtr();
extern double* fGPUUsagePtr;
extern double* fCPUUsagePtr;

Expand Down
8 changes: 4 additions & 4 deletions dllmain/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ void re4t::init::Gameplay()
break;
}

IDSystemPtr()->unitPtr(0x1u, IDC_TITLE_MENU)->texId_78 = 164;
IDSystemPtr()->unitPtr(0x1u, IDC_TITLE_MENU)->size0_W_DC = texW;
IDSystemPtr()->unitPtr(0x2u, IDC_TITLE_MENU)->texId_78 = 164;
IDSystemPtr()->unitPtr(0x2u, IDC_TITLE_MENU)->size0_W_DC = texW;
IdSysPtr()->unitPtr(0x1u, IDC_TITLE_MENU_0)->texId_78 = 164;
IdSysPtr()->unitPtr(0x1u, IDC_TITLE_MENU_0)->size0_W_DC = texW;
IdSysPtr()->unitPtr(0x2u, IDC_TITLE_MENU_0)->texId_78 = 164;
IdSysPtr()->unitPtr(0x2u, IDC_TITLE_MENU_0)->size0_W_DC = texW;
}

// Code we overwrote
Expand Down
50 changes: 25 additions & 25 deletions dllmain/HUDTweaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void ApplyHUDEdits(ID_CLASS idClass, const HUDEditData* data, int size)
{
for (int i = 0; i < size; ++i)
{
ID_UNIT* tex = IDSystemPtr()->unitPtr2(data[i].unitNo, idClass);
ID_UNIT* tex = IdSysPtr()->unitPtr2(data[i].unitNo, idClass);
if (data[i].posX != DEF) tex->pos0_94.x = data[i].posX;
if (data[i].posY != DEF) tex->pos0_94.y = data[i].posY;
if (data[i].sizeW != DEF) tex->size0_W_DC = data[i].sizeW;
Expand All @@ -27,8 +27,8 @@ void ApplyHUDEdits(ID_CLASS idClass, const HUDEditData* data, int size)

void ShrinkIDClass(ID_CLASS idClass, float scale)
{
ID_UNIT* tex = IDSystemPtr()->m_IdUnit_50;
for (int i = 0; i < IDSystemPtr()->m_maxId_0; ++i)
ID_UNIT* tex = IdSysPtr()->m_IdUnit_50;
for (int i = 0; i < IdSysPtr()->m_maxId_0; ++i)
{
if (tex->classNo_2 == idClass && tex->texId_78 != 0xFF)
{
Expand Down Expand Up @@ -120,30 +120,30 @@ extern float fGameDisplayAspectRatio;
void SideAlignHUD()
{
float fHudPosOffset = ((360.0f * fGameDisplayAspectRatio) - 640.0f) / 2.0f;
IDSystemPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x += fHudPosOffset;
IdSysPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x += fHudPosOffset;
}

float fDefaultHUDPosX;
float fDefaultHUDPosY;

void OffsetHUD()
{
IDSystemPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x = fDefaultHUDPosX + re4t::cfg->fHUDOffsetX;
IDSystemPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.y = fDefaultHUDPosY + re4t::cfg->fHUDOffsetY;
IdSysPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x = fDefaultHUDPosX + re4t::cfg->fHUDOffsetX;
IdSysPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.y = fDefaultHUDPosY + re4t::cfg->fHUDOffsetY;
}

void re4t::HUDTweaks::UpdateHUDOffsets()
{
if (IDSystemPtr()->setCk(IDC_LIFE_METER))
if (IdSysPtr()->setCk(IDC_LIFE_METER))
OffsetHUD();
}

void re4t::HUDTweaks::ResetLifeMeter()
{
if (IDSystemPtr()->setCk(IDC_LIFE_METER))
if (IdSysPtr()->setCk(IDC_LIFE_METER))
{
IDSystemPtr()->kill(0xFF, IDC_LIFE_METER);
IDSystemPtr()->kill(0xFF, IDC_LASER_GAUGE);
IdSysPtr()->kill(0xFF, IDC_LIFE_METER);
IdSysPtr()->kill(0xFF, IDC_LASER_GAUGE);
Cckpt->m_LifeMeter_0.roomInit();
Cckpt->m_BlltInfo_6C.roomInit();
}
Expand All @@ -170,15 +170,15 @@ void re4t::init::HUDTweaks()
SideAlignHUD();

// Save the default HUD position
fDefaultHUDPosX = IDSystemPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x;
fDefaultHUDPosY = IDSystemPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.y;
fDefaultHUDPosX = IdSysPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.x;
fDefaultHUDPosY = IdSysPtr()->unitPtr(0u, IDC_LIFE_METER)->pos0_94.y;

// Reposition the HUD
if (re4t::cfg->bRepositionHUD)
OffsetHUD();

// Code we overwrote
regs.ecx = (uint32_t)IDSystemPtr();
regs.ecx = (uint32_t)IdSysPtr();
}
}; injector::MakeInline<BulletInfo__roomInit_hook>(pattern.count(1).get(0).get<uint32_t>(2), pattern.count(1).get(0).get<uint32_t>(7));

Expand All @@ -191,7 +191,7 @@ void re4t::init::HUDTweaks()
ShrinkBulletInfo();

// Code we overwrote
regs.ecx = (uint32_t)IDSystemPtr();
regs.ecx = (uint32_t)IdSysPtr();
}
}; injector::MakeInline<BulletInfo__move_hook>(pattern.count(1).get(0).get<uint32_t>(5), pattern.count(1).get(0).get<uint32_t>(10));
}
Expand All @@ -209,10 +209,10 @@ void re4t::init::HUDTweaks()
ShrinkIDClass(IDC_ACT_BUTTON, 0.9f);

// grab prompt anchor
IDSystemPtr()->unitPtr(6u, IDC_ACT_BUTTON)->pos0_94.y = -90.5f;
IdSysPtr()->unitPtr(6u, IDC_ACT_BUTTON)->pos0_94.y = -90.5f;
// interact prompt anchor
IDSystemPtr()->unitPtr(0x20u, IDC_ACT_BUTTON)->pos0_94.x = -55.8f;
IDSystemPtr()->unitPtr(0x20u, IDC_ACT_BUTTON)->pos0_94.y = -148.1f;
IdSysPtr()->unitPtr(0x20u, IDC_ACT_BUTTON)->pos0_94.x = -55.8f;
IdSysPtr()->unitPtr(0x20u, IDC_ACT_BUTTON)->pos0_94.y = -148.1f;
}

// Code we overwrote
Expand All @@ -226,10 +226,10 @@ void re4t::init::HUDTweaks()
void operator()(injector::reg_pack& regs)
{
if (re4t::cfg->bSmallerActionPrompts)
cMes->setFontSize(1, 21, 29); // default font size: 23 x 32
MessageControlPtr()->setFontSize(1, 21, 29); // default font size: 23 x 32

// Code we overwrote
regs.ecx = (uint32_t)cMes;
regs.ecx = (uint32_t)MessageControlPtr();
}
}; injector::MakeInline<cActionButton__disp_hook>(pattern.count(1).get(0).get<uint32_t>(4), pattern.count(1).get(0).get<uint32_t>(9));
}
Expand All @@ -243,8 +243,8 @@ void re4t::init::HUDTweaks()
{
if (re4t::cfg->bHideZoomControlHints)
{
IDSystemPtr()->unitPtr(0x20u, IDC_SCOPE)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IDSystemPtr()->unitPtr(0x21u, IDC_SCOPE)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x20u, IDC_SCOPE)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x21u, IDC_SCOPE)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;

IdScope* thisptr = (IdScope*)regs.ecx;
thisptr->m_zoom_disp_C = 0; // hides the text
Expand All @@ -266,14 +266,14 @@ void re4t::init::HUDTweaks()
bool isEvent = FlagIsSet(GlobalPtr()->flags_STATUS_0_501C, uint32_t(Flags_STATUS::STA_EVENT));
if (re4t::cfg->bHideZoomControlHints || isEvent)
{
IDSystemPtr()->unitPtr(0x30u, IDC_BINOCULAR)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IDSystemPtr()->unitPtr(0x1Bu, IDC_BINOCULAR)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x30u, IDC_BINOCULAR)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x1Bu, IDC_BINOCULAR)->be_flag_0 &= ~ID_BE_FLAG_VISIBLE;
regs.ef &= ~(1 << regs.zero_flag);
}
else
{
IDSystemPtr()->unitPtr(0x30u, IDC_BINOCULAR)->be_flag_0 |= ID_BE_FLAG_VISIBLE;
IDSystemPtr()->unitPtr(0x1Bu, IDC_BINOCULAR)->be_flag_0 |= ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x30u, IDC_BINOCULAR)->be_flag_0 |= ID_BE_FLAG_VISIBLE;
IdSysPtr()->unitPtr(0x1Bu, IDC_BINOCULAR)->be_flag_0 |= ID_BE_FLAG_VISIBLE;
regs.ef |= (1 << regs.zero_flag);
}
}
Expand Down
5 changes: 4 additions & 1 deletion dllmain/MouseTurning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ bool __cdecl KeyOnCheck_hook(KEY_BTN a1)
switch (LastUsedDevice()) {
case InputDevices::DinputController:
case InputDevices::XinputController:
ret = bio4::KeyOnCheck_0(a1);
//if (re4t::cfg->bAnalogTurning && isTurning)
// ret = true;
//else
ret = bio4::KeyOnCheck_0(a1);
break;
case InputDevices::Keyboard:
case InputDevices::Mouse:
Expand Down
Loading

0 comments on commit 9a5cb13

Please sign in to comment.