-
Member
[Help][SL 9.2.7] CGPlayer CalculateThreat
Hello, trying to reverse CalculateThreat (thanks to scizzydo) function but it returns zeros, seems i missing something:
char __fastcall CGUnit_C::CalculateThreat(__int64 a1, wGUID *a2, bool *a3, _BYTE *a4, float *a5, _QWORD *a6)
Code:
auto inline ThreatPercentFor(Unit* a1, Unit* otherUnit)
{
int tStatus = 0;
int tPercent = 0;
int tRawPercent = 0;
int tValue = 0;
((void(__fastcall*)(DWORD_PTR, wGUID&, int&, int&, int&, int&))(Hook::baseAddress + 0x1865710))(a1->addr, otherUnit->wguid, tStatus, tPercent, tRawPercent, tValue);
std::cout << tStatus << " " << tPercent << " " << tRawPercent << " " << tValue << " " << std::endl;
return tPercent;
}
-
Contributor
Maybe try calling it the same way as the binary? Correct data types, and correct passing. You decided to change it all from what you write at the top, to how it's actually used
Also worth noting, that if you're calling it against training dummies, you usually don't have threat on those. Make sure you're testing it on a monster attacking you
Last edited by scizzydo; 04-06-2024 at 03:11 PM.
-
Contributor
Just tested on retail, and it does indeed work. However, I feel the confusion comes from the way it's called.
Code:
inline bool(__fastcall* CGUnit_C__GetThreatSituation)(void* pObj, WoWGUID* guid, bool* status, uint8_t* rawthreatpct, float* threatpct, uint64_t* threatvalue) = nullptr;
The confusion happens in the pObj & GUID. In the lua function, arg1 is the "unit" and arg2 is the "target", however, in the lua what happens is arg1 "unit" is the GUID in this case, and the arg2 "target" is the pObj
Code:
auto result = CGUnit_C__GetThreatSituation(pObj, &guid, &status, &rawthreatpct, &threatpct, &threatvalue);
std::cout << "Result: " << result << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "rawthreatpct: " << (uint32_t)rawthreatpct << std::endl;
std::cout << "threatpct: " << threatpct << std::endl;
std::cout << "threatvalue: " << threatvalue << std::endl;
-
Post Thanks / Like - 1 Thanks
Trogg (1 members gave Thanks to scizzydo for this useful post)
-
Member
my current call is:
Code:
typedef bool(__fastcall* _ThreatPercentFor)(void* addr, wGUID* guid, bool* tStatus, uint8_t* tPercent, float* tRawPercent, uint64_t* tValue);
I’m not sure that the output data types are correct, the function in 3.3.5 looks exactly the same, but in fact the output was ints
Code:
bool ThreatPercentFor(Unit* a1, Unit* otherUnit)
{
auto addr = a1->addr;
void* addrv = &addr;
wGUID guid = otherUnit->wguid;
bool tStatus = 0;
uint8_t tPercent = 0;
float tRawPercent = 0;
uint64_t tValue = 0;
_ThreatPercentFor Threat = (_ThreatPercentFor)(0x1865710 + Hook::baseAddress);
bool res = Threat(addrv, &guid, &tStatus, &tPercent, &tRawPercent, &tValue);
std::cout << "Result: " << res << std::endl;
std::cout << "Status: " << tStatus << std::endl;
std::cout << "rawthreatpct: " << (uint32_t)tPercent << std::endl;
std::cout << "threatpct: " << tRawPercent << std::endl;
std::cout << "threatvalue: " << tValue << std::endl;
return res;
}
on each call, no matter, in combat or not with target it returns
Code:
Result: 0
Status: 0
rawthreatpct: 0
threatpct: 0
threatvalue: 0
v8 = *(_DWORD *)(a1 + 5816);
a1 - address of unit1
v20 = *a2;
v9 = (unsigned int)(-691005195 * LODWORD(v20.low) - 1565916357 * LODWORD(v20.high)+ ((3603962101u * v20.low + 2729050939u * v20.high) >> 32)) % v8;
*a2 - pointer to WGUID of unit2
others parrameters are the same
Last edited by Trogg; 04-07-2024 at 06:20 AM.
-
Contributor
3.3.5 pointers were 32 bit (so ints). But, looking at your test, your addr is wrong. You want to pass addr, not addrv. You also aren't doing it how I explained with them flipped. So, depending on what you're testing on you may not get anything. addr is the "other unit" and guid is your "a1" guid
-
Post Thanks / Like - 1 Thanks
Trogg (1 members gave Thanks to scizzydo for this useful post)
-
Member