diff --git a/Engine/Source/Frame/CSimpleModel.cpp b/Engine/Source/Frame/CSimpleModel.cpp index 75ecc05..21b9acc 100644 --- a/Engine/Source/Frame/CSimpleModel.cpp +++ b/Engine/Source/Frame/CSimpleModel.cpp @@ -592,3 +592,9 @@ void CSimpleModel::ReplaceTexture(uint32_t type, const char* fileName) { HandleClose(reinterpret_cast(texture)); } } + +// VERIFY: 06d1129f auto +// OFFSET: 0x00542F80 +void CSimpleModel::SetPosition(const C3Vector& position) { + this->m_position = position; +} diff --git a/Engine/Source/Frame/CSimpleModel.h b/Engine/Source/Frame/CSimpleModel.h index 8476a77..facf53f 100644 --- a/Engine/Source/Frame/CSimpleModel.h +++ b/Engine/Source/Frame/CSimpleModel.h @@ -78,6 +78,7 @@ class CSimpleModel : public CSimpleFrame { CM2Scene* GetScene(); void ReplaceTexture(uint32_t type, const char* fileName); void SetCamera(CCamera* camera); + void SetPosition(const C3Vector& position); void SetCameraByID(uint32_t id); void SetCameraByIndex(uint32_t index); void SetLight(const CM2Light& light); diff --git a/Engine/Source/Storm/H/stpl.h b/Engine/Source/Storm/H/stpl.h index 028ecaa..3f83543 100644 --- a/Engine/Source/Storm/H/stpl.h +++ b/Engine/Source/Storm/H/stpl.h @@ -415,7 +415,7 @@ void TSList::ChangeLinkOffset(ptrdiff_t linkoffset) { } // VERIFY: ab66a452 manual -// OFFSET: [0x0047C470, 0x0047E7C0, 0x0047E830, 0x0047E8A0, 0x00485970, 0x00488940, 0x00489A60, 0x00498AE0, 0x00498B80, 0x0049A610, 0x004B73E0, 0x004B7460, 0x004BA230, 0x004BA2A0, 0x004BCEF0, 0x004C9650, 0x004CA310, 0x004CDA60, 0x004DA510, 0x004F1650, 0x004F92A0, 0x00502270, 0x00503060, 0x00527B00, 0x00528690, 0x0052F090, 0x0053EEB0, 0x0055FD20, 0x005AE0C0, 0x005B2170, 0x005B2260, 0x005B4CF0, 0x005BE660, 0x005BE6D0, 0x005BE740, 0x005F3DB0, 0x00606480, 0x00615FF0, 0x00617210, 0x00633470, 0x00670070, 0x00687FD0, 0x006BC100, 0x006BDDC0, 0x006BDE40, 0x006BF210, 0x006E4B80, 0x006EBF90, 0x006F2B70, 0x006F2BE0, 0x006FAF40, 0x0074F550, 0x0074F640, 0x00764420, 0x00771C20, 0x00772EF0, 0x00788B20, 0x007FBC20, 0x00804D90, 0x00804E00, 0x00807650, 0x0081A530, 0x0083D2D0, 0x008489F0, 0x00848A60, 0x0086E850, 0x008C8550, 0x008C8640, 0x0095B8E0] +// OFFSET: [0x0047C470, 0x0047E7C0, 0x0047E830, 0x0047E8A0, 0x00485970, 0x00488940, 0x00489A60, 0x00498AE0, 0x00498B80, 0x0049A610, 0x004B73E0, 0x004B7460, 0x004BA230, 0x004BA2A0, 0x004BCEF0, 0x004C9650, 0x004CA310, 0x004CDA60, 0x004DA510, 0x004F1650, 0x004F92A0, 0x00502270, 0x00503060, 0x00527B00, 0x00528690, 0x0052F090, 0x0053EEB0, 0x0055FD20, 0x0056C9C0, 0x005AE0C0, 0x005B2170, 0x005B2260, 0x005B4CF0, 0x005BE660, 0x005BE6D0, 0x005BE740, 0x005F3DB0, 0x00606480, 0x00615FF0, 0x00617210, 0x00633470, 0x00670070, 0x00687FD0, 0x006BC100, 0x006BDDC0, 0x006BDE40, 0x006BF210, 0x006E4B80, 0x006EBF90, 0x006F2B70, 0x006F2BE0, 0x006FAF40, 0x0074F550, 0x0074F640, 0x00764420, 0x00771C20, 0x00772EF0, 0x00788B20, 0x007FBC20, 0x00804D90, 0x00804E00, 0x00807650, 0x0081A530, 0x0083D2D0, 0x008489F0, 0x00848A60, 0x0086E850, 0x008C8550, 0x008C8640, 0x0095B8E0] template void TSList::Clear() { T* node; @@ -686,7 +686,7 @@ TSFixedArray::TSFixedArray(const TSFixedArray& source) { } // VERIFY: 0f3f0aeb manual -// OFFSET: [0x0047C630, 0x0047C6C0, 0x00490BE0, 0x004967E0, 0x004B74F0, 0x004BAFD0, 0x004BC2F0, 0x004BC380, 0x004BE2D0, 0x004C0260, 0x004C9520, 0x004CA720, 0x004CC6F0, 0x004CC780, 0x004CDDD0, 0x004CF070, 0x004D0A70, 0x004D3130, 0x004D33C0, 0x004D4E10, 0x004F31F0, 0x00502360, 0x005032A0, 0x00503330, 0x005033C0, 0x00503450, 0x005053E0, 0x00527BF0, 0x00527C80, 0x00527E70, 0x0052F100, 0x0053F160, 0x00548B70, 0x00558C50, 0x00558CE0, 0x0055F560, 0x0055F5F0, 0x0055F680, 0x0055F710, 0x0055F7A0, 0x00566700, 0x00575F60, 0x005920F0, 0x005B4DE0, 0x005B4E70, 0x005BE830, 0x005BE8C0, 0x005C7290, 0x005C7320, 0x005D24E0, 0x005F03B0, 0x005F3E20, 0x005F5AD0, 0x005F5B60, 0x005F5BF0, 0x005FCB80, 0x00617AA0, 0x00617B30, 0x00617BC0, 0x0066E830, 0x0066E8C0, 0x0066E950, 0x0066E9E0, 0x0066EA70, 0x0066EB00, 0x0066EB90, 0x0066EC20, 0x0066ECB0, 0x0066ED40, 0x0066EDD0, 0x0066EE60, 0x0066EEF0, 0x0066EF80, 0x0066F010, 0x0066F0A0, 0x0066F130, 0x0066F1C0, 0x0066F250, 0x0066F2E0, 0x0066F370, 0x0066F400, 0x0066F490, 0x0066F520, 0x0066F5B0, 0x0066F640, 0x0066F6D0, 0x0066F760, 0x0066F7F0, 0x0066F880, 0x006881A0, 0x006BBE30, 0x006BEE90, 0x006C2650, 0x006C2AC0, 0x006C2B50, 0x006C8380, 0x006E4EB0, 0x006E4F40, 0x006F2C50, 0x006F2CE0, 0x006F2D70, 0x006F2E00, 0x006F2E90, 0x006F2F20, 0x006F2FB0, 0x00709AA0, 0x00709B30, 0x0072FFC0, 0x007675F0, 0x007685D0, 0x00776AD0, 0x007B04D0, 0x007B5DF0, 0x007C0B40, 0x007C0BD0, 0x007DD360, 0x007DD3F0, 0x007E01C0, 0x007F2A20, 0x007F4ED0, 0x00804EF0, 0x00804F80, 0x008109F0, 0x00810A80, 0x00810B10, 0x00812BC0, 0x00812C50, 0x00814910, 0x0081A620, 0x00848800, 0x0084B570, 0x00876550, 0x00877760, 0x0087B0F0, 0x00965260, 0x009681C0, 0x009694A0, 0x009694F0, 0x0097BB80] +// OFFSET: [0x0047C630, 0x0047C6C0, 0x00490BE0, 0x004967E0, 0x004B74F0, 0x004BAFD0, 0x004BC2F0, 0x004BC380, 0x004BE2D0, 0x004C0260, 0x004C9520, 0x004CA720, 0x004CC6F0, 0x004CC780, 0x004CDDD0, 0x004CF070, 0x004D0A70, 0x004D3130, 0x004D33C0, 0x004D4E10, 0x004F31F0, 0x00502360, 0x005032A0, 0x00503330, 0x005033C0, 0x00503450, 0x005053E0, 0x00527BF0, 0x00527C80, 0x00527E70, 0x0052F100, 0x0053F160, 0x00548B70, 0x00558C50, 0x00558CE0, 0x0055F560, 0x0055F5F0, 0x0055F680, 0x0055F710, 0x0055F7A0, 0x00566700, 0x00575F60, 0x005920F0, 0x005B4DE0, 0x005B4E70, 0x005BE830, 0x005BE8C0, 0x005C7290, 0x005C7320, 0x005C91F0, 0x005D24E0, 0x005F03B0, 0x005F3E20, 0x005F5AD0, 0x005F5B60, 0x005F5BF0, 0x005FCB80, 0x00617AA0, 0x00617B30, 0x00617BC0, 0x0066E830, 0x0066E8C0, 0x0066E950, 0x0066E9E0, 0x0066EA70, 0x0066EB00, 0x0066EB90, 0x0066EC20, 0x0066ECB0, 0x0066ED40, 0x0066EDD0, 0x0066EE60, 0x0066EEF0, 0x0066EF80, 0x0066F010, 0x0066F0A0, 0x0066F130, 0x0066F1C0, 0x0066F250, 0x0066F2E0, 0x0066F370, 0x0066F400, 0x0066F490, 0x0066F520, 0x0066F5B0, 0x0066F640, 0x0066F6D0, 0x0066F760, 0x0066F7F0, 0x0066F880, 0x006881A0, 0x006BBE30, 0x006BEE90, 0x006C2650, 0x006C2AC0, 0x006C2B50, 0x006C8380, 0x006E4EB0, 0x006E4F40, 0x006F2C50, 0x006F2CE0, 0x006F2D70, 0x006F2E00, 0x006F2E90, 0x006F2F20, 0x006F2FB0, 0x00709AA0, 0x00709B30, 0x0072FFC0, 0x007675F0, 0x007685D0, 0x00776AD0, 0x007B04D0, 0x007B5DF0, 0x007C0B40, 0x007C0BD0, 0x007DD360, 0x007DD3F0, 0x007E01C0, 0x007F2A20, 0x007F4ED0, 0x00804EF0, 0x00804F80, 0x008109F0, 0x00810A80, 0x00810B10, 0x00812BC0, 0x00812C50, 0x00814910, 0x0081A620, 0x00848800, 0x0084B570, 0x00876550, 0x00877760, 0x0087B0F0, 0x00965260, 0x009681C0, 0x009694A0, 0x009694F0, 0x0097BB80] template TSFixedArray::~TSFixedArray() { for (uint32_t i = 0; i < this->m_count; i++) { @@ -768,7 +768,7 @@ void TSFixedArray::Set(uint32_t count, const T* data) { } // VERIFY: 30433c72 manual -// OFFSET: [0x00464B30, 0x00465AC0, 0x004670D0, 0x004957B0, 0x004D0B00, 0x004F5840, 0x00547E20, 0x00592F00, 0x00592FC0, 0x00599820, 0x006171B0, 0x0061F9C0, 0x006C0270, 0x006CA0B0, 0x0079E080, 0x007F1220, 0x007F1EA0, 0x007F1F20, 0x00966B10, 0x009AAF10] +// OFFSET: [0x00464B30, 0x00465AC0, 0x004670D0, 0x004957B0, 0x004D0B00, 0x004F5840, 0x00547E20, 0x00592F00, 0x00592FC0, 0x00599820, 0x005C9690, 0x006171B0, 0x0061F9C0, 0x006C0270, 0x006CA0B0, 0x0079E080, 0x007F1220, 0x007F1EA0, 0x007F1F20, 0x00966B10, 0x009AAF10] template void TSFixedArray::SetCount(uint32_t count) { if (count != this->m_count) { @@ -1017,7 +1017,7 @@ T* TSHashTable::InternalNew(TSExplicitList* listptr, size_t extrabyt } // VERIFY: 4a402d4d manual -// OFFSET: [0x0047C870, 0x0047CA60, 0x004921C0, 0x00496AD0, 0x004B84E0, 0x004BB410, 0x004BB510, 0x004BC6C0, 0x004BC930, 0x004BCA30, 0x004BCA60, 0x004BE5C0, 0x004BE6C0, 0x004C0890, 0x004C0990, 0x004C95B0, 0x004C97F0, 0x004CAE00, 0x004CAF00, 0x004CCBB0, 0x004CCDA0, 0x004CCEA0, 0x004CCED0, 0x004CE3C0, 0x004CE4C0, 0x004CF590, 0x004CF690, 0x004D6040, 0x004F34D0, 0x00506110, 0x00506430, 0x00506630, 0x00506830, 0x00529750, 0x00529850, 0x00529A60, 0x0052F400, 0x0053F770, 0x00549040, 0x0055A270, 0x0055A480, 0x00560700, 0x005608A0, 0x00560AB0, 0x00560CB0, 0x00560EA0, 0x00567700, 0x00576330, 0x00592E00, 0x005B64F0, 0x005B6690, 0x005C1690, 0x005C1880, 0x005C8820, 0x005D27C0, 0x005F0850, 0x005F40E0, 0x005F5FB0, 0x005F6240, 0x005F6400, 0x005FCE70, 0x00618450, 0x00618680, 0x006188A0, 0x00672CA0, 0x00672E50, 0x00672F50, 0x00673100, 0x00673200, 0x006733B0, 0x006734B0, 0x00673660, 0x00673760, 0x00673910, 0x00673A10, 0x00673BD0, 0x00673CD0, 0x00673E70, 0x00673F70, 0x00674110, 0x00674210, 0x006743C0, 0x006744C0, 0x00674670, 0x00674770, 0x00674910, 0x00674A10, 0x00674BB0, 0x00674CB0, 0x00674E50, 0x00674F50, 0x006750F0, 0x006751F0, 0x006753B0, 0x00688560, 0x006BC390, 0x006BF030, 0x006C2D30, 0x006C3180, 0x006C8620, 0x006E66C0, 0x006E67C0, 0x006F3AD0, 0x006F3C70, 0x006F3EC0, 0x006F40C0, 0x006F4310, 0x006F44D0, 0x006F4690, 0x00709F60, 0x0070A150, 0x00734910, 0x00767BC0, 0x00768D00, 0x00776E00, 0x007B0860, 0x007B71F0, 0x007C0E60, 0x007C0F60, 0x007DD840, 0x007DDA30, 0x007E04E0, 0x007F2CC0, 0x007F5400, 0x0080A430, 0x0080A620, 0x008110B0, 0x008112A0, 0x008114A0, 0x008132F0, 0x008134E0, 0x0081AFD0, 0x0084A1B0, 0x0084B910, 0x008767E0, 0x00877910, 0x0087C0A0] +// OFFSET: [0x0047C870, 0x0047CA60, 0x004921C0, 0x00496AD0, 0x004B84E0, 0x004BB410, 0x004BB510, 0x004BC6C0, 0x004BC930, 0x004BCA30, 0x004BCA60, 0x004BE5C0, 0x004BE6C0, 0x004C0890, 0x004C0990, 0x004C95B0, 0x004C97F0, 0x004CAE00, 0x004CAF00, 0x004CCBB0, 0x004CCDA0, 0x004CCEA0, 0x004CCED0, 0x004CE3C0, 0x004CE4C0, 0x004CF590, 0x004CF690, 0x004D6040, 0x004F34D0, 0x00506110, 0x00506430, 0x00506630, 0x00506830, 0x00529750, 0x00529850, 0x00529A60, 0x0052F400, 0x0053F770, 0x00549040, 0x0055A270, 0x0055A480, 0x00560700, 0x005608A0, 0x00560AB0, 0x00560CB0, 0x00560EA0, 0x00567700, 0x00576330, 0x00592E00, 0x005B64F0, 0x005B6690, 0x005C1690, 0x005C1880, 0x005C8630, 0x005C8820, 0x005D27C0, 0x005F0850, 0x005F40E0, 0x005F5FB0, 0x005F6240, 0x005F6400, 0x005FCE70, 0x00618450, 0x00618680, 0x006188A0, 0x00672CA0, 0x00672E50, 0x00672F50, 0x00673100, 0x00673200, 0x006733B0, 0x006734B0, 0x00673660, 0x00673760, 0x00673910, 0x00673A10, 0x00673BD0, 0x00673CD0, 0x00673E70, 0x00673F70, 0x00674110, 0x00674210, 0x006743C0, 0x006744C0, 0x00674670, 0x00674770, 0x00674910, 0x00674A10, 0x00674BB0, 0x00674CB0, 0x00674E50, 0x00674F50, 0x006750F0, 0x006751F0, 0x006753B0, 0x00688560, 0x006BC390, 0x006BF030, 0x006C2D30, 0x006C3180, 0x006C8620, 0x006E66C0, 0x006E67C0, 0x006F3AD0, 0x006F3C70, 0x006F3EC0, 0x006F40C0, 0x006F4310, 0x006F44D0, 0x006F4690, 0x00709F60, 0x0070A150, 0x00734910, 0x00767BC0, 0x00768D00, 0x00776E00, 0x007B0860, 0x007B71F0, 0x007C0E60, 0x007C0F60, 0x007DD840, 0x007DDA30, 0x007E04E0, 0x007F2CC0, 0x007F5400, 0x0080A430, 0x0080A620, 0x008110B0, 0x008112A0, 0x008114A0, 0x008132F0, 0x008134E0, 0x0081AFD0, 0x0084A1B0, 0x0084B910, 0x008767E0, 0x00877910, 0x0087C0A0] template TSHashTable::~TSHashTable() { this->InternalClear(1); @@ -1614,17 +1614,18 @@ T& TSCGrowableArray::operator[](uint32_t index) { return this->m_inline[index]; } -// VERIFY: 2e6b9329 manual -// OFFSET: [0x007B3B70] +// VERIFY: ab2e9eb9 manual +// OFFSET: [0x00728B10, 0x00728B90, 0x00728C10, 0x007B3B70] template void TSCGrowableArray::BecomeDynamic() { + const uint32_t overlap = (sizeof(TSGrowableArray) + sizeof(T) - 1) / sizeof(T); uint32_t count = this->m_count; - if (static_cast(count) > static_cast(N)) { - count = N; + if (count > overlap) { + count = overlap; } - T saved[N]; + T saved[overlap]; if (count) { memcpy(saved, this->m_inline, sizeof(T) * count); diff --git a/Engine/Source/Tempest/C33Matrix.cpp b/Engine/Source/Tempest/C33Matrix.cpp index fbfceb7..c072f2d 100644 --- a/Engine/Source/Tempest/C33Matrix.cpp +++ b/Engine/Source/Tempest/C33Matrix.cpp @@ -322,3 +322,14 @@ C3Vector operator*(const C3Vector& v, const C33Matrix& m) { result.z = m.b2 * v.y + m.a2 * v.x + m.c2 * v.z; return result; } + +// VERIFY: 50c0b42d auto +// OFFSET: 0x0050F520 +C3Vector operator*=(C3Vector& v, const C33Matrix& m) { + float y = m.c1 * v.z + m.b1 * v.y + m.a1 * v.x; + float z = m.c2 * v.z + m.b2 * v.y + m.a2 * v.x; + v.x = m.c0 * v.z + m.b0 * v.y + v.x * m.a0; + v.y = y; + v.z = z; + return v; +} diff --git a/Engine/Source/Tempest/C33Matrix.h b/Engine/Source/Tempest/C33Matrix.h index 89edf83..7c2e649 100644 --- a/Engine/Source/Tempest/C33Matrix.h +++ b/Engine/Source/Tempest/C33Matrix.h @@ -41,5 +41,6 @@ class C33Matrix { C33Matrix operator*(const C33Matrix& l, const C33Matrix& r); C3Vector operator*(const C3Vector& v, const C33Matrix& m); +C3Vector operator*=(C3Vector& v, const C33Matrix& m); #endif diff --git a/Engine/Source/Tempest/C3Vector.cpp b/Engine/Source/Tempest/C3Vector.cpp index 0c988e7..2015322 100644 --- a/Engine/Source/Tempest/C3Vector.cpp +++ b/Engine/Source/Tempest/C3Vector.cpp @@ -217,3 +217,13 @@ float C3Vector::Distance(const C3Vector& a, const C3Vector& b) { float dx = a.x - b.x; return sqrt(dx * dx + dz * dz + dy * dy); } + +// VERIFY: 9db61a8f auto +// OFFSET: 0x004BEC40 +C3Vector operator*(const C3Vector& l, float r) { + C3Vector result; + result.x = l.x * r; + result.y = l.y * r; + result.z = r * l.z; + return result; +} diff --git a/Engine/Source/Tempest/C3Vector.h b/Engine/Source/Tempest/C3Vector.h index 2d9edb4..8535b0b 100644 --- a/Engine/Source/Tempest/C3Vector.h +++ b/Engine/Source/Tempest/C3Vector.h @@ -43,6 +43,7 @@ class C3Vector { C3Vector operator+(const C3Vector& l, const C3Vector& r); C3Vector operator-(const C3Vector& l, const C3Vector& r); +C3Vector operator*(const C3Vector& l, float r); bool operator==(const C3Vector& l, const C3Vector& r); bool operator!=(const C3Vector& l, const C3Vector& r); C3Vector operator%(const C3Vector& l, const C2Vector& r); diff --git a/Engine/Source/Tempest/CMath.cpp b/Engine/Source/Tempest/CMath.cpp index 5bd259f..6cf4450 100644 --- a/Engine/Source/Tempest/CMath.cpp +++ b/Engine/Source/Tempest/CMath.cpp @@ -700,3 +700,17 @@ float CMath::sin_(float x) { float OrganicSmooth(float from, float to, float t) { return from + (to - from) * ((1.0f - cosf(t * 3.1415927f)) * 0.5f); } + +// VERIFY: 0fa97e20 auto +// OFFSET: 0x006F7A60 +void CMath::sincos_(float x, float* s, float* c) { + float turns = x * 0.31830987f; + float frac; + int32_t whole; + CMath::split_(turns - 0.5f, &frac, &whole); + float value = 1.0f - frac * ((6.0f - 4.0f * frac) * frac); + *s = (whole & 1) ? -value : value; + CMath::split_(turns, &frac, &whole); + value = 1.0f - frac * ((6.0f - 4.0f * frac) * frac); + *c = (whole & 1) ? -value : value; +} diff --git a/Engine/Source/Tempest/CMath.h b/Engine/Source/Tempest/CMath.h index 93335de..78c9275 100644 --- a/Engine/Source/Tempest/CMath.h +++ b/Engine/Source/Tempest/CMath.h @@ -23,6 +23,7 @@ class CMath { static float sin_(float x); static bool solvequad_(float a, float b, float c, float& r0, float& r1); static void split_(float x, float* frac, int32_t* whole); + static void sincos_(float x, float* s, float* c); static uint32_t fuint_pi(float f); static uint32_t sqrt_(uint32_t n); }; diff --git a/Tools/WowClient/standin_runtime.cpp b/Tools/WowClient/standin_runtime.cpp index 14ee05e..092fd2a 100644 --- a/Tools/WowClient/standin_runtime.cpp +++ b/Tools/WowClient/standin_runtime.cpp @@ -11,6 +11,7 @@ extern "C" const int g_standinCount; static char s_logPath[MAX_PATH]; static HANDLE s_console = INVALID_HANDLE_VALUE; +static HANDLE s_logFile = INVALID_HANDLE_VALUE; static void LogLine(const char* text) { fputs(text, stderr); @@ -21,11 +22,9 @@ static void LogLine(const char* text) { WriteFile(s_console, text, static_cast(strlen(text)), &written, nullptr); } - FILE* file = nullptr; - - if (s_logPath[0] && fopen_s(&file, s_logPath, "a") == 0 && file) { - fputs(text, file); - fclose(file); + if (s_logFile != INVALID_HANDLE_VALUE) { + DWORD written = 0; + WriteFile(s_logFile, text, static_cast(strlen(text)), &written, nullptr); } } @@ -181,6 +180,7 @@ static struct StandinRuntimeInit { } DeleteFileA(s_logPath); + s_logFile = CreateFileA(s_logPath, FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (AllocConsole()) { SetConsoleTitleA("WowClient stand-ins"); diff --git a/WoW/Source/Client.cpp b/WoW/Source/Client.cpp index f247c02..2fce596 100644 --- a/WoW/Source/Client.cpp +++ b/WoW/Source/Client.cpp @@ -4,6 +4,8 @@ #include #include "Client.h" #include "_Triage/AreaList.h" +#include "WoW/Source/Net/NetClient/NetClient.h" +#include "_Triage/SHA1.h" #include "_Triage/DataPreload.h" #include "_Triage/GameClientCommands.h" #include "_Triage/StartupReport.h" @@ -76,6 +78,7 @@ #include "WoW/Source/Object/ObjectClient/Movement_C.h" #include "WoW/Source/Object/ObjectClient/ObjectEffect.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Ui/Types.h" #include "WoW/Source/Object/ObjectClient/Trade_C.h" #include "WoW/Source/Object/ObjectClient/Unit_C.h" #include "WoW/Source/ObjectAlloc/HeapUsage.h" @@ -104,6 +107,7 @@ #include "WoW/Source/WorldClient/shadow.h" #include "WoW/Source/WowServices/PatchFiles.h" #include "WoW/Source/WowServices/RealmConnection.h" +#include "WoW/Source/WowServices/WDataStore.h" #include "WoW/Source/WowSvcs/WowSvcsClient/AccountData.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/WowSvcs/WowSvcsClient/FriendList.h" @@ -283,6 +287,24 @@ static int32_t s_clientTaxiBenchIsOnTaxi; // STATIC: 0x00B2F9AC static int32_t s_clientTaxiBenchEnabled; +// STATIC: 0x00B2F9B0 +static double s_clientTaxiBenchMinFPS; + +// STATIC: 0x00B2F9B8 +static double s_clientTaxiBenchMaxFPS; + +// STATIC: 0x00B2F9C0 +static double s_clientTaxiBenchTotalTime; + +// STATIC: 0x00B2F9C8 +static uint32_t s_clientTaxiBenchTotalFrames; + +// STATIC: 0x00B2F9CC +static uint32_t s_clientTaxiBenchDelayTime; + +// STATIC: 0x00B2F9D0 +static uint64_t s_clientTaxiTimestamp; + // STATIC: 0x00B2F9E0 static uint8_t s_botCheckEnabled; @@ -290,7 +312,7 @@ static uint8_t s_botCheckEnabled; static uint32_t s_botCheckStartTime; // STATIC: 0x00B2F9E8 -static uint32_t s_botCheckDelay; +static int32_t s_botCheckDelay; // STATIC: 0x00B2FA1C static C3Vector s_spawnPosition; @@ -1440,7 +1462,7 @@ int32_t ForEveryRunOnceWTF::AppendFileName(OS_FILE_DATA& data, void* param) { return 0; } -// VERIFY: 0f3b98a4 manual +// VERIFY: fedc85e6 manual // OFFSET: 0x00406510 void ClientDestroyGame(int32_t charSelect, int32_t resumeGlue, int32_t worldLogin) { if (!s_gameInitialized) { @@ -1476,7 +1498,7 @@ void ClientDestroyGame(int32_t charSelect, int32_t resumeGlue, int32_t worldLogi CGGameObject_C::Shutdown(); CGObject_C::Shutdown(); MovementDestroy(); - LootRollDestroy(); + LootRollShutdown(); EventUnregister(EVENT_ID_IDLE, MovementIdleMoveUnits); Spell_C_StopTargeting(); ClntObjMgrDestroy(); @@ -1905,3 +1927,186 @@ int32_t STORMAPI SendErrorLog(uint32_t errorcode, const char* description, const return 1; } + +// VERIFY: b4bcd439 manual +// OFFSET: 0x00404EE0 +static void ClientBeginTaxiBenchmarkMode() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || !(player->m_player->m_playerFlags & 0x20000)) { + return; + } + + s_clientTaxiBenchEnabled = 1; + s_clientTaxiBenchMinFPS = 99999.0; + s_clientTaxiBenchIsOnTaxi = 1; + s_clientTaxiBenchTotalFrames = 0; + s_clientTaxiBenchMaxFPS = 0.0; + s_clientTaxiBenchTotalTime = 0.0; + s_clientTaxiBenchDelayTime = OsGetAsyncTimeMs() + 5000; +} + +// VERIFY: a664a31a manual +// OFFSET: 0x00404F60 +static void ClientEndTaxiBenchmarkMode(int32_t silent) { + if (!s_clientTaxiBenchEnabled) { + return; + } + + s_clientTaxiBenchEnabled = 0; + s_clientTaxiBenchIsOnTaxi = 0; + + if (silent || !s_clientTaxiBenchTotalFrames) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || player->IsDeadOrGhost()) { + return; + } + + char text[3000]; + CGChat::AddChatMessage(FrameScript_GetText("BENCHMARK_TAXI_RESULTS", -1, GENDER_NOT_APPLICABLE), CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + SStrPrintf(text, sizeof(text), FrameScript_GetText("BENCHMARK_TAXI_MIN_FPS", -1, GENDER_NOT_APPLICABLE), s_clientTaxiBenchMinFPS); + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + SStrPrintf(text, sizeof(text), FrameScript_GetText("BENCHMARK_TAXI_MAX_FPS", -1, GENDER_NOT_APPLICABLE), s_clientTaxiBenchMaxFPS); + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + SStrPrintf(text, sizeof(text), FrameScript_GetText("BENCHMARK_TAXI_AVERAGE_FPS", -1, GENDER_NOT_APPLICABLE), s_clientTaxiBenchTotalFrames / s_clientTaxiBenchTotalTime); + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); +} + +// VERIFY: 79999d66 manual +// OFFSET: 0x00405130 +void ClientUpdateTaxiBenchmarkMode() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + if (s_clientTaxiBenchIsOnTaxi) { + if (!(player->m_unit->m_unitFieldFlags & 0x100000) || !(player->m_player->m_playerFlags & 0x20000)) { + ClientEndTaxiBenchmarkMode(0); + } + } else if ((player->m_unit->m_unitFieldFlags & 0x100000) && (player->m_player->m_playerFlags & 0x20000)) { + ClientBeginTaxiBenchmarkMode(); + } + + if (!s_clientTaxiBenchEnabled) { + return; + } + + uint64_t now = OsGetAsyncTimeClocks(); + double elapsed = static_cast(static_cast(now - s_clientTaxiTimestamp)) / static_cast(OsGetAsyncClocksPerSecond()); + + if (elapsed <= 0.0) { + return; + } + + s_clientTaxiTimestamp = now; + + if (static_cast(OsGetAsyncTimeMs() - s_clientTaxiBenchDelayTime) < 0) { + return; + } + + s_clientTaxiBenchTotalFrames++; + double fps = 1.0 / elapsed; + s_clientTaxiBenchTotalTime += elapsed; + + if (fps <= s_clientTaxiBenchMinFPS) { + s_clientTaxiBenchMinFPS = fps; + } + + if (fps >= s_clientTaxiBenchMaxFPS) { + s_clientTaxiBenchMaxFPS = fps; + } +} + +// VERIFY: ada684ee auto +// OFFSET: 0x00403FC0 +void CheckAndSendBotDetected() { + if (!s_botCheckEnabled) { + return; + } + + ClientConnection* connection = ClientServices::Connection(); + + if (!s_gameInitialized || !connection) { + return; + } + + uint32_t now = OsGetAsyncTimeMs(); + + if (now - s_botCheckStartTime < 1000) { + return; + } + + s_botCheckStartTime = now; + + if (--s_botCheckDelay > 0) { + return; + } + + s_botCheckEnabled = 0; + + uint8_t check1; + uint8_t check2; + uint8_t check3; + + if (!GatherAdditionalChecks(&check1, &check2, &check3)) { + return; + } + + SHA1 sha; + sha.Prepare(); + sha.Process(connection->GetSessionKey(), sizeof(LoginData::m_sessionKey)); + sha.Process(&check1, sizeof(check1)); + sha.Process(&check2, sizeof(check2)); + sha.Process(&check3, sizeof(check3)); + sha.Process(connection->GetSessionKey(), sizeof(LoginData::m_sessionKey)); + SHA1::Digest digest; + sha.Finish(digest); + + WDataStore msg; + msg.Put(static_cast(CMSG_BOT_DETECTED)); + msg.Put(check1); + msg.Put(check2); + msg.Put(check3); + msg.PutArray(digest.m_data, sizeof(digest.m_data)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: b337a4a2 manual +// OFFSET: 0x00401390 +int32_t Packet_SMSG_PLAYED_TIME(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + int32_t total; + int32_t level; + uint8_t show = 0; + msg->Get(reinterpret_cast(total)); + msg->Get(reinterpret_cast(level)); + msg->Get(show); + + WOWGUID guid = ClntObjMgrGetActivePlayer(); + + if (guid) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + player->SetPlayedTime(total); + } + } + + if (show) { + char text[256]; + ConsolePrintf("Time played:"); + FormatTime(text, sizeof(text), total); + ConsolePrintf("Total: %s", text); + FormatTime(text, sizeof(text), level); + ConsolePrintf("Level: %s", text); + FrameScript_SignalEvent(SCRIPT_EVENT_TIME_PLAYED_MSG, "%d%d", total, level); + } + + return 1; +} diff --git a/WoW/Source/Client.h b/WoW/Source/Client.h index ae89cb3..f4bf3b2 100644 --- a/WoW/Source/Client.h +++ b/WoW/Source/Client.h @@ -113,6 +113,7 @@ struct ARCHIVELISTPARAMS { }; void CheckAndSendBotDetected(); +int32_t GatherAdditionalChecks(uint8_t* check1, uint8_t* check2, uint8_t* check3); void ClientUpdateTaxiBenchmarkMode(); void ListInterfaceArchive(const char* prefix, int32_t (*callback)(const char* fileName, void* param), void* param); diff --git a/WoW/Source/DB/DBClient/DBCache.h b/WoW/Source/DB/DBClient/DBCache.h index e8dcfdb..fc89420 100644 --- a/WoW/Source/DB/DBClient/DBCache.h +++ b/WoW/Source/DB/DBClient/DBCache.h @@ -9,6 +9,7 @@ #include "Engine/Source/BlizzardCore/Source/System/Using/Using.h" #include "Engine/Source/ConsoleBase/IConsole.h" #include "Engine/Source/Os/OsFile.h" +#include "Engine/Source/Os/TimeManager.h" #include "Engine/Source/Storm/H/stpl.h" #include "Engine/Source/Storm/H/storm.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" @@ -77,9 +78,11 @@ class DBCache : public Blizzard::Using::GlobalUse { void Invalidate(TKey key); REVERSEENTRY* FindReverseEntry(const char* name); T* GetRecordByName(const char* name); + void Idle(); void RemoveReverseEntry(const char* name); void ItemAdded(T* item); void Load(); + bool QueryLimitReached(); void RetryItem(TKey key); void Save(); void SendSingleQuery(DBCACHEHASH* hash); @@ -625,4 +628,39 @@ void DBCache::Invalidate(TKey key) { } } +// VERIFY: bad8a014 auto +// OFFSET: 0x00668890 +template +bool DBCache::QueryLimitReached() { + return this->m_maxQueriesPerPump && this->m_queriesSent >= this->m_maxQueriesPerPump; +} + +// VERIFY: 8c6b274a manual +// OFFSET: [0x00669350, 0x00669420, 0x006694F0, 0x006695C0, 0x00669690, 0x00669760, 0x00669830, 0x00669900, 0x006699D0, 0x00669AA0, 0x00669B70, 0x00669C40, 0x00669D10, 0x00669DE0] +template +void DBCache::Idle() { + if (!this->m_maxQueriesPerPump || !this->m_loaded) { + return; + } + + if (this->m_nextQueryTime && static_cast(OsGetAsyncTimeMs() - this->m_nextQueryTime) < 0) { + return; + } + + this->m_queriesSent = 0; + this->m_nextQueryTime = OsGetAsyncTimeMs() + 30000; + + DBCACHEHASH* next; + + for (DBCACHEHASH* hash = this->m_pending.Head(); !this->m_pending.IsEnd(hash); hash = next) { + next = this->m_pending.RawNext(hash); + this->m_pending.UnlinkNode(hash); + this->SendSingleQuery(hash); + + if (this->QueryLimitReached()) { + break; + } + } +} + #endif diff --git a/WoW/Source/DB/DBClient/DBCacheInstances.cpp b/WoW/Source/DB/DBClient/DBCacheInstances.cpp index 0f67125..fc00e97 100644 --- a/WoW/Source/DB/DBClient/DBCacheInstances.cpp +++ b/WoW/Source/DB/DBClient/DBCacheInstances.cpp @@ -625,3 +625,22 @@ void DBCache::AddItem(NameCache* item, uint64 this->Invalidate(key); } } + +// VERIFY: b863bbfc auto +// OFFSET: 0x00635100 +void DBCache_Idle() { + g_creatureDBCache.Idle(); + g_gameObjectDBCache.Idle(); + g_itemDBCache.Idle(); + g_itemNameDBCache.Idle(); + g_npcTextDBCache.Idle(); + g_nameDBCache.Idle(); + g_guildInfoCache.Idle(); + g_questDBCache.Idle(); + g_pageTextCache.Idle(); + g_petNameCache.Idle(); + g_petitionCache.Idle(); + g_itemTextDBCache.Idle(); + g_wardenCache.Idle(); + g_arenaTeamCache.Idle(); +} diff --git a/WoW/Source/DB/Rec/SpellRec.h b/WoW/Source/DB/Rec/SpellRec.h index 01c9f04..91fdc70 100644 --- a/WoW/Source/DB/Rec/SpellRec.h +++ b/WoW/Source/DB/Rec/SpellRec.h @@ -127,6 +127,7 @@ class SpellRec { static const int32_t* GetClassMask(const SpellRec* spell, int32_t effect); static bool IsAffectedBy(const SpellRec* spell, const SpellRec* modifier, int32_t effect); static bool UsableInShapeshift(const SpellRec* spell, int32_t form); + static bool NotUsableInShapeshiftForm(const SpellRec* spell, int32_t form); static int32_t GetCastTime(const SpellRec* spell, int32_t isPet, int32_t isUnit, int32_t allowNegative); static bool IsMeleeRange(const SpellRec* spell); static bool IsMinimumRange(const SpellRec* spell); diff --git a/WoW/Source/Game/ClientGameTime.cpp b/WoW/Source/Game/ClientGameTime.cpp index 18c5d18..c21a9d8 100644 --- a/WoW/Source/Game/ClientGameTime.cpp +++ b/WoW/Source/Game/ClientGameTime.cpp @@ -156,3 +156,21 @@ void ClientInitializeGameTime() { s_timeCallbacks[i] = nullptr; } } + +// VERIFY: 3f0c07d8 auto +// OFFSET: 0x007E27F0 +int32_t ClientGameTimeTickHandler(const void* data, void* param) { + g_clientGameTime.GameTimeUpdate(*static_cast(data)); + return 1; +} + +// VERIFY: c94f4e8a manual +// OFFSET: 0x007E2810 +void ClientDestroyGameTime() { + ClientServices::ClearMessageHandler(SMSG_GAME_SPEED_SET); + ClientServices::ClearMessageHandler(SMSG_LOGIN_SET_TIME_SPEED); + ClientServices::ClearMessageHandler(SMSG_GAME_TIME_UPDATE); + ClientServices::ClearMessageHandler(SMSG_SERVERTIME); + ClientServices::ClearMessageHandler(SMSG_GAME_TIME_SET); + g_clientGameTime.m_timeStamps.Clear(); +} diff --git a/WoW/Source/Game/GameClient/ComSatClient.cpp b/WoW/Source/Game/GameClient/ComSatClient.cpp index 3182ac6..37e9897 100644 --- a/WoW/Source/Game/GameClient/ComSatClient.cpp +++ b/WoW/Source/Game/GameClient/ComSatClient.cpp @@ -80,7 +80,7 @@ static TSFixedArray s_comsatCallbacks; static SMutex unk_D37D54; // STATIC: 0x00D37D88 -static TSHashTable unk_D37D88; +TSHashTable unk_D37D88; // STATIC: 0x00D37DB0 static TSHashTable unk_D37DB0; diff --git a/WoW/Source/Game/GameClient/ComSatClient.h b/WoW/Source/Game/GameClient/ComSatClient.h index 8aa76e6..2b82a08 100644 --- a/WoW/Source/Game/GameClient/ComSatClient.h +++ b/WoW/Source/Game/GameClient/ComSatClient.h @@ -61,6 +61,7 @@ struct COMSATDATA { extern COMSATDATA s_comsatData[32]; extern int32_t s_currentSession; +extern TSHashTable unk_D37D88; extern CVar* s_cvarEnableMicrophone; extern CVar* s_cvarEnableVoiceChat; extern CVar* s_cvarPushToTalkButton; @@ -98,7 +99,6 @@ extern int32_t s_comsatDisabledByClient; class SCritSect; extern SCritSect s_comsatDeviceLock; -int32_t Script_UnitIsTalking(lua_State* L); void VoiceRegisterScriptFunctions(); #endif diff --git a/WoW/Source/Game/GameClient/ComSatClient_Scripts.cpp b/WoW/Source/Game/GameClient/ComSatClient_Scripts.cpp index 4cc5fdb..3571e21 100644 --- a/WoW/Source/Game/GameClient/ComSatClient_Scripts.cpp +++ b/WoW/Source/Game/GameClient/ComSatClient_Scripts.cpp @@ -1,4 +1,6 @@ #include "ComSatClient.h" +#include "Engine/Source/lua-5.1/src/lua.h" +#include "WoW/Source/Ui/ChatFrame.h" #include #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" @@ -261,6 +263,25 @@ static int32_t Script_GetNumVoiceSessionMembersBySessionID(lua_State* L) { return 0; } +// VERIFY: 09dafb32 auto +// OFFSET: 0x007DF0B0 +static int32_t Script_UnitIsTalking(lua_State* L) { + if (!lua_isstring(L, 1)) { + return 0; + } + + WOWGUID guid = { 0 }; + CGChat::ChatTokenToGUID(lua_tolstring(L, 1, nullptr), guid); + + if (guid && unk_D37D88.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid))) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + // STATIC: 0x00AF29C0 static FrameScript_Method s_ScriptFunctions[] = { { "VoiceEnumerateOutputDevices", &Script_VoiceEnumerateOutputDevices }, diff --git a/WoW/Source/Game/GameClient/PlayerName.h b/WoW/Source/Game/GameClient/PlayerName.h index b6c0aca..a8a4abc 100644 --- a/WoW/Source/Game/GameClient/PlayerName.h +++ b/WoW/Source/Game/GameClient/PlayerName.h @@ -35,6 +35,7 @@ extern TSExplicitList s_player PLAYERNAMEDESC* PlayerNameCreate(const WOWGUID& guid); void PlayerNameDelete(PLAYERNAMEDESC* desc); void PlayerNameCreateText(PLAYERNAMEDESC* desc, uint32_t type, const char* text, const CImVector* color, const CImVector* shadowColor); +void PlayerNameDeleteText(PLAYERNAMEDESC* desc, uint32_t type); void PlayerNameTriggerColorUpdate(PLAYERNAMEDESC* desc); void PlayerNameTriggerNameRegenerate(PLAYERNAMEDESC* desc); diff --git a/WoW/Source/Game/GameTime.cpp b/WoW/Source/Game/GameTime.cpp index f00e951..a34c108 100644 --- a/WoW/Source/Game/GameTime.cpp +++ b/WoW/Source/Game/GameTime.cpp @@ -78,3 +78,98 @@ bool CGameTime::IsDaytime() { return time.InRange(start, end); } + +// VERIFY: 7db0b0c3 manual +// OFFSET: 0x0076D650 +void CGameTime::UpdateTimeStamps(int32_t minutes) { + HASHKEY_NONE key; + TIMESTAMPSTRUCT* stamp = this->m_timeStamps.Ptr(minutes, key); + + if (!stamp) { + return; + } + + TIMESTAMPCALLBACK* callback = stamp->m_callbacks.Head(); + + while (callback) { + TIMESTAMPCALLBACK* next = stamp->m_callbacks.Next(callback); + callback->m_callback(this, callback->m_param); + callback = next; + } +} + +// VERIFY: eef716d6 manual +// OFFSET: 0x0076D740 +void CGameTime::TickMinute() { + int32_t minutes = (this->GetHourAndMinutes() + 1) % 1440; + this->SetHourAndMinutes(minutes); + + if (!minutes) { + this->AddDays(1, false); + } + + this->m_minuteTicks++; + this->UpdateTimeStamps(minutes); + this->m_lastTickMs = OsGetAsyncTimeMs(); + this->m_running = 1; + this->m_baseMinuteOfDay = minutes + this->m_fracMinutes; +} + +// VERIFY: 71f0267b manual +// OFFSET: 0x0076D810 +void CGameTime::GameTimeSetTime(const WowTime& time, bool tick) { + WowTime newTime = time; + + if (this->m_minuteOffset) { + int32_t minutes = newTime.GetHourAndMinutes() + this->m_minuteOffset; + newTime.SetHourAndMinutes(minutes < 0 ? minutes + 1440 : minutes % 1440); + } + + if (this->m_dayOffset) { + newTime.AddDays(this->m_dayOffset, false); + } + + newTime.m_tzHours = time.m_tzHours; + *static_cast(this) = newTime; + + if (!tick) { + return; + } + + if (this->m_minute) { + this->m_minute--; + } else { + this->m_minute = 59; + + if (this->m_hour) { + this->m_hour--; + } else { + this->m_hour = 23; + this->AddDays(-1, false); + } + } + + this->TickMinute(); +} + +// VERIFY: b37d545d manual +// OFFSET: 0x0076D900 +void CGameTime::GameTimeUpdate(float elapsed) { + this->m_fracMinutes = this->m_minutesPerSecond * elapsed + this->m_fracMinutes; + + if (this->m_elapsedMinutes && this->m_fracMinutes >= 1.0f) { + uint32_t minutes = static_cast(this->m_fracMinutes); + + if (this->m_elapsedMinutes < minutes) { + minutes = this->m_elapsedMinutes; + } + + this->m_elapsedMinutes -= minutes; + this->m_fracMinutes -= minutes; + } + + while (this->m_fracMinutes >= 1.0f) { + this->m_fracMinutes -= 1.0f; + this->TickMinute(); + } +} diff --git a/WoW/Source/Game/GameTime.h b/WoW/Source/Game/GameTime.h index 3261ef3..69e7c4f 100644 --- a/WoW/Source/Game/GameTime.h +++ b/WoW/Source/Game/GameTime.h @@ -15,7 +15,7 @@ class CGameTime : public WowTime { /* 002C */ int32_t m_minuteTicks; /* 0030 */ float m_minutesPerSecond; /* 0034 */ float m_fracMinutes; - /* 0038 */ int32_t m_elapsedMinutes; + /* 0038 */ uint32_t m_elapsedMinutes; /* 003C */ uint32_t m_lastTickMs; /* 0040 */ uint8_t m_running; /* 0041 */ uint8_t unk_0041[3]; @@ -27,9 +27,12 @@ class CGameTime : public WowTime { CGameTime(); float GameTimeGetDayProgression(); float GameTimeSetMinutesPerSecond(float minutesPerSecond); - void GameTimeSetTime(const WowTime& time, bool a2); + void GameTimeSetTime(const WowTime& time, bool tick); void GameTimeSync(const WowTime& time, bool a2); + void GameTimeUpdate(float elapsed); bool IsDaytime(); + void TickMinute(); + void UpdateTimeStamps(int32_t minutes); }; extern CGameTime g_clientGameTime; diff --git a/WoW/Source/Magic/MagicClient/SpellVisuals.cpp b/WoW/Source/Magic/MagicClient/SpellVisuals.cpp index 524e91d..1e31e20 100644 --- a/WoW/Source/Magic/MagicClient/SpellVisuals.cpp +++ b/WoW/Source/Magic/MagicClient/SpellVisuals.cpp @@ -9,6 +9,16 @@ #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/UIUtil/Camera.h" #include "WoW/Source/Ui/WorldFrame.h" +#include "Engine/Source/Os/TimeManager.h" +#include "Engine/Source/Model2/M2Model.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Object/ObjectClient/Effect_C.h" +#include "WoW/Source/Object/MovementShared.h" +#include "WoW/Source/DB/Rec/SpellEffectCameraShakesRec.h" +#include "WoW/Source/WorldClient/DayNight__DNInfo.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/DB/Rec/SpellRec.h" // STATIC: 0x00D39750 static CLightningManager* s_lightningManager; @@ -28,6 +38,12 @@ static CDataAllocator s_blizzardObjectHeap(sizeof(BlizzardObject), 8); // STATIC: 0x00D39770 static CDataAllocator s_shardHeap(sizeof(Shard), 32); +// STATIC: 0x00D39798 +static EclipseState s_eclipse; + +// STATIC: 0x00AF50AC +static TSList s_mountTransitions; + // STATIC: 0x00D39758 static TSGrowableArray*>* s_modelAttachLookup; @@ -133,3 +149,146 @@ int32_t SpellVisualsIsMountTransitionFinished(const MountTransitionObject* trans void SpellVisualsRender() { s_lightningManager->Render(CGWorldFrame::GetActiveCamera()->m_position); } + +// VERIFY: 6a5e8212 auto +// OFFSET: 0x007F9F00 +float SpellVisualsGetMountTransitionHeight(const MountTransitionObject* transition) { + return transition->m_height; +} + +// VERIFY: 21a8f719 auto +// OFFSET: 0x007F9F60 +void SpellVisualsFlagMountTransitionFinished(MountTransitionObject* transition) { + transition->unk_0078 |= 0x2; +} + +// VERIFY: 985816b3 auto +// OFFSET: 0x007FA620 +void SpellVisualsPlayCameraShakeID(int32_t id, const C3Vector* position) { + SpellEffectCameraShakesRec* rec = g_spellEffectCameraShakesDB.GetRecord(id); + + if (!rec) { + return; + } + + for (uint32_t i = 0; i < 3; i++) { + if (rec->m_cameraShake[i]) { + CGWorldFrame::GetActiveCamera()->AddShakeById(rec->m_cameraShake[i], position); + } + } +} + +// VERIFY: 3532766c auto +// OFFSET: 0x007FA680 +void SpellVisualsBlizzardSetFrameOfReference(BlizzardObject* object, const C44Matrix* matrix) { + object->SetFrameOfReference(matrix); +} + +// VERIFY: eeefbc3b manual +// OFFSET: 0x007FA930 +void SpellVisualsComputeMountTransitionJumpVec(const MountTransitionObject* transition, C3Vector* jump) { + *jump = transition->m_jumpVector; + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(transition->m_unitGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit || !unit->m_mountTransitionEffect) { + return; + } + + CM2Model* model = unit->m_mountTransitionEffect->m_model; + + if (!model) { + return; + } + + C3Vector world = model->GetWorldPosition(); + C3Vector attach = model->GetAttachmentPosition(0); + jump->x = attach.x - world.x; + jump->y = attach.y - world.y; + jump->z = attach.z - world.z; + + float height = transition->m_height; + jump->x = jump->x * height; + jump->y = jump->y * height; + jump->z = height * jump->z; +} + +// VERIFY: 32467c5c manual +// OFFSET: 0x007FA9F0 +uint32_t SpellVisualsGetModelAttachRecCount(uint32_t kitId) { + if (kitId < s_modelAttachLookup->m_count && s_modelAttachLookup->m_data[kitId]) { + return s_modelAttachLookup->m_data[kitId]->m_count; + } + + return 0; +} + +// VERIFY: 778c397e auto +// OFFSET: 0x007FBE00 +MountTransitionObject* SpellVisualsStartMountTransition(CGUnit_C* unit) { + MountTransitionObject* transition = s_mountTransitions.NewNode(2, 0, 0); + + if (!transition) { + return nullptr; + } + + transition->unk_0078 = 0; + transition->m_unitGuid = unit->m_obj->m_guid; + transition->m_groundNormal = unit->m_movement->GetGroundNormal(); + transition->m_startTime = OsGetAsyncTimeMs(); + transition->unk_0020 = 0.0f; + transition->unk_0024 = 0.0f; + transition->unk_0028 = 0.0f; + transition->unk_007C = 0.0f; + transition->unk_0080 = OsGetAsyncTimeMs(); + return transition; +} + +// VERIFY: c6399436 auto +// OFFSET: 0x007FC9D0 +void SpellVisualsCancelMountTransition(MountTransitionObject* transition) { + if (transition) { + s_mountTransitions.DeleteNode(transition); + } +} + +// VERIFY: 1bb4ee05 auto +// OFFSET: 0x007FAA20 +const SpellVisualKitModelAttachRec* SpellVisualsGetModelAttachRec(uint32_t kitId, uint32_t index) { + return s_modelAttachLookup->m_data[kitId]->m_data[index]; +} + +// VERIFY: 4bfbe4ed manual +// OFFSET: 0x007F9E10 +void EclipseState::Update(uint32_t time) { + if (this->m_start == this->m_end) { + return; + } + + float blend = 0.0f; + + if (time < this->m_fadeInEnd) { + blend = static_cast(time - this->m_start) / static_cast(this->m_fadeInEnd - this->m_start); + } else if (time < this->m_holdEnd) { + blend = 1.0f; + } else if (time < this->m_end) { + blend = 1.0f - static_cast(time - this->m_holdEnd) / static_cast(this->m_end - this->m_holdEnd); + } else { + this->m_end = 0; + this->m_start = 0; + } + + DayNight::SetFlashColor(this->m_color, blend); +} + +// VERIFY: 21c0a07b manual +// OFFSET: 0x007FA450 +void SpellVisualsHandleEclipse(const CImVector* color, float fadeIn, const SpellRec* spell) { + uint32_t castTime = SpellRec::GetCastTime(spell, 0, 0, 0); + s_eclipse.m_color = *color; + uint32_t now = OsGetAsyncTimeMs(); + s_eclipse.m_start = now; + s_eclipse.m_holdEnd = now + castTime; + s_eclipse.m_fadeInEnd = static_cast(castTime * fadeIn) + now; + s_eclipse.m_end = now + castTime + 100; +} diff --git a/WoW/Source/Magic/MagicClient/SpellVisuals.h b/WoW/Source/Magic/MagicClient/SpellVisuals.h index 1cbbd05..987b714 100644 --- a/WoW/Source/Magic/MagicClient/SpellVisuals.h +++ b/WoW/Source/Magic/MagicClient/SpellVisuals.h @@ -4,8 +4,15 @@ #include #include #include "Engine/Source/Storm/H/stpl.h" +#include "Engine/Source/Tempest/C3Vector.h" +#include "Engine/Source/Tempest/CImVector.h" +#include "WoW/Source/Object/WGUID.h" struct CVar; +class SpellVisualKitModelAttachRec; +class C44Matrix; +class SpellRec; +class CGUnit_C; class BlizzardObject : public TSLinkedNode { public: @@ -26,6 +33,18 @@ class BlizzardObject : public TSLinkedNode { /* 0184 */ uint32_t unk_0184; ~BlizzardObject(); + void SetFrameOfReference(const C44Matrix* matrix); +}; + +class EclipseState { + public: + /* 0000 */ CImVector m_color; + /* 0004 */ uint32_t m_start; + /* 0008 */ uint32_t m_fadeInEnd; + /* 000C */ uint32_t m_holdEnd; + /* 0010 */ uint32_t m_end; + + void Update(uint32_t time); }; class Shard { @@ -60,21 +79,19 @@ class LightningObject : public TSLinkedNode { ~LightningObject(); }; -class MountTransitionObject { +void LightningObjectReleaseRef(LightningObject* object); + +class MountTransitionObject : public TSLinkedNode { public: - /* 0000 */ uint8_t unk_0000[8]; - /* 0008 */ uint32_t unk_0008; - /* 000C */ uint32_t unk_000C; - /* 0010 */ uint32_t unk_0010; + /* 0008 */ WOWGUID m_unitGuid; + /* 0010 */ float m_height; /* 0014 */ uint32_t unk_0014; /* 0018 */ uint32_t unk_0018; /* 001C */ uint32_t unk_001C; - /* 0020 */ uint32_t unk_0020; - /* 0024 */ uint32_t unk_0024; - /* 0028 */ uint32_t unk_0028; - /* 002C */ uint32_t unk_002C; - /* 0030 */ uint32_t unk_0030; - /* 0034 */ uint32_t unk_0034; + /* 0020 */ float unk_0020; + /* 0024 */ float unk_0024; + /* 0028 */ float unk_0028; + /* 002C */ C3Vector m_jumpVector; /* 0038 */ uint32_t unk_0038; /* 003C */ uint32_t unk_003C; /* 0040 */ uint32_t unk_0040; @@ -82,17 +99,15 @@ class MountTransitionObject { /* 0048 */ uint32_t unk_0048; /* 004C */ uint32_t unk_004C; /* 0050 */ uint32_t unk_0050; - /* 0054 */ uint32_t unk_0054; - /* 0058 */ uint32_t unk_0058; - /* 005C */ uint32_t unk_005C; - /* 0060 */ uint32_t unk_0060; + /* 0054 */ C3Vector m_groundNormal; + /* 0060 */ uint32_t m_startTime; /* 0064 */ uint32_t unk_0064; /* 0068 */ uint32_t unk_0068; /* 006C */ uint32_t unk_006C; /* 0070 */ uint32_t unk_0070; /* 0074 */ uint32_t unk_0074; /* 0078 */ uint32_t unk_0078; - /* 007C */ uint32_t unk_007C; + /* 007C */ float unk_007C; /* 0080 */ uint32_t unk_0080; }; @@ -107,5 +122,15 @@ void SpellVisualsClear(); void SpellVisualsShutdown(); void SpellVisualsShutdownModelAttachLookup(); int32_t SpellVisualsIsMountTransitionFinished(const MountTransitionObject* transition); +float SpellVisualsGetMountTransitionHeight(const MountTransitionObject* transition); +void SpellVisualsFlagMountTransitionFinished(MountTransitionObject* transition); +void SpellVisualsPlayCameraShakeID(int32_t id, const C3Vector* position); +void SpellVisualsBlizzardSetFrameOfReference(BlizzardObject* object, const C44Matrix* matrix); +void SpellVisualsComputeMountTransitionJumpVec(const MountTransitionObject* transition, C3Vector* jump); +uint32_t SpellVisualsGetModelAttachRecCount(uint32_t kitId); +const SpellVisualKitModelAttachRec* SpellVisualsGetModelAttachRec(uint32_t kitId, uint32_t index); +MountTransitionObject* SpellVisualsStartMountTransition(CGUnit_C* unit); +void SpellVisualsCancelMountTransition(MountTransitionObject* transition); +void SpellVisualsHandleEclipse(const CImVector* color, float fadeIn, const SpellRec* spell); #endif diff --git a/WoW/Source/Magic/MagicClient/Spell_C.cpp b/WoW/Source/Magic/MagicClient/Spell_C.cpp index b2d823d..9610ccf 100644 --- a/WoW/Source/Magic/MagicClient/Spell_C.cpp +++ b/WoW/Source/Magic/MagicClient/Spell_C.cpp @@ -1,4 +1,5 @@ #include "Spell_C.h" +#include "WoW/Source/Magic/Types.h" #include "Engine/Source/Base/CDataStore.h" #include "Engine/Source/ConsoleBase/ConsoleVar.h" #include "Engine/Source/Tempest/CMath.h" @@ -60,6 +61,35 @@ #include "WoW/Source/Object/ObjectClient/VehiclePassenger_C.h" #include "WoW/Source/Ui/PaperDollInfoFrame.h" #include "WoW/Source/WowServices/WDataStore.h" +#include "WoW/Source/DB/Rec/SpellRadiusRec.h" +#include "WoW/Source/Magic/Spell.h" +#include "WoW/Source/DB/Rec/VehicleSeatRec.h" +#include "WoW/Source/Object/ObjectClient/Vehicle_C.h" +#include "Engine/Source/lua-5.1/src/lua.h" +#include "WoW/Source/Ui/TradeFrame.h" +#include "WoW/Source/DB/Rec/SkillLineAbilityRec.h" +#include "WoW/Source/DB/Rec/ItemSubClassRec.h" +#include "WoW/Source/DB/Rec/ItemSubClassMaskRec.h" +#include "WoW/Source/DB/Rec/PowerDisplayRec.h" +#include "WoW/Source/DB/Rec/AreaTableRec.h" +#include "WoW/Source/DB/Rec/SpellFocusObjectRec.h" +#include "WoW/Source/DB/Rec/SpellMechanicRec.h" +#include "WoW/Source/DB/Rec/ItemLimitCategoryRec.h" +#include "WoW/Source/DB/Rec/TotemCategoryRec.h" +#include "WoW/Source/DB/Rec/SkillLineRec.h" +#include "WoW/Source/UIUtil/Tooltip.h" +#include "WoW/Source/Ui/Tutorial.h" +#include "WoW/Source/Ui/UIMacros.h" +#include "Engine/Source/Event/Event.h" +#include "Engine/Source/ConsoleBase/IConsole.h" +#include "WoW/Source/WorldClient/FrameTime.h" +#include "WoW/Source/DB/Rec/GameObjectDisplayInfoRec.h" +#include "Engine/Source/Model2/M2Scene.h" +#include "WoW/Source/WorldClient/Map.h" +#include "WoW/Source/Object/GameObjectStats.h" +#include "Engine/Source/Frame/CSimpleTop.h" +#include "WoW/Source/DB/Rec/GlyphPropertiesRec.h" +#include "WoW/Source/DB/Rec/GlyphSlotRec.h" #if defined(_MSC_VER) #include #else @@ -85,7 +115,7 @@ uint32_t s_needTargets; PendingSpellCast* s_targetingSpell; // STATIC: 0x00D3F4E8 -static uint32_t unk_D3F4E8; +static PendingSpellCast* s_delayedTrajectoryCast; // STATIC: 0x00D397B0 static CVar* s_enableErrorSpeechCVar; @@ -97,11 +127,20 @@ static int32_t s_spellClassSet; static const CSoftFloat s_softPercent = { 0x3C23D70A }; // STATIC: 0x00D397B8 -static uint32_t unk_D397B8; +static uint32_t s_feedPetSpell; // STATIC: 0x00D397C4 static uint32_t unk_D397C4; +// STATIC: 0x00D397C0 +static int32_t s_lastFailedReason; + +// STATIC: 0x00D397BC +static uint32_t s_lastFailedTime; + +// STATIC: 0x00A439C8 +static const UIErrors s_powerErrors[] = { ERR_OUT_OF_MANA, ERR_OUT_OF_RAGE, ERR_OUT_OF_FOCUS, ERR_OUT_OF_ENERGY, ERR_NOT_HAPPY_ENOUGH, ERR_OUT_OF_RUNES, ERR_OUT_OF_RUNIC_POWER }; + // STATIC: 0x00D397D8 static int32_t s_spellPctModifiers[96][31]; @@ -138,6 +177,30 @@ static uint8_t s_cursorWorldObjectHousing; // STATIC: 0x00D3F4DC static float s_cursorWorldObjectFacing; +// STATIC: 0x00D3F578 +static C3Vector s_cursorWorldObjectPosition; + +// STATIC: 0x00D3F4D8 +static float s_cursorWorldObjectScale; + +// STATIC: 0x00D3F4F0 +static char s_targetString[128]; + +// STATIC: 0x00AF53C4 +static uint8_t s_meleeTutorialActive; + +// STATIC: 0x00D3F604 +static uint32_t s_meleeTutorialCount; + +// STATIC: 0x00D3F584 +static TSHashTable s_itemCooldowns; + +// STATIC: 0x00AF5264 +static TSList> s_periodicClientTriggers; + +// STATIC: 0x00D3F5DC +static TSHashTable s_destLocSpellCasts; + // VERIFY: f852b51c manual // OFFSET: 0x008008D0 void Spell_C_CancelChannelSpell(int32_t spellId) { @@ -188,7 +251,7 @@ void Spell_C_ClearLastAutoRangedCombatError() { s_lastAutoRangedCombatError = 187; } -// VERIFY: e5501e2c manual +// VERIFY: 7a4c1c3e manual // OFFSET: 0x0080C340 bool Spell_C_HandleTerrainClick(const CTerrainClickEvent& evt) { PendingSpellCast* spell = s_targetingSpell; @@ -216,7 +279,7 @@ bool Spell_C_HandleTerrainClick(const CTerrainClickEvent& evt) { s_needTargets = needTargets; if (!needTargets) { - Spell_C::SendPendingCast(false); + Spell_C::SendPendingCast(spell, false); } return true; @@ -436,7 +499,7 @@ int32_t Spell_C_NeedsCooldownEvent(int32_t itemId) { return 0; } -// VERIFY: 091fab9f manual +// VERIFY: a6fcb014 manual // OFFSET: 0x0080B5D0 bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID& target, const ItemStats_C* item, bool ignoreControl) { if (!unit) { @@ -479,11 +542,11 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID if (!CGGameUI::m_hasControl && !ignoreControl) { int32_t allowed = 0; - if ((unit->m_unit->m_unitFieldFlags & 0x800000) && ((spell->m_attributesExE & 0x20000) || Spell_C_CancelsAuraEffect(spell, 7, 0))) { + if ((unit->m_unit->m_unitFieldFlags & 0x800000) && ((spell->m_attributesExE & 0x20000) || Spell_C_CancelsAuraEffect(unit, spell, 7, nullptr))) { allowed = 1; } - if ((unit->m_unit->m_unitFieldFlags & 0x400000) && ((spell->m_attributesExE & 0x40000) || Spell_C_CancelsAuraEffect(spell, 5, 0))) { + if ((unit->m_unit->m_unitFieldFlags & 0x400000) && ((spell->m_attributesExE & 0x40000) || Spell_C_CancelsAuraEffect(unit, spell, 5, nullptr))) { allowed = 1; } @@ -500,7 +563,7 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID return false; } - if (!Spell_C_HaveEquippedSpellItems(unit, spell, true, nullptr)) { + if (!Spell_C_HaveEquippedSpellItems(unit, spell, true, false, nullptr)) { return false; } @@ -516,7 +579,7 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID int32_t reason; - if (!unit->CheckShapeshiftRules(spell, &reason) && (reason == 94 || !unit->CanAutoCancelShapeshift())) { + if (!unit->CheckShapeshiftRules(spell, &reason) && (reason == 94 || !unit->CanAutoUnshift())) { return false; } @@ -534,13 +597,13 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID int32_t casterAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_casterAuraSpell); - if (casterAura && !unit->HasAura(casterAura) && !unit->IgnoresAuraState(spell)) { + if (casterAura && !unit->HasAuraBySpellId(casterAura) && !unit->IgnoresAuraState(spell)) { return false; } int32_t excludeCasterAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_excludeCasterAuraSpell); - if (excludeCasterAura && unit->HasAura(excludeCasterAura) && !unit->IgnoresAuraState(spell)) { + if (excludeCasterAura && unit->HasAuraBySpellId(excludeCasterAura) && !unit->IgnoresAuraState(spell)) { return false; } @@ -573,11 +636,11 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID return false; } - if (targetAura && !targetUnit->HasAura(targetAura) && !unit->IgnoresAuraState(spell)) { + if (targetAura && !targetUnit->HasAuraBySpellId(targetAura) && !unit->IgnoresAuraState(spell)) { return false; } - if (excludeTargetAura && targetUnit->HasAura(excludeTargetAura) && !unit->IgnoresAuraState(spell)) { + if (excludeTargetAura && targetUnit->HasAuraBySpellId(excludeTargetAura) && !unit->IgnoresAuraState(spell)) { return false; } @@ -634,7 +697,7 @@ bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID return (!(spell->m_attributesExD & 0x4000000) || static_cast(unit)->IsInFlyableZone(1)) && (!(spell->m_attributesExC & 0x800) || !map || map->m_instanceType == 3) && (!(spell->m_attributesExF & 0x800) || !map || map->m_instanceType != 2); } -// VERIFY: e4a633f9 auto +// VERIFY: e589f6bd auto // OFFSET: 0x008100E0 void Spell_C_Initialize() { ClientServices::SetMessageHandler(SMSG_SPELL_START, Packet_Group_30, nullptr); @@ -673,9 +736,9 @@ void Spell_C_Initialize() { s_autoRangedCombatSpell = 0; s_lastAutoRangedCombatError = 187; unk_D397C4 = 0; - unk_D397B8 = 0; + s_feedPetSpell = 0; s_spellClassSet = 0; - unk_D3F4E8 = 0; + s_delayedTrajectoryCast = nullptr; s_enableErrorSpeechCVar = CVar::Lookup("Sound_EnableErrorSpeech"); } @@ -1713,7 +1776,7 @@ void SpellHistory::GarbageCollect(uint32_t time) { } } -// VERIFY: 41117beb manual +// VERIFY: 234969f9 manual // OFFSET: 0x0080E1B0 void PendingSpellCast::OnSpellGo(CDataStore* msg) { WOWGUID castItem = this->m_data.m_castItem; @@ -2128,7 +2191,7 @@ void PendingSpellCast::OnSpellGo(CDataStore* msg) { LaunchMissileVisual(hits, misses, unit, &spell, visual, ammoDisplayId, ammoInventoryType, &this->m_data, missReasons, reflectResults, delay); if ((visual->m_hasMissile || ammoDisplayId) && points.m_count) { - unit->CreateMissile(points, &this->m_data, ammoDisplayId, ammoInventoryType, visual, spell.m_id, delay); + unit->CreateMissile(&points, &this->m_data, ammoDisplayId, ammoInventoryType, visual, spell.m_id, delay); } } else { CreateMissilesForTargets(hits, unit, &spell, visual, ammoDisplayId, ammoInventoryType, &this->m_data, nullptr, nullptr, delay); @@ -2417,10 +2480,10 @@ int32_t Spell_C_IsCursorWorldObjectHousing() { return s_cursorWorldObjectHousing; } -// VERIFY: 61051f38 auto +// VERIFY: 53c745f7 auto // OFFSET: 0x007FE1A0 void SpellSetFeedPetSpell(int32_t spellId) { - unk_D397B8 = spellId; + s_feedPetSpell = spellId; } // VERIFY: 54519a8f manual @@ -3789,3 +3852,5112 @@ bool Spell_C_GetItemCooldown(CGItem_C* item, uint32_t* duration, uint32_t* start return s_spellHistory[0].GetSpellCooldown(item->GetEnchantmentSpell(0), item->m_obj->m_entryID, duration, start, enable); } + +// VERIFY: dac09432 auto +// OFFSET: 0x007FCCA0 +const char* GetSpellFailedResult(int32_t reason) { + switch (reason) { + case SPELL_FAILED_SUCCESS: + return "SPELL_FAILED_SUCCESS"; + case SPELL_FAILED_AFFECTING_COMBAT: + return "SPELL_FAILED_AFFECTING_COMBAT"; + case SPELL_FAILED_ALREADY_AT_FULL_HEALTH: + return "SPELL_FAILED_ALREADY_AT_FULL_HEALTH"; + case SPELL_FAILED_ALREADY_AT_FULL_MANA: + return "SPELL_FAILED_ALREADY_AT_FULL_MANA"; + case SPELL_FAILED_ALREADY_AT_FULL_POWER: + return "SPELL_FAILED_ALREADY_AT_FULL_POWER"; + case SPELL_FAILED_ALREADY_BEING_TAMED: + return "SPELL_FAILED_ALREADY_BEING_TAMED"; + case SPELL_FAILED_ALREADY_HAVE_CHARM: + return "SPELL_FAILED_ALREADY_HAVE_CHARM"; + case SPELL_FAILED_ALREADY_HAVE_SUMMON: + return "SPELL_FAILED_ALREADY_HAVE_SUMMON"; + case SPELL_FAILED_ALREADY_OPEN: + return "SPELL_FAILED_ALREADY_OPEN"; + case SPELL_FAILED_AURA_BOUNCED: + return "SPELL_FAILED_AURA_BOUNCED"; + case SPELL_FAILED_AUTOTRACK_INTERRUPTED: + return "SPELL_FAILED_AUTOTRACK_INTERRUPTED"; + case SPELL_FAILED_BAD_IMPLICIT_TARGETS: + return "SPELL_FAILED_BAD_IMPLICIT_TARGETS"; + case SPELL_FAILED_BAD_TARGETS: + return "SPELL_FAILED_BAD_TARGETS"; + case SPELL_FAILED_CANT_BE_CHARMED: + return "SPELL_FAILED_CANT_BE_CHARMED"; + case SPELL_FAILED_CANT_BE_DISENCHANTED: + return "SPELL_FAILED_CANT_BE_DISENCHANTED"; + case SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL: + return "SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL"; + case SPELL_FAILED_CANT_BE_MILLED: + return "SPELL_FAILED_CANT_BE_MILLED"; + case SPELL_FAILED_CANT_BE_PROSPECTED: + return "SPELL_FAILED_CANT_BE_PROSPECTED"; + case SPELL_FAILED_CANT_CAST_ON_TAPPED: + return "SPELL_FAILED_CANT_CAST_ON_TAPPED"; + case SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE: + return "SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE"; + case SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED: + return "SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED"; + case SPELL_FAILED_CANT_STEALTH: + return "SPELL_FAILED_CANT_STEALTH"; + case SPELL_FAILED_CASTER_AURASTATE: + return "SPELL_FAILED_CASTER_AURASTATE"; + case SPELL_FAILED_CASTER_DEAD: + return "SPELL_FAILED_CASTER_DEAD"; + case SPELL_FAILED_CHARMED: + return "SPELL_FAILED_CHARMED"; + case SPELL_FAILED_CHEST_IN_USE: + return "SPELL_FAILED_CHEST_IN_USE"; + case SPELL_FAILED_CONFUSED: + return "SPELL_FAILED_CONFUSED"; + case SPELL_FAILED_DONT_REPORT: + return "SPELL_FAILED_DONT_REPORT"; + case SPELL_FAILED_EQUIPPED_ITEM: + return "SPELL_FAILED_EQUIPPED_ITEM"; + case SPELL_FAILED_EQUIPPED_ITEM_CLASS: + return "SPELL_FAILED_EQUIPPED_ITEM_CLASS"; + case SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND: + return "SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND"; + case SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND: + return "SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND"; + case SPELL_FAILED_ERROR: + return "SPELL_FAILED_ERROR"; + case SPELL_FAILED_FIZZLE: + return "SPELL_FAILED_FIZZLE"; + case SPELL_FAILED_FLEEING: + return "SPELL_FAILED_FLEEING"; + case SPELL_FAILED_FOOD_LOWLEVEL: + return "SPELL_FAILED_FOOD_LOWLEVEL"; + case SPELL_FAILED_HIGHLEVEL: + return "SPELL_FAILED_HIGHLEVEL"; + case SPELL_FAILED_HUNGER_SATIATED: + return "SPELL_FAILED_HUNGER_SATIATED"; + case SPELL_FAILED_IMMUNE: + return "SPELL_FAILED_IMMUNE"; + case SPELL_FAILED_INCORRECT_AREA: + return "SPELL_FAILED_INCORRECT_AREA"; + case SPELL_FAILED_INTERRUPTED: + return "SPELL_FAILED_INTERRUPTED"; + case SPELL_FAILED_INTERRUPTED_COMBAT: + return "SPELL_FAILED_INTERRUPTED_COMBAT"; + case SPELL_FAILED_ITEM_ALREADY_ENCHANTED: + return "SPELL_FAILED_ITEM_ALREADY_ENCHANTED"; + case SPELL_FAILED_ITEM_GONE: + return "SPELL_FAILED_ITEM_GONE"; + case SPELL_FAILED_ITEM_NOT_FOUND: + return "SPELL_FAILED_ITEM_NOT_FOUND"; + case SPELL_FAILED_ITEM_NOT_READY: + return "SPELL_FAILED_ITEM_NOT_READY"; + case SPELL_FAILED_LEVEL_REQUIREMENT: + return "SPELL_FAILED_LEVEL_REQUIREMENT"; + case SPELL_FAILED_LINE_OF_SIGHT: + return "SPELL_FAILED_LINE_OF_SIGHT"; + case SPELL_FAILED_LOWLEVEL: + return "SPELL_FAILED_LOWLEVEL"; + case SPELL_FAILED_LOW_CASTLEVEL: + return "SPELL_FAILED_LOW_CASTLEVEL"; + case SPELL_FAILED_MAINHAND_EMPTY: + return "SPELL_FAILED_MAINHAND_EMPTY"; + case SPELL_FAILED_MOVING: + return "SPELL_FAILED_MOVING"; + case SPELL_FAILED_NEED_AMMO: + return "SPELL_FAILED_NEED_AMMO"; + case SPELL_FAILED_NEED_AMMO_POUCH: + return "SPELL_FAILED_NEED_AMMO_POUCH"; + case SPELL_FAILED_NEED_EXOTIC_AMMO: + return "SPELL_FAILED_NEED_EXOTIC_AMMO"; + case SPELL_FAILED_NEED_MORE_ITEMS: + return "SPELL_FAILED_NEED_MORE_ITEMS"; + case SPELL_FAILED_NOPATH: + return "SPELL_FAILED_NOPATH"; + case SPELL_FAILED_NOT_BEHIND: + return "SPELL_FAILED_NOT_BEHIND"; + case SPELL_FAILED_NOT_FISHABLE: + return "SPELL_FAILED_NOT_FISHABLE"; + case SPELL_FAILED_NOT_FLYING: + return "SPELL_FAILED_NOT_FLYING"; + case SPELL_FAILED_NOT_HERE: + return "SPELL_FAILED_NOT_HERE"; + case SPELL_FAILED_NOT_INFRONT: + return "SPELL_FAILED_NOT_INFRONT"; + case SPELL_FAILED_NOT_IN_CONTROL: + return "SPELL_FAILED_NOT_IN_CONTROL"; + case SPELL_FAILED_NOT_KNOWN: + return "SPELL_FAILED_NOT_KNOWN"; + case SPELL_FAILED_NOT_MOUNTED: + return "SPELL_FAILED_NOT_MOUNTED"; + case SPELL_FAILED_NOT_ON_TAXI: + return "SPELL_FAILED_NOT_ON_TAXI"; + case SPELL_FAILED_NOT_ON_TRANSPORT: + return "SPELL_FAILED_NOT_ON_TRANSPORT"; + case SPELL_FAILED_NOT_READY: + return "SPELL_FAILED_NOT_READY"; + case SPELL_FAILED_NOT_SHAPESHIFT: + return "SPELL_FAILED_NOT_SHAPESHIFT"; + case SPELL_FAILED_NOT_STANDING: + return "SPELL_FAILED_NOT_STANDING"; + case SPELL_FAILED_NOT_TRADEABLE: + return "SPELL_FAILED_NOT_TRADEABLE"; + case SPELL_FAILED_NOT_TRADING: + return "SPELL_FAILED_NOT_TRADING"; + case SPELL_FAILED_NOT_UNSHEATHED: + return "SPELL_FAILED_NOT_UNSHEATHED"; + case SPELL_FAILED_NOT_WHILE_GHOST: + return "SPELL_FAILED_NOT_WHILE_GHOST"; + case SPELL_FAILED_NOT_WHILE_LOOTING: + return "SPELL_FAILED_NOT_WHILE_LOOTING"; + case SPELL_FAILED_NO_AMMO: + return "SPELL_FAILED_NO_AMMO"; + case SPELL_FAILED_NO_CHARGES_REMAIN: + return "SPELL_FAILED_NO_CHARGES_REMAIN"; + case SPELL_FAILED_NO_CHAMPION: + return "SPELL_FAILED_NO_CHAMPION"; + case SPELL_FAILED_NO_COMBO_POINTS: + return "SPELL_FAILED_NO_COMBO_POINTS"; + case SPELL_FAILED_NO_DUELING: + return "SPELL_FAILED_NO_DUELING"; + case SPELL_FAILED_NO_ENDURANCE: + return "SPELL_FAILED_NO_ENDURANCE"; + case SPELL_FAILED_NO_FISH: + return "SPELL_FAILED_NO_FISH"; + case SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED: + return "SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED"; + case SPELL_FAILED_NO_MOUNTS_ALLOWED: + return "SPELL_FAILED_NO_MOUNTS_ALLOWED"; + case SPELL_FAILED_NO_PET: + return "SPELL_FAILED_NO_PET"; + case SPELL_FAILED_NO_POWER: + return "SPELL_FAILED_NO_POWER"; + case SPELL_FAILED_NOTHING_TO_DISPEL: + return "SPELL_FAILED_NOTHING_TO_DISPEL"; + case SPELL_FAILED_NOTHING_TO_STEAL: + return "SPELL_FAILED_NOTHING_TO_STEAL"; + case SPELL_FAILED_ONLY_ABOVEWATER: + return "SPELL_FAILED_ONLY_ABOVEWATER"; + case SPELL_FAILED_ONLY_DAYTIME: + return "SPELL_FAILED_ONLY_DAYTIME"; + case SPELL_FAILED_ONLY_INDOORS: + return "SPELL_FAILED_ONLY_INDOORS"; + case SPELL_FAILED_ONLY_MOUNTED: + return "SPELL_FAILED_ONLY_MOUNTED"; + case SPELL_FAILED_ONLY_NIGHTTIME: + return "SPELL_FAILED_ONLY_NIGHTTIME"; + case SPELL_FAILED_ONLY_OUTDOORS: + return "SPELL_FAILED_ONLY_OUTDOORS"; + case SPELL_FAILED_ONLY_SHAPESHIFT: + return "SPELL_FAILED_ONLY_SHAPESHIFT"; + case SPELL_FAILED_ONLY_STEALTHED: + return "SPELL_FAILED_ONLY_STEALTHED"; + case SPELL_FAILED_ONLY_UNDERWATER: + return "SPELL_FAILED_ONLY_UNDERWATER"; + case SPELL_FAILED_OUT_OF_RANGE: + return "SPELL_FAILED_OUT_OF_RANGE"; + case SPELL_FAILED_PACIFIED: + return "SPELL_FAILED_PACIFIED"; + case SPELL_FAILED_POSSESSED: + return "SPELL_FAILED_POSSESSED"; + case SPELL_FAILED_REAGENTS: + return "SPELL_FAILED_REAGENTS"; + case SPELL_FAILED_REQUIRES_AREA: + return "SPELL_FAILED_REQUIRES_AREA"; + case SPELL_FAILED_REQUIRES_SPELL_FOCUS: + return "SPELL_FAILED_REQUIRES_SPELL_FOCUS"; + case SPELL_FAILED_ROOTED: + return "SPELL_FAILED_ROOTED"; + case SPELL_FAILED_SILENCED: + return "SPELL_FAILED_SILENCED"; + case SPELL_FAILED_SPELL_IN_PROGRESS: + return "SPELL_FAILED_SPELL_IN_PROGRESS"; + case SPELL_FAILED_SPELL_LEARNED: + return "SPELL_FAILED_SPELL_LEARNED"; + case SPELL_FAILED_SPELL_UNAVAILABLE: + return "SPELL_FAILED_SPELL_UNAVAILABLE"; + case SPELL_FAILED_STUNNED: + return "SPELL_FAILED_STUNNED"; + case SPELL_FAILED_TARGETS_DEAD: + return "SPELL_FAILED_TARGETS_DEAD"; + case SPELL_FAILED_TARGET_AFFECTING_COMBAT: + return "SPELL_FAILED_TARGET_AFFECTING_COMBAT"; + case SPELL_FAILED_TARGET_AURASTATE: + return "SPELL_FAILED_TARGET_AURASTATE"; + case SPELL_FAILED_TARGET_DUELING: + return "SPELL_FAILED_TARGET_DUELING"; + case SPELL_FAILED_TARGET_ENEMY: + return "SPELL_FAILED_TARGET_ENEMY"; + case SPELL_FAILED_TARGET_ENRAGED: + return "SPELL_FAILED_TARGET_ENRAGED"; + case SPELL_FAILED_TARGET_FRIENDLY: + return "SPELL_FAILED_TARGET_FRIENDLY"; + case SPELL_FAILED_TARGET_IN_COMBAT: + return "SPELL_FAILED_TARGET_IN_COMBAT"; + case SPELL_FAILED_TARGET_IS_PLAYER: + return "SPELL_FAILED_TARGET_IS_PLAYER"; + case SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED: + return "SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED"; + case SPELL_FAILED_TARGET_NOT_DEAD: + return "SPELL_FAILED_TARGET_NOT_DEAD"; + case SPELL_FAILED_TARGET_NOT_IN_PARTY: + return "SPELL_FAILED_TARGET_NOT_IN_PARTY"; + case SPELL_FAILED_TARGET_NOT_LOOTED: + return "SPELL_FAILED_TARGET_NOT_LOOTED"; + case SPELL_FAILED_TARGET_NOT_PLAYER: + return "SPELL_FAILED_TARGET_NOT_PLAYER"; + case SPELL_FAILED_TARGET_NO_POCKETS: + return "SPELL_FAILED_TARGET_NO_POCKETS"; + case SPELL_FAILED_TARGET_NO_WEAPONS: + return "SPELL_FAILED_TARGET_NO_WEAPONS"; + case SPELL_FAILED_TARGET_NO_RANGED_WEAPONS: + return "SPELL_FAILED_TARGET_NO_RANGED_WEAPONS"; + case SPELL_FAILED_TARGET_UNSKINNABLE: + return "SPELL_FAILED_TARGET_UNSKINNABLE"; + case SPELL_FAILED_THIRST_SATIATED: + return "SPELL_FAILED_THIRST_SATIATED"; + case SPELL_FAILED_TOO_CLOSE: + return "SPELL_FAILED_TOO_CLOSE"; + case SPELL_FAILED_TOO_MANY_OF_ITEM: + return "SPELL_FAILED_TOO_MANY_OF_ITEM"; + case SPELL_FAILED_TOTEM_CATEGORY: + return "SPELL_FAILED_TOTEM_CATEGORY"; + case SPELL_FAILED_TOTEMS: + return "SPELL_FAILED_TOTEMS"; + case SPELL_FAILED_TRY_AGAIN: + return "SPELL_FAILED_TRY_AGAIN"; + case SPELL_FAILED_UNIT_NOT_BEHIND: + return "SPELL_FAILED_UNIT_NOT_BEHIND"; + case SPELL_FAILED_UNIT_NOT_INFRONT: + return "SPELL_FAILED_UNIT_NOT_INFRONT"; + case SPELL_FAILED_WRONG_PET_FOOD: + return "SPELL_FAILED_WRONG_PET_FOOD"; + case SPELL_FAILED_NOT_WHILE_FATIGUED: + return "SPELL_FAILED_NOT_WHILE_FATIGUED"; + case SPELL_FAILED_TARGET_NOT_IN_INSTANCE: + return "SPELL_FAILED_TARGET_NOT_IN_INSTANCE"; + case SPELL_FAILED_NOT_WHILE_TRADING: + return "SPELL_FAILED_NOT_WHILE_TRADING"; + case SPELL_FAILED_TARGET_NOT_IN_RAID: + return "SPELL_FAILED_TARGET_NOT_IN_RAID"; + case SPELL_FAILED_TARGET_FREEFORALL: + return "SPELL_FAILED_TARGET_FREEFORALL"; + case SPELL_FAILED_NO_EDIBLE_CORPSES: + return "SPELL_FAILED_NO_EDIBLE_CORPSES"; + case SPELL_FAILED_ONLY_BATTLEGROUNDS: + return "SPELL_FAILED_ONLY_BATTLEGROUNDS"; + case SPELL_FAILED_TARGET_NOT_GHOST: + return "SPELL_FAILED_TARGET_NOT_GHOST"; + case SPELL_FAILED_TRANSFORM_UNUSABLE: + return "SPELL_FAILED_TRANSFORM_UNUSABLE"; + case SPELL_FAILED_WRONG_WEATHER: + return "SPELL_FAILED_WRONG_WEATHER"; + case SPELL_FAILED_DAMAGE_IMMUNE: + return "SPELL_FAILED_DAMAGE_IMMUNE"; + case SPELL_FAILED_PREVENTED_BY_MECHANIC: + return "SPELL_FAILED_PREVENTED_BY_MECHANIC"; + case SPELL_FAILED_PLAY_TIME: + return "SPELL_FAILED_PLAY_TIME"; + case SPELL_FAILED_REPUTATION: + return "SPELL_FAILED_REPUTATION"; + case SPELL_FAILED_MIN_SKILL: + return "SPELL_FAILED_MIN_SKILL"; + case SPELL_FAILED_NOT_IN_ARENA: + return "SPELL_FAILED_NOT_IN_ARENA"; + case SPELL_FAILED_NOT_ON_SHAPESHIFT: + return "SPELL_FAILED_NOT_ON_SHAPESHIFT"; + case SPELL_FAILED_NOT_ON_STEALTHED: + return "SPELL_FAILED_NOT_ON_STEALTHED"; + case SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE: + return "SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE"; + case SPELL_FAILED_NOT_ON_MOUNTED: + return "SPELL_FAILED_NOT_ON_MOUNTED"; + case SPELL_FAILED_TOO_SHALLOW: + return "SPELL_FAILED_TOO_SHALLOW"; + case SPELL_FAILED_TARGET_NOT_IN_SANCTUARY: + return "SPELL_FAILED_TARGET_NOT_IN_SANCTUARY"; + case SPELL_FAILED_TARGET_IS_TRIVIAL: + return "SPELL_FAILED_TARGET_IS_TRIVIAL"; + case SPELL_FAILED_BM_OR_INVISGOD: + return "SPELL_FAILED_BM_OR_INVISGOD"; + case SPELL_FAILED_EXPERT_RIDING_REQUIREMENT: + return "SPELL_FAILED_EXPERT_RIDING_REQUIREMENT"; + case SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT: + return "SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT"; + case SPELL_FAILED_NOT_IDLE: + return "SPELL_FAILED_NOT_IDLE"; + case SPELL_FAILED_NOT_INACTIVE: + return "SPELL_FAILED_NOT_INACTIVE"; + case SPELL_FAILED_PARTIAL_PLAYTIME: + return "SPELL_FAILED_PARTIAL_PLAYTIME"; + case SPELL_FAILED_NO_PLAYTIME: + return "SPELL_FAILED_NO_PLAYTIME"; + case SPELL_FAILED_NOT_IN_BATTLEGROUND: + return "SPELL_FAILED_NOT_IN_BATTLEGROUND"; + case SPELL_FAILED_NOT_IN_RAID_INSTANCE: + return "SPELL_FAILED_NOT_IN_RAID_INSTANCE"; + case SPELL_FAILED_ONLY_IN_ARENA: + return "SPELL_FAILED_ONLY_IN_ARENA"; + case SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE: + return "SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE"; + case SPELL_FAILED_ON_USE_ENCHANT: + return "SPELL_FAILED_ON_USE_ENCHANT"; + case SPELL_FAILED_NOT_ON_GROUND: + return "SPELL_FAILED_NOT_ON_GROUND"; + case SPELL_FAILED_CUSTOM_ERROR: + return "SPELL_FAILED_CUSTOM_ERROR"; + case SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW: + return "SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW"; + case SPELL_FAILED_TOO_MANY_SOCKETS: + return "SPELL_FAILED_TOO_MANY_SOCKETS"; + case SPELL_FAILED_INVALID_GLYPH: + return "SPELL_FAILED_INVALID_GLYPH"; + case SPELL_FAILED_UNIQUE_GLYPH: + return "SPELL_FAILED_UNIQUE_GLYPH"; + case SPELL_FAILED_GLYPH_SOCKET_LOCKED: + return "SPELL_FAILED_GLYPH_SOCKET_LOCKED"; + case SPELL_FAILED_NO_VALID_TARGETS: + return "SPELL_FAILED_NO_VALID_TARGETS"; + case SPELL_FAILED_ITEM_AT_MAX_CHARGES: + return "SPELL_FAILED_ITEM_AT_MAX_CHARGES"; + case SPELL_FAILED_NOT_IN_BARBERSHOP: + return "SPELL_FAILED_NOT_IN_BARBERSHOP"; + case SPELL_FAILED_FISHING_TOO_LOW: + return "SPELL_FAILED_FISHING_TOO_LOW"; + case SPELL_FAILED_ITEM_ENCHANT_TRADE_WINDOW: + return "SPELL_FAILED_ITEM_ENCHANT_TRADE_WINDOW"; + case SPELL_FAILED_SUMMON_PENDING: + return "SPELL_FAILED_SUMMON_PENDING"; + case SPELL_FAILED_MAX_SOCKETS: + return "SPELL_FAILED_MAX_SOCKETS"; + case SPELL_FAILED_PET_CAN_RENAME: + return "SPELL_FAILED_PET_CAN_RENAME"; + case SPELL_FAILED_TARGET_CANNOT_BE_RESURRECTED: + return "SPELL_FAILED_TARGET_CANNOT_BE_RESURRECTED"; + default: + return "SPELL_FAILED_UNKNOWN"; + } +} + +// VERIFY: 338bf6ad auto +// OFFSET: 0x007FD5F0 +bool Spell_C_SpellUsesReagent(const SpellRec* spell, int32_t itemId) { + for (uint32_t i = 0; i < sizeof(spell->m_reagent) / sizeof(spell->m_reagent[0]); i++) { + if (spell->m_reagent[i] == itemId && spell->m_reagentCount[i] > 0) { + return true; + } + } + + return false; +} + +// VERIFY: 102740d5 auto +// OFFSET: 0x007FD640 +PendingSpellCast* Spell_C_GetTargetingSpellCast() { + return s_targetingSpell; +} + +// VERIFY: 1e96df1d auto +// OFFSET: 0x007FD760 +int32_t Spell_C_CanTargetItems() { + return (s_needTargets & 0x4010) != 0; +} + +// VERIFY: e4e8f874 auto +// OFFSET: 0x007FD7A0 +CM2Model* Spell_C_GetCursorWorldObjectModel() { + return s_spellWorldModel; +} + +// VERIFY: e512de8b auto +// OFFSET: 0x007FD7B0 +void Spell_C_SetCursorWorldObjectPosition(const C3Vector& position) { + s_cursorWorldObjectPosition = position; +} + +// VERIFY: 1a823145 auto +// OFFSET: 0x007FD7E0 +const C3Vector& Spell_C_GetCursorWorldObjectPosition() { + return s_cursorWorldObjectPosition; +} + +// VERIFY: 9616d0ac manual +// OFFSET: 0x007FDFA0 +static bool SpellCancelsAura(const SpellRec* spell, const SpellRec* aura, uint32_t auraEffect) { + if (!spell || !(spell->m_attributesEx & 0x8000) || (aura->m_attributes & 0x20000000)) { + return false; + } + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (spell->m_effect[i] != 6) { + continue; + } + + int32_t misc = spell->m_effectMiscValue[i]; + + switch (spell->m_effectAura[i]) { + case 38: + if (misc == aura->m_effectAura[auraEffect]) { + return true; + } + + break; + + case 39: + case 267: + if (!(aura->m_attributesExB & 0x4000000) && (aura->m_schoolMask & misc)) { + return true; + } + + break; + + case 41: + if (misc == aura->m_dispelType) { + return true; + } + + break; + + case 77: + if (misc == aura->m_mechanic || misc == aura->m_effectMechanic[auraEffect]) { + return true; + } + + break; + } + } + + return false; +} + +// VERIFY: 4e168416 manual +// OFFSET: 0x007FE3E0 +uint32_t GetRequiredAuraVisionBitmask(const SpellRec* spell) { + uint32_t mask = spell->m_requiredAuraVision > 0 ? 1 << (spell->m_requiredAuraVision - 1) : 0; + + for (uint32_t i = 0; i < sizeof(spell->m_effectAura) / sizeof(spell->m_effectAura[0]); i++) { + if (spell->m_effectAura[i] == 17) { + mask |= 0x20; + } + + if (spell->m_effectAura[i] == 19 && (!spell->m_effectMiscValue[i] || spell->m_effectMiscValue[i] == 10)) { + mask |= 0x40; + } + } + + return mask; +} + +// VERIFY: 62cca87e manual +// OFFSET: 0x007FE890 +bool SpellRec::NotUsableInShapeshiftForm(const SpellRec* spell, int32_t form) { + if (form < 0) { + return false; + } + + return (spell->m_shapeshiftExclude[form / 32] & (1 << (form % 32))) != 0; +} + +// VERIFY: 2ba175f5 manual +// OFFSET: 0x007FEA80 +void SpellMissingItemCallback(int32_t itemId, const WOWGUID& guid, void* param, bool success) { + int32_t reason = static_cast(reinterpret_cast(param)); + UIErrors error = ERR_SPELL_FAILED_S; + char format[1024]; + SStrCopy(format, FrameScript_GetText(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (reason == SPELL_FAILED_REAGENTS) { + error = ERR_SPELL_FAILED_REAGENTS; + } else if (reason == SPELL_FAILED_TOTEMS) { + error = ERR_SPELL_FAILED_TOTEMS; + } + + char text[1024]; + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (stats) { + SStrPrintf(text, sizeof(text), format, stats->m_name[0]); + } else { + SStrPrintf(text, sizeof(text), format, "UNKNOWN"); + } + + CGGameUI::DisplayError(error, text); +} + +// VERIFY: 2f537c65 auto +// OFFSET: 0x007FEB50 +void SpellMissingItemsCallback(int32_t itemId, const WOWGUID& guid, void* param, bool success) { + char format[1024]; + SStrCopy(format, FrameScript_GetText("SPELL_FAILED_NEED_MORE_ITEMS", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + char text[1024]; + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (stats) { + SStrPrintf(text, sizeof(text), format, static_cast(reinterpret_cast(param)), stats->m_name[0]); + } else { + SStrPrintf(text, sizeof(text), format, 0, "UNKNOWN"); + } + + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, text); +} + +// VERIFY: 52758823 auto +// OFFSET: 0x007FEF10 +void GetCustomSpellFailedString(char* buffer, uint32_t size, int32_t customError) { + char token[64]; + SStrPrintf(token, sizeof(token), "%s_%d", "SPELL_FAILED_CUSTOM_ERROR", customError); + SStrCopy(buffer, FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), size); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, buffer); +} + +// VERIFY: 0e3e8924 manual +// OFFSET: 0x007FFF60 +float Spell_C_GetCursorWorldObjectFacing() { + if (s_cursorWorldObjectHousing) { + return s_cursorWorldObjectFacing; + } + + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(s_targetingSpell->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + return s_cursorWorldObjectFacing; + } + + s_cursorWorldObjectFacing = caster->GetFacing(); + return s_cursorWorldObjectFacing; +} + +// VERIFY: 78608420 manual +// OFFSET: 0x00802A50 +void SpellHistory::ClearAll() { + while (SPELLHISTORY* history = this->m_history.Head()) { + this->m_free.LinkToTail(history); + } +} + +// VERIFY: 81391441 auto +// OFFSET: 0x00804110 +int32_t Packet_SMSG_COOLDOWN_CHEAT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + + if (guid == ClntObjMgrGetActivePlayer()) { + s_spellHistory[0].ClearAll(); + CGSpellBook::UpdateCooldowns(); + CGContainerInfo::UpdateCooldowns(); + return 1; + } + + if (guid == CGPetInfo::GetPet(0)) { + s_spellHistory[1].ClearAll(); + CGSpellBook::UpdateCooldowns(); + CGPetInfo::UpdateCooldowns(); + } + + return 1; +} + +// VERIFY: 7425edb0 manual +// OFFSET: 0x00804430 +bool Spell_C_CancelsAuraEffect(const CGUnit_C* unit, const SpellRec* spell, int32_t auraType, int32_t* reason) { + bool found = false; + SpellRec aura; + + for (uint32_t i = 0; i < unit->GetAuraCount(); i++) { + int32_t spellId = const_cast(unit)->m_auras[i].m_spellId; + + if (!spellId || !g_spellDB.GetRecord(spellId, &aura)) { + continue; + } + + for (uint32_t j = 0; j < sizeof(aura.m_effectAura) / sizeof(aura.m_effectAura[0]); j++) { + if (aura.m_effectAura[j] != auraType) { + continue; + } + + found = true; + + if (!SpellCancelsAura(spell, &aura, j)) { + if (reason) { + if (aura.m_effectMechanic[j]) { + *reason = aura.m_effectMechanic[j]; + } else if (aura.m_mechanic) { + *reason = aura.m_mechanic; + } + } + + return false; + } + } + } + + return found; +} + +// VERIFY: 6bd9469f auto +// OFFSET: 0x00804590 +bool Spell_C_CancelsStun(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 12, reason); +} + +// VERIFY: 65a88e05 auto +// OFFSET: 0x008045C0 +bool Spell_C_CancelsSilence(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 27, reason) || Spell_C_CancelsAuraEffect(unit, spell, 60, reason); +} + +// VERIFY: c9a4c918 auto +// OFFSET: 0x00804610 +bool Spell_C_CancelsPacify(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 25, reason) || Spell_C_CancelsAuraEffect(unit, spell, 60, reason); +} + +// VERIFY: 851db6e3 auto +// OFFSET: 0x00804660 +bool Spell_C_CancelsFear(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 7, reason); +} + +// VERIFY: bb2a34cc auto +// OFFSET: 0x00804690 +bool Spell_C_CancelsConfuse(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 5, reason); +} + +// VERIFY: 7ba2f519 auto +// OFFSET: 0x008046C0 +bool Spell_C_CancelsCharm(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason) { + if (reason) { + *reason = 0; + } + + return Spell_C_CancelsAuraEffect(unit, spell, 6, reason) || Spell_C_CancelsAuraEffect(unit, spell, 177, reason) || Spell_C_CancelsAuraEffect(unit, spell, 2, reason); +} + +// VERIFY: 751283a6 manual +// OFFSET: 0x00804720 +void SpellHistory::RemoveStartCooldown(int32_t startRecoveryCategory) { + bool removed = false; + + for (SPELLHISTORY* history = this->m_history.Head(); history; history = this->m_history.Next(history)) { + if (history->m_spellId == startRecoveryCategory) { + history->m_startRecoveryCategory = 0; + history->m_startRecoveryTime = 0; + removed = true; + } + } + + if (removed) { + this->GarbageCollect(OsGetAsyncTimeMs()); + CGSpellBook::UpdateCooldowns(); + } +} + +// VERIFY: 3c3b6e25 auto +// OFFSET: 0x00804780 +void Spell_C_PetSpellFailedUpdateCooldowns(int32_t spellId) { + s_spellHistory[1].RemoveStartCooldown(spellId); + CGPetInfo::UpdateCooldowns(); +} + +// VERIFY: 474b58ab manual +// OFFSET: 0x008047A0 +void Spell_C_ClearInTransitList() { + SpellInTransit* spell = s_spellsInTransit.Head(); + + while (spell) { + SpellInTransit* next = s_spellsInTransit.Next(spell); + s_spellsInTransit.UnlinkNode(spell); + delete spell; + spell = next; + } +} + +// VERIFY: e7eb7309 auto +// OFFSET: 0x00804AF0 +void Spell_C_ClearCooldowns() { + s_itemCooldowns.InternalClear(0); + + for (uint32_t i = 0; i < sizeof(s_spellHistory) / sizeof(s_spellHistory[0]); i++) { + s_spellHistory[i].ClearAll(); + } +} + +// VERIFY: 1d8a9dca manual +// OFFSET: 0x00804C10 +void Spell_C_UpdateInTransitList() { + uint32_t now = OsGetAsyncTimeMs(); + SpellInTransit* spell = s_spellsInTransit.Head(); + + while (spell) { + SpellInTransit* next = s_spellsInTransit.Next(spell); + + if (static_cast(now - spell->m_arrivalTime) < 0) { + break; + } + + s_spellsInTransit.UnlinkNode(spell); + delete spell; + spell = next; + } +} + +// VERIFY: 28603e8e manual +// OFFSET: 0x00804CC0 +int32_t Spell_C_IsSpellInTransit(WOWGUID caster, uint32_t spellId, uint32_t castTime) { + for (SpellInTransit* spell = s_spellsInTransit.Head(); spell; spell = s_spellsInTransit.Next(spell)) { + if (spell->m_caster == caster && spell->m_spellId == static_cast(spellId) && spell->m_serverTime == castTime) { + return 1; + } + } + + return 0; +} +// VERIFY: dbeddd39 manual +// OFFSET: 0x00809030 +bool Spell_C_GetItemCooldown(int32_t itemId, uint32_t* duration, uint32_t* start, uint32_t* enable) { + WOWGUID player = ClntObjMgrGetActivePlayer(); + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, player, ItemCheckCooldownCallback, nullptr, true); + + if (!stats) { + return false; + } + + for (uint32_t i = 0; i < sizeof(stats->m_spellId) / sizeof(stats->m_spellId[0]); i++) { + if (static_cast(stats->m_spellId[i]) > 0 && !stats->m_spellTrigger[i]) { + return s_spellHistory[0].GetSpellCooldown(stats->m_spellId[i], itemId, duration, start, enable); + } + } + + return false; +} + +// VERIFY: 95db2eb3 auto +// OFFSET: 0x0080ABE0 +void ItemCheckCooldownCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (success && Spell_C_GetItemCooldown(id, nullptr, nullptr, nullptr)) { + CGSpellBook::UpdateCooldowns(); + CGContainerInfo::UpdateCooldowns(); + } +} + +// VERIFY: 41a8c8a3 manual +// OFFSET: 0x0080E060 +void Spell_C_AddPendingItemCooldown(int32_t itemId, int32_t spellId, uint32_t time, bool onHold) { + HASHKEY_NONE key; + ITEMCOOLDOWNHASHNODE* node = s_itemCooldowns.Ptr(itemId, key); + + if (!node) { + node = s_itemCooldowns.New(itemId, key, 0, 0); + } + + node->m_spellId = spellId; + node->m_time = time; + node->m_onHold = onHold; +} + +// VERIFY: bcfe0d9d auto +// OFFSET: 0x007FE470 +static bool SpellVisualKitHasChainEffect(const SpellVisualKitRec* kit) { + for (uint32_t i = 0; i < sizeof(kit->m_charProc) / sizeof(kit->m_charProc[0]); i++) { + if (!kit->m_charProc[i]) { + return false; + } + + if (kit->m_charProc[i] == 12) { + return true; + } + } + + return false; +} + +// VERIFY: 88789792 auto +// OFFSET: 0x00800390 +void Spell_C_PetTameFailure(uint8_t reason) { + const char* token; + + switch (reason) { + case 1: + token = "PETTAME_INVALIDCREATURE"; + break; + + case 2: + token = "PETTAME_TOOMANY"; + break; + + case 3: + token = "PETTAME_CREATUREALREADYOWNED"; + break; + + case 4: + token = "PETTAME_NOTTAMEABLE"; + break; + + case 5: + token = "PETTAME_ANOTHERSUMMONACTIVE"; + break; + + case 6: + token = "PETTAME_UNITSCANTTAME"; + break; + + case 7: + token = "PETTAME_NOPETAVAILABLE"; + break; + + case 8: + token = "PETTAME_INTERNALERROR"; + break; + + case 9: + token = "PETTAME_TOOHIGHLEVEL"; + break; + + case 10: + token = "PETTAME_DEAD"; + break; + + case 11: + token = "PETTAME_NOTDEAD"; + break; + + case 12: + token = "PETTAME_CANTCONTROLEXOTIC"; + break; + + default: + token = "PETTAME_UNKNOWNERROR"; + break; + } + + char text[1024]; + SStrCopy(text, FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), sizeof(text)); + CGGameUI::DisplayError(ERR_TAME_FAILED, text); +} + +// VERIFY: af4cb118 manual +// OFFSET: 0x00800470 +int32_t Packet_SMSG_SPELL_UPDATE_CHAIN_TARGETS(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID caster; + msg->Get(caster.m_guid); + int32_t spellId; + msg->Get(reinterpret_cast(spellId)); + uint32_t count = 0; + msg->Get(count); + TSStackArray targets(static_cast(alloca(sizeof(WOWGUID) * count)), count, 1); + + for (uint32_t i = 0; i < count; i++) { + msg->Get(targets.m_data[i].m_guid); + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->UpdateChainTargets(targets, spellId); + } + + return 1; +} + +// VERIFY: 679f44cf manual +// OFFSET: 0x00800610 +int32_t Packet_SMSG_PLAY_SPELL_VISUAL(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + uint32_t kitId; + msg->Get(kitId); + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(kitId); + + if (kit) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + PlaySpellVisuaKitData kitData(nullptr, kit, 0); + unit->PlaySpellVisualKit(kitData); + } + } + + return 1; +} + +// VERIFY: d9c2084e manual +// OFFSET: 0x008006C0 +int32_t Packet_SMSG_PLAY_SPELL_IMPACT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + uint32_t kitId; + msg->Get(kitId); + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(kitId); + + if (kit) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + PlaySpellVisuaKitData kitData(nullptr, kit, 1); + unit->PlaySpellVisualKit(kitData); + } + } + + return 1; +} + +// VERIFY: 23ec14f4 auto +// OFFSET: 0x00800950 +bool SpellAppliesNonStanceShapeshift(const SpellRec* spell) { + for (uint32_t i = 0; i < sizeof(spell->m_effectAura) / sizeof(spell->m_effectAura[0]); i++) { + if (spell->m_effectAura[i] != 36) { + continue; + } + + SpellShapeshiftFormRec* form = g_spellShapeshiftFormDB.GetRecord(spell->m_effectMiscValue[i]); + + if (!form || !(form->m_flags & 0x1)) { + return true; + } + } + + return false; +} + +// VERIFY: 28d55e5b manual +// OFFSET: 0x00800A00 +void Spell_C_SetAutoRepeatingSpell(int32_t spellId) { + if (s_autoRepeatingSpell == spellId) { + return; + } + + s_autoRepeatingSpell = spellId; + + if (!s_autoRangedCombatSpell) { + if (spellId) { + FrameScript_SignalEvent(SCRIPT_EVENT_START_AUTOREPEAT_SPELL, nullptr); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_STOP_AUTOREPEAT_SPELL, nullptr); + } + } + + if (s_autoRepeatingSpell) { + ClntObjMgrGetActivePlayerObj()->MeleeModeLeave(); + } +} + +// VERIFY: 9a0a630e manual +// OFFSET: 0x00800BF0 +bool Spell_C_SpellVisualHasChainEffect(const SpellVisualRec* visual) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_castKit); + + if (kit && SpellVisualKitHasChainEffect(kit)) { + return true; + } + + kit = g_spellVisualKitDB.GetRecord(visual->m_impactKit); + + if (kit && SpellVisualKitHasChainEffect(kit)) { + return true; + } + + kit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + + if (kit && SpellVisualKitHasChainEffect(kit)) { + return true; + } + + kit = g_spellVisualKitDB.GetRecord(visual->m_channelKit); + + if (kit && SpellVisualKitHasChainEffect(kit)) { + return true; + } + + kit = g_spellVisualKitDB.GetRecord(visual->m_casterImpactKit); + + if (kit && SpellVisualKitHasChainEffect(kit)) { + return true; + } + + kit = g_spellVisualKitDB.GetRecord(visual->m_targetImpactKit); + return kit && SpellVisualKitHasChainEffect(kit); +} + +// VERIFY: 2d56a1b9 manual +// OFFSET: 0x00800D00 +SpellVisualKitRec* Spell_C_GetAppropriateImpactKit(const SpellVisualRec* visual, int32_t caster) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(caster ? visual->m_casterImpactKit : visual->m_targetImpactKit); + + if (kit) { + return kit; + } + + return g_spellVisualKitDB.GetRecord(visual->m_impactKit); +} + +// VERIFY: 50dd76ca manual +// OFFSET: 0x008019C0 +float Spell_C_GetSpellRadius() { + PendingSpellCast* cast = s_targetingSpell; + + if (!cast) { + return 0.0f; + } + + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + return 0.0f; + } + + SpellRec spell; + g_spellDB.GetRecord(cast->m_data.m_spellId, &spell); + + SpellRadiusRec* radiusRec = g_spellRadiusDB.GetRecord(spell.m_effectRadiusIndex[0]); + float radius = radiusRec ? radiusRec->m_radius + static_cast(caster->m_unit->m_unitFieldLevel) * radiusRec->m_radiusPerLevel : 0.0f; + + radiusRec = g_spellRadiusDB.GetRecord(spell.m_effectRadiusIndex[1]); + float radius2 = radiusRec ? radiusRec->m_radius + static_cast(caster->m_unit->m_unitFieldLevel) * radiusRec->m_radiusPerLevel : 0.0f; + + if (radius2 >= radius) { + radius = radius2; + } + + int32_t flat; + int32_t pct; + + if (Spell_C_GetSpellModifiers(&spell, 6, flat, pct)) { + radius = (radius + flat) * pct * 0.01f; + } + + return radius; +} + +// VERIFY: 780f5311 manual +// OFFSET: 0x00801B80 +int32_t Packet_SMSG_SPELL_DELAYED(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + int32_t delay; + msg->Get(reinterpret_cast(delay)); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + SpellRec spell; + + if (g_spellDB.GetRecord(unit->m_castingSpellId, &spell)) { + if ((spell.m_attributesExD & 0x8000000) || (!(spell.m_attributes & 0x2) && (unit->m_obj->m_guid == ClntObjMgrGetActivePlayer() || (!(spell.m_attributes & 0x180) && !(spell.m_attributesExD & 0x1))))) { + unit->DelayCast(delay); + Script_SendUnitSpellSignal(guid, unit->m_castCount, &spell, 329); + } + } + } + + return 1; +} + +// VERIFY: ca8bfe75 manual +// OFFSET: 0x008020C0 +int32_t Packet_SMSG_UNIT_SPELLCAST_START(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID caster; + *msg >> caster; + SmartGUID target; + *msg >> target; + int32_t spellId; + msg->Get(reinterpret_cast(spellId)); + uint32_t remaining; + msg->Get(remaining); + uint32_t duration; + msg->Get(duration); + uint32_t end = OsGetAsyncTimeMs() + remaining; + uint32_t start = end - duration; + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + int32_t signal; + + if (spell.m_attributesEx & 0x4) { + unit->SetUIChannelDirect(spellId, start, end); + signal = 331; + } else { + unit->SetUICastingDirect(spellId, target, start, end); + signal = 324; + } + + Script_SendUnitSpellSignal(caster, 0, &spell, signal); + } + } + + return 1; +} + +// VERIFY: 24535fb9 manual +// OFFSET: 0x00802A10 +void SpellHistory::DelayCooldown(int32_t spellId, int32_t delay) { + for (SPELLHISTORY* history = this->m_history.Head(); history; history = this->m_history.Next(history)) { + if (history->m_spellId == spellId) { + history->m_time += delay; + history->m_categoryTime += delay; + } + } +} + +// VERIFY: 6a53b8e9 auto +// OFFSET: 0x00802BA0 +void Spell_C_ModifyCooldown(int32_t spellId, uint32_t time, int32_t index, int32_t remove) { + s_spellHistory[index].ClearOnHold(spellId, time, remove != 0); + CGSpellBook::UpdateCooldowns(); + CGSpellBook::UpdateUsable(); + + if (index) { + CGPetInfo::UpdateCooldowns(); + } else { + CGContainerInfo::UpdateCooldowns(); + } +} + +// VERIFY: d71e0c5b auto +// OFFSET: 0x00802BF0 +void Spell_C_DelayCooldown(int32_t index, int32_t spellId, int32_t delay) { + s_spellHistory[index].DelayCooldown(spellId, delay); + CGSpellBook::UpdateCooldowns(); + CGSpellBook::UpdateUsable(); + + if (index) { + CGPetInfo::UpdateCooldowns(); + } else { + CGContainerInfo::UpdateCooldowns(); + } +} + +// VERIFY: 019f1364 auto +// OFFSET: 0x007FDF20 +static bool SpellHasUnitAuraEffect(const SpellRec* spell) { + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (Spell_IsUnitAuraEffect(spell->m_effect[i])) { + return true; + } + } + + return false; +} + +// VERIFY: 76133823 manual +// OFFSET: 0x00802CB0 +bool Spell_C_IsActiveSpell(const SpellRec* spell, const CGUnit_C* unit) { + if (!unit) { + return false; + } + + if (!spell->m_activeIconID && !SpellRec::WillSummonCritter(spell)) { + return false; + } + + CGUnit_C* vehicle = unit->m_vehiclePassenger ? unit->m_vehiclePassenger->GetVehicleUnit() : nullptr; + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (spell->m_effect[i] != 28) { + continue; + } + + if (vehicle && vehicle->m_obj->m_entryID == spell->m_effectMiscValue[i] && vehicle->m_unit->m_unitFieldCreatedby == ClntObjMgrGetActivePlayer()) { + return true; + } + + SummonPropertiesRec* properties = g_summonPropertiesDB.GetRecord(spell->m_effectMiscValueB[0]); + + if (properties && properties->m_slot == 5) { + return static_cast((unit->m_unit->m_unitFieldCritter.m_guid >> 24) & 0xFFFFFFF) == spell->m_effectMiscValue[i]; + } + } + + bool active = false; + CGUnit_C* self = const_cast(unit); + + for (uint32_t i = 0; i < unit->GetAuraCount(); i++) { + if (self->m_auras[i].m_spellId != spell->m_id) { + continue; + } + + if (self->IsActivePlayer() && SpellRec::HasAura(spell, 36) && unit->m_shapeshiftSuppressed) { + break; + } + + if (self->m_auras[i].m_flags & 0x10) { + return true; + } + } + + if (spell->m_effectAura[0] == 78) { + SpellRec aura; + + for (uint32_t i = 0; i < unit->GetAuraCount(); i++) { + if (g_spellDB.GetRecord(self->m_auras[i].m_spellId, &aura) && aura.m_effectAura[0] == 78 && aura.m_effectMiscValue[0] == spell->m_effectMiscValue[0]) { + active = true; + break; + } + } + } + + return active; +} + +// VERIFY: 399e67df manual +// OFFSET: 0x00802F80 +void Spell_C_CancelAura(const SpellRec* spell, CGUnit_C* unit, int32_t auraIndex) { + if (!spell || !unit) { + return; + } + + if (!unit->IsActivePlayer()) { + if (SpellHasUnitAuraEffect(spell)) { + CDataStore msg; + msg.Put(static_cast(CMSG_PET_CANCEL_AURA)); + msg.Put(unit->m_obj->m_guid.m_guid); + msg.Put(static_cast(spell->m_id)); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + return; + } + + if (unit->m_unit->m_unitFieldCharmedby) { + return; + } + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (spell->m_effect[i] != 28) { + continue; + } + + SummonPropertiesRec* properties = g_summonPropertiesDB.GetRecord(spell->m_effectMiscValueB[0]); + + if (properties && properties->m_slot == 5 && static_cast((unit->m_unit->m_unitFieldCritter.m_guid >> 24) & 0xFFFFFFF) == spell->m_effectMiscValue[i]) { + CDataStore msg; + msg.Put(static_cast(CMSG_DISMISS_CRITTER)); + msg.Put(unit->m_unit->m_unitFieldCritter.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + } + } + + if (!SpellHasUnitAuraEffect(spell)) { + return; + } + + if (unit->m_mountDisplayId > 0 && !(unit->m_clientFlags & 0x10000000) && SpellRec::HasAura(spell, 78)) { + SpellRec mount; + + for (uint32_t i = 0; i < unit->GetAuraCount(); i++) { + if (g_spellDB.GetRecord(unit->m_auras[i].m_spellId, &mount) && mount.m_effectAura[0] == 78 && mount.m_effectMiscValue[0] == spell->m_effectMiscValue[0] && mount.m_id != spell->m_id) { + Spell_C_CancelAura(&mount, unit, -1); + return; + } + } + + unit->OnMountDisplayChanged(0); + } + + if (unit->GetShapeshiftForm() && SpellRec::HasAura(spell, 36)) { + if (lua_tainted) { + for (uint32_t i = s_shapeshiftSpells.Count(); i; ) { + i--; + + if (s_shapeshiftSpells.m_data[i].m_spellId == spell->m_id) { + return; + } + } + } + + for (uint32_t i = 0; i < sizeof(spell->m_effectAura) / sizeof(spell->m_effectAura[0]); i++) { + if (spell->m_effectAura[i] != 36) { + continue; + } + + SpellShapeshiftFormRec* form = g_spellShapeshiftFormDB.GetRecord(spell->m_effectMiscValue[i]); + + if (!form || (form->m_flags & 0x2)) { + return; + } + + if (unit->GetShapeshiftForm() == static_cast(spell->m_effectMiscValue[i])) { + unit->PreemptivelyCancelShapeshift(); + break; + } + } + } + + if ((spell->m_attributesEx & 0x2000) && !(spell->m_attributesEx & 0x4) && (unit->m_obj->m_type & TYPEMASK_PLAYER) && static_cast(unit)->ToggleFarSight(nullptr)) { + return; + } + + if (spell->m_id == 2584) { + FrameScript_SignalEvent(SCRIPT_EVENT_AREA_SPIRIT_HEALER_OUT_OF_RANGE, nullptr); + } + + for (uint32_t i = 0; i < sizeof(spell->m_effectAura) / sizeof(spell->m_effectAura[0]); i++) { + if (spell->m_effectAura[i] != 236) { + continue; + } + + const WOWGUID* controlled = &unit->m_unit->m_unitFieldCharm; + + if (!*controlled) { + controlled = &unit->m_unit->m_unitFieldSummon; + } + + if (controlled->m_guid == unit->GetTransportGUID()) { + WOWGUID transport = { unit->GetTransportGUID() }; + CGUnit_C* transportUnit = static_cast(ClntObjMgrObjectPtr(transport, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (transportUnit) { + CVehicle_C* vehicle = transportUnit->m_vehicle; + uint8_t seat = unit->m_movementData.m_transportSeat; + + if (vehicle) { + VehicleSeatRec* seatRec = vehicle->GetVehicleSeatRec(seat); + + if (seatRec && (seatRec->m_flags & 0x2000000)) { + CGUnit_C* mover = static_cast(ClntObjMgrObjectPtr(CGUnit_C::s_activeMover, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (mover) { + mover->VehicleExit(); + + if (auraIndex >= 0 && unit->m_obj->m_guid.m_guid == unit->GetAuraCaster(auraIndex)) { + return; + } + } + } + } + } + } + + break; + } + + CGUnit_C* vehicleUnit = unit->m_vehiclePassenger ? unit->m_vehiclePassenger->GetVehicleUnit() : nullptr; + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (spell->m_effect[i] == 28 && vehicleUnit && vehicleUnit->m_obj->m_entryID == spell->m_effectMiscValue[i]) { + CGInputControl* input = CGInputControl::GetActive(); + CGUnit_C* mover = static_cast(ClntObjMgrObjectPtr(CGUnit_C::s_activeMover, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (mover && input->IsVehicleSeatFlagSet(0x2000000)) { + mover->VehicleExit(); + } + } + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CANCEL_AURA)); + msg.Put(static_cast(spell->m_id)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: c6760f6a manual +// OFFSET: 0x008038F0 +bool Spell_C_IsCastingInterruptedByCombat(const WOWGUID& guid) { + for (PendingSpellCast* cast = s_pendingSpellCasts.Head(); cast; cast = s_pendingSpellCasts.Next(cast)) { + if (cast->m_data.m_caster == guid) { + SpellRec spell; + + if (g_spellDB.GetRecord(cast->m_data.m_spellId, &spell) && (spell.m_interruptFlags & 0x8)) { + return true; + } + } + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && unit->m_unit->m_unitChannelSpell) { + SpellRec spell; + + if (g_spellDB.GetRecord(unit->m_unit->m_unitChannelSpell, &spell) && (spell.m_channelInterruptFlags & 0x1000)) { + return true; + } + } + + return false; +} + +// VERIFY: 839db5ad manual +// OFFSET: 0x00803EE0 +int32_t Spell_C_HandleTerrainRay(const CTerrainClickEvent& evt, bool checkRange) { + if (!(s_needTargets & 0x60)) { + return 1; + } + + PendingSpellCastData* data = s_targetingSpell ? &s_targetingSpell->m_data : nullptr; + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(data->m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + return 1; + } + + if (!checkRange) { + return 0; + } + + C3Vector position = evt.m_point; + + if (evt.m_guid) { + CGObject_C* object = ClntObjMgrObjectPtr(evt.m_guid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (object) { + position *= object->GetMatrix(); + } + } + + float distance = caster->GetDistanceToPos(position); + float minRange; + float maxRange; + Spell_C::GetSpellRange(caster, data->m_spellId, &minRange, &maxRange, nullptr); + + if (distance >= minRange * minRange && maxRange * maxRange >= distance) { + return 0; + } + + return maxRange * maxRange * 16.0f >= distance ? 1 : 2; +} + +// VERIFY: 047edb41 manual +// OFFSET: 0x008055C0 +void Spell_C_FailPendingCast(PendingSpellCast* cast, const SpellRec* spell, int32_t reason) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, spell, reason); + FinishPendingSpellCast(cast, spell, unit); + } +} + +// VERIFY: fee48a29 manual +// OFFSET: 0x00805EF0 +bool Spell_C_IsModal(const WOWGUID& item) { + for (PendingSpellCast* cast = s_pendingSpellCasts.Head(); cast; cast = s_pendingSpellCasts.Next(cast)) { + if (cast->m_data.m_castItem == item) { + return true; + } + } + + return false; +} + +// VERIFY: c6982e6a manual +// OFFSET: 0x00805F30 +static bool Spell_C_IsSpellPending(int32_t spellId) { + for (PendingSpellCast* cast = s_pendingSpellCasts.Head(); cast; cast = s_pendingSpellCasts.Next(cast)) { + if (cast->m_data.m_spellId == static_cast(spellId)) { + return true; + } + } + + return false; +} + +// VERIFY: a0204cde manual +// OFFSET: 0x00806030 +bool Spell_C_IsCurrentSpell(int32_t spellId) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return false; + } + + if (Spell_C_IsSpellPending(spellId)) { + return true; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (spell.m_effect[0] == 78) { + return player && player->m_combat.m_attacking; + } + + if (spell.m_effect[0] == 47) { + if (player) { + SkillLineAbilityRec* ability = player->LookupAbility(spell.m_id); + + if (ability && !CGTradeSkillInfo::m_linkData && CGTradeSkillInfo::m_skillLineID == ability->m_skillLine) { + return true; + } + } + + return false; + } + + if (!SpellRec::WillSummonCritter(&spell) && !SpellRec::HasAura(&spell, 36)) { + return false; + } + + return Spell_C_IsActiveSpell(&spell, player); +} + +// VERIFY: 07e6999f manual +// OFFSET: 0x008061A0 +PendingSpellCast* Spell_C_GetActivePlayerPendingCast() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return nullptr; + } + + return GetPendingSpellCast(player->m_castCount, player->m_castSpellId, player->m_obj->m_guid); +} + +// VERIFY: fd2d4d6a manual +// OFFSET: 0x00806200 +void Spell_C_CancelSpell(PendingSpellCast* cast, bool stopRecast, bool notifyServer, int32_t reason) { + SpellRec spell; + + if (!g_spellDB.GetRecord(cast->m_data.m_spellId, &spell)) { + return; + } + + if (CGTradeInfo::m_enchantingItem && CGTradeInfo::m_enchantingItem == cast->m_data.m_castItem) { + CGTradeInfo::SetEnchantingItem(nullptr); + } + + if (cast != s_targetingSpell && notifyServer) { + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if ((caster && caster->GetSpellCastingTime(&spell) > 0) || (spell.m_attributes & 0x404)) { + CDataStore msg; + msg.Put(static_cast(CMSG_CANCEL_CAST)); + msg.Put(cast->m_data.m_castCount); + msg.Put(static_cast(cast->m_data.m_spellId)); + msg.Finalize(); + ClientServices::Send2(&msg); + } + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, &spell, reason); + FinishPendingSpellCast(cast, &spell, unit); + } + + if (stopRecast) { + CGTradeSkillInfo::StopRecast(); + } +} + +// VERIFY: a7ca1637 manual +// OFFSET: 0x00806390 +void Spell_C_CancelSpellByCaster(const WOWGUID& caster) { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + + if (cast->m_data.m_castItem == caster) { + Spell_C_CancelSpell(cast, true, true, 27); + } + + cast = next; + } +} + +// VERIFY: 099397b4 manual +// OFFSET: 0x008063E0 +void Spell_C_CancelSpellByTarget(const WOWGUID& target, int32_t reason) { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + + if (cast->m_data.m_objectTarget == target) { + Spell_C_CancelSpell(cast, true, true, reason); + } + + cast = next; + } +} + +// VERIFY: 98e4a5c1 manual +// OFFSET: 0x00806440 +void Spell_C_CancelSpellsWithId(int32_t spellId) { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + + if (cast->m_data.m_spellId == static_cast(spellId)) { + Spell_C_CancelSpell(cast, true, true, 27); + } + + cast = next; + } +} + +// VERIFY: 09c12820 manual +// OFFSET: 0x00806480 +void Spell_C_CancelMeleeSpells() { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + SpellRec spell; + + if (g_spellDB.GetRecord(cast->m_data.m_spellId, &spell) && (spell.m_attributes & 0x404)) { + Spell_C_CancelSpell(cast, false, true, 27); + } + + cast = next; + } +} + +// VERIFY: 6f75e1c3 manual +// OFFSET: 0x00806550 +void Spell_C_CancelRangedSpells() { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + SpellRec spell; + + if (g_spellDB.GetRecord(cast->m_data.m_spellId, &spell) && (spell.m_attributes & 0x2)) { + Spell_C_CancelSpell(cast, false, true, 27); + } + + cast = next; + } +} + +// VERIFY: 3a7b6437 manual +// OFFSET: 0x00806620 +void Spell_C_CancelCastingSpellByMovement() { + PendingSpellCast* cast = s_pendingSpellCasts.Head(); + + while (cast) { + PendingSpellCast* next = s_pendingSpellCasts.Next(cast); + + if (cast != s_targetingSpell) { + SpellRec spell; + + if (g_spellDB.GetRecord(cast->m_data.m_spellId, &spell) && (spell.m_interruptFlags & 0x1)) { + Spell_C_CancelSpell(cast, false, true, 40); + } + } + + cast = next; + } +} + +// VERIFY: 627f2c2d manual +// OFFSET: 0x00806AD0 +int32_t Packet_SMSG_SPELL_FAILED_OTHER(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID caster; + *msg >> caster; + uint8_t castCount; + msg->Get(castCount); + uint32_t spellId; + msg->Get(spellId); + uint8_t reason; + msg->Get(reason); + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return 1; + } + + PendingSpellCast local; + PendingSpellCast* cast = FindPendingSpellCast(caster, &local, castCount, spellId, caster); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, &spell, reason); + FinishPendingSpellCast(cast, &spell, unit); + } + + return 1; +} + +// VERIFY: 29396807 manual +// OFFSET: 0x00807060 +int32_t Packet_SMSG_ITEM_COOLDOWN(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + uint32_t spellId; + msg->Get(spellId); + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (item) { + int32_t itemId = item->m_obj->m_entryID; + SpellHistory& history = s_spellHistory[0]; + SPELLHISTORY* entry = history.m_free.Head(); + + if (entry) { + history.m_free.UnlinkNode(entry); + history.m_history.LinkToTail(entry); + } else { + entry = history.m_history.NewNode(2, 0, 8); + } + + entry->m_spellId = spellId; + entry->m_itemId = itemId; + entry->m_time = time; + entry->m_recoveryTime = 30000; + entry->m_category = 0; + entry->m_categoryTime = 0; + entry->m_categoryRecoveryTime = 0; + entry->m_onHold = false; + entry->m_startRecoveryCategory = 0; + entry->m_startRecoveryTime = 0; + } + } + + CGSpellBook::UpdateCooldowns(); + CGContainerInfo::UpdateCooldowns(); + return 1; +} + +// VERIFY: d5a8355c auto +// OFFSET: 0x008073A0 +void Spell_C_Destroy() { + ClientServices::ClearMessageHandler(SMSG_SPELL_START); + ClientServices::ClearMessageHandler(SMSG_SPELL_GO); + ClientServices::ClearMessageHandler(SMSG_CAST_FAILED); + ClientServices::ClearMessageHandler(SMSG_SPELL_FAILURE); + ClientServices::ClearMessageHandler(SMSG_SPELL_FAILED_OTHER); + ClientServices::ClearMessageHandler(SMSG_PET_CAST_FAILED); + ClientServices::ClearMessageHandler(SMSG_SPELL_COOLDOWN); + ClientServices::ClearMessageHandler(SMSG_ITEM_COOLDOWN); + ClientServices::ClearMessageHandler(SMSG_COOLDOWN_EVENT); + ClientServices::ClearMessageHandler(SMSG_CLEAR_COOLDOWN); + ClientServices::ClearMessageHandler(SMSG_MODIFY_COOLDOWN); + ClientServices::ClearMessageHandler(SMSG_COOLDOWN_CHEAT); + ClientServices::ClearMessageHandler(SMSG_PET_TAME_FAILURE); + ClientServices::ClearMessageHandler(SMSG_SPELL_DELAYED); + ClientServices::ClearMessageHandler(MSG_CHANNEL_START); + ClientServices::ClearMessageHandler(MSG_CHANNEL_UPDATE); + ClientServices::ClearMessageHandler(SMSG_PLAY_SPELL_VISUAL); + ClientServices::ClearMessageHandler(SMSG_PLAY_SPELL_IMPACT); + ClientServices::ClearMessageHandler(SMSG_SET_FLAT_SPELL_MODIFIER); + ClientServices::ClearMessageHandler(SMSG_SET_PCT_SPELL_MODIFIER); + ClientServices::ClearMessageHandler(SMSG_CANCEL_AUTO_REPEAT); + ClientServices::ClearMessageHandler(SMSG_GAME_OBJECT_RESET_STATE); + ClientServices::ClearMessageHandler(SMSG_FEIGN_DEATH_RESISTED); + ClientServices::ClearMessageHandler(SMSG_SPELL_UPDATE_CHAIN_TARGETS); + ClientServices::ClearMessageHandler(SMSG_NOTIFY_DEST_LOC_SPELL_CAST); + ClientServices::ClearMessageHandler(SMSG_ON_CANCEL_EXPECTED_RIDE_VEHICLE_AURA); + ClientServices::ClearMessageHandler(SMSG_SET_PROJECTILE_POSITION); + ClientServices::ClearMessageHandler(SMSG_RESET_RANGED_COMBAT_TIMER); + ClientServices::ClearMessageHandler(SMSG_RESUME_CAST_BAR); + s_itemCooldowns.InternalClear(0); + + for (uint32_t i = 0; i < sizeof(s_spellHistory) / sizeof(s_spellHistory[0]); i++) { + s_spellHistory[i].ClearAll(); + } + + if (s_spellWorldObject) { + World::ObjectDestroy(s_spellWorldObject); + s_spellWorldObject = nullptr; + } + + if (s_spellWorldModel) { + s_spellWorldModel->Release(); + s_spellWorldModel = nullptr; + } + + s_pendingSpellCasts.Clear(); + s_freePendingSpellCasts.Clear(); + s_periodicClientTriggers.Clear(); + s_destLocSpellCasts.InternalClear(0); + s_enableErrorSpeechCVar = nullptr; +} + +// VERIFY: f60bc498 manual +// OFFSET: 0x00807D40 +int32_t SpellHistory::RecentlyCast(int32_t spellId, int32_t itemId) { + uint32_t now = OsGetAsyncTimeMs(); + + for (SPELLHISTORY* history = this->m_history.Head(); history; history = this->m_history.Next(history)) { + if (history->m_spellId == spellId && history->m_itemId == itemId && static_cast(now - history->m_time - 1500) < 0) { + return 1; + } + } + + return 0; +} + +// VERIFY: 293fcda8 manual +// OFFSET: 0x007FEA30 +ItemSubClassRec* FindAnyItemSubclassRec(int32_t classId, int32_t subclassMask) { + for (int32_t i = 0; i < g_itemSubClassDB.m_numRecords; i++) { + ItemSubClassRec* rec = i < 0 || i >= g_itemSubClassDB.m_numRecords ? nullptr : &g_itemSubClassDB.m_records[i]; + + if (rec->m_classID == classId && ((1 << rec->m_subClassID) & subclassMask)) { + return rec; + } + } + + return nullptr; +} + +// VERIFY: e5a5e4cb manual +// OFFSET: 0x00805610 +void ShowPetSpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t misc1, int32_t misc2) { + char format[1024]; + char text[1024]; + + switch (reason) { + case 1: + CGGameUI::DisplayError(ERR_PET_SPELL_AFFECTING_COMBAT); + break; + + case 23: + CGGameUI::DisplayError(ERR_PET_SPELL_DEAD); + break; + + case 29: + case 30: + case 31: { + FormatString(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE, format, sizeof(format)); + bool found = false; + + for (int32_t i = 0; i < g_itemSubClassMaskDB.m_numRecords; i++) { + ItemSubClassMaskRec* rec = i < 0 || i >= g_itemSubClassMaskDB.m_numRecords ? nullptr : &g_itemSubClassMaskDB.m_records[i]; + + if (rec->m_classID == misc1 && rec->m_mask == misc2) { + SStrPrintf(text, sizeof(text), format, rec->m_name); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, text); + found = true; + break; + } + } + + if (!found) { + ItemSubClassRec* rec = FindAnyItemSubclassRec(misc1, misc2); + + if (rec) { + SStrPrintf(text, sizeof(text), format, rec->m_displayName); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, text); + } + } + + break; + } + + case 56: + CGGameUI::DisplayError(ERR_PET_SPELL_NOPATH); + break; + + case 57: + CGGameUI::DisplayError(ERR_PET_SPELL_NOT_BEHIND); + break; + + case 67: + CGGameUI::DisplayError(static_cast(((spell->m_attributes & 0x10) | 0x340) >> 4)); + break; + + case 85: { + PowerDisplayRec* display = g_powerDisplayDB.GetRecord(spell->m_powerDisplayID); + + if (display) { + char power[128]; + FormatString(display->m_globalStringBaseTag, -1, GENDER_NOT_APPLICABLE, power, 127); + CGGameUI::DisplayError(ERR_OUT_OF_POWER_DISPLAY, power); + } else if (spell->m_powerType == -2) { + CGGameUI::DisplayError(ERR_OUT_OF_HEALTH); + } else { + CGGameUI::DisplayError(s_powerErrors[spell->m_powerType]); + } + + break; + } + + case 94: { + FormatString(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + uint32_t count = g_spellShapeshiftFormDB.m_numRecords; + + if (count > 64) { + count = 64; + } + + for (uint32_t i = 0; i < count; i++) { + if (!SpellRec::UsableInShapeshift(spell, i)) { + continue; + } + + SpellShapeshiftFormRec* form = static_cast(i) < 0 || static_cast(i) >= g_spellShapeshiftFormDB.m_numRecords ? nullptr : &g_spellShapeshiftFormDB.m_records[i]; + + if (form && form->m_name && *form->m_name) { + SStrPrintf(format, sizeof(format), text, form->m_name); + CGGameUI::DisplayError(ERR_SPELL_FAILED_SHAPESHIFT_FORM_S, format); + break; + } + } + + break; + } + + case 97: + CGGameUI::DisplayError(ERR_PET_SPELL_OUT_OF_RANGE); + break; + + case 101: { + FormatString(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + AreaTableRec* area = g_areaTableDB.GetRecord(misc1); + + if (area) { + SStrPrintf(format, sizeof(format), text, area->m_areaName); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, format); + } + + break; + } + + case 102: { + FormatString(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + SpellFocusObjectRec* focus = g_spellFocusObjectDB.GetRecord(misc1); + + if (focus) { + SStrPrintf(format, sizeof(format), text, focus->m_name); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, format); + } + + break; + } + + case 103: + CGGameUI::DisplayError(ERR_PET_SPELL_ROOTED); + break; + + case 109: + CGGameUI::DisplayError(ERR_PET_SPELL_TARGETS_DEAD); + break; + + case 147: { + FormatString(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + SpellMechanicRec* mechanic = g_spellMechanicDB.GetRecord(misc1); + + if (mechanic) { + SStrPrintf(format, sizeof(format), text, mechanic->m_stateName); + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, format); + } + + break; + } + + case 172: + GetCustomSpellFailedString(text, sizeof(text), misc1); + break; + + default: + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, FrameScript_GetText(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE)); + break; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, spell, reason); + FinishPendingSpellCast(cast, spell, unit); + } +} + +// VERIFY: 3494eae5 manual +// OFFSET: 0x00805B10 +void Spell_C_SetCooldownLeft(int32_t spellId, uint32_t itemId, uint32_t category, int32_t cooldownLeft, int32_t categoryCooldownLeft, bool onHold, int32_t pet) { + uint32_t now = OsGetAsyncTimeMs(); + int32_t time = 0; + int32_t recovery = 0; + int32_t categoryTime = 0; + int32_t categoryRecovery = 0; + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + ItemStats_C* stats = nullptr; + int32_t index = 0; + + if (itemId) { + WOWGUID none = { 0 }; + stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (stats) { + for (index = 0; index < 5; index++) { + if (stats->m_spellId[index] == static_cast(spellId)) { + break; + } + } + + if (index >= 5) { + stats = nullptr; + } + } + } + + if (cooldownLeft > 0) { + int32_t value; + + if (!stats || (value = static_cast(stats->m_spellCooldown[index])) < 0) { + value = spell.m_recoveryTime; + } + + if (value <= cooldownLeft) { + value = cooldownLeft; + } + + if (Spell_C_GetSpellModifiers(&spell, 11, time, recovery)) { + value = (time + value) * recovery / 100; + } + + recovery = value; + time = now - (value - cooldownLeft); + } + + if (categoryCooldownLeft > 0) { + int32_t value; + + if (!stats || (value = static_cast(stats->m_spellCategoryCooldown[index])) < 0) { + categoryRecovery = spell.m_categoryRecoveryTime; + Spell_C_ModifyCategoryRecovery(categoryRecovery, &spell, pet); + value = categoryRecovery; + } + + if (value <= categoryCooldownLeft) { + value = categoryCooldownLeft; + } + + categoryTime = now - (value - categoryCooldownLeft); + categoryRecovery = value; + } + + if (recovery || categoryRecovery || onHold) { + SpellHistory& history = s_spellHistory[pet]; + SPELLHISTORY* entry = history.m_free.Head(); + + if (entry) { + history.m_free.UnlinkNode(entry); + history.m_history.LinkToTail(entry); + } else { + entry = history.m_history.NewNode(2, 0, 8); + } + + entry->m_spellId = spellId; + entry->m_itemId = itemId; + entry->m_time = time; + entry->m_recoveryTime = recovery; + entry->m_category = category; + entry->m_categoryTime = categoryTime; + entry->m_categoryRecoveryTime = categoryRecovery; + entry->m_onHold = onHold; + entry->m_startRecoveryCategory = 0; + entry->m_startRecoveryTime = 0; + } +} + +// VERIFY: 8f7722c4 manual +// OFFSET: 0x00805D70 +void Spell_C_StartSpellCooldown(const SpellRec* spell, CGUnit_C* unit) { + if (!spell->m_startRecoveryCategory && !spell->m_startRecoveryTime) { + return; + } + + int32_t time = spell->m_startRecoveryTime; + int32_t recovery = time; + int32_t flat; + int32_t pct; + + if (Spell_C_GetSpellModifiers(spell, 21, flat, pct)) { + recovery = (recovery + flat) * pct / 100; + } + + if (spell->m_startRecoveryCategory == 133 && time == 1500 && spell->m_defenseType != 2 && spell->m_defenseType != 3 && !(spell->m_attributes & 0x12)) { + float scaled = recovery * unit->m_unit->m_unitModCastSpeed; + recovery = CMath::fint_(scaled - 0.5f); + + if (static_cast(recovery - 1000) > 500) { + recovery = recovery - 1000 < 0 ? 1000 : 1500; + } + } + + if (!recovery) { + return; + } + + bool pet = unit->m_obj->m_guid == CGPetInfo::GetPet(0); + bool onHold = Spell_C_HasCooldownOnEvent(spell, unit->m_obj->m_guid); + s_spellHistory[pet].AddHistory(spell->m_id, 0, OsGetAsyncTimeMs(), 0, 0, OsGetAsyncTimeMs(), 0, onHold, spell->m_startRecoveryCategory, recovery); + CGSpellBook::UpdateCooldowns(); + + if (spell->m_attributes & 0x2000000) { + CGSpellBook::UpdateUsable(); + } + + if (pet) { + CGPetInfo::UpdateCooldowns(); + } +} + +// VERIFY: 10210842 manual +// OFFSET: 0x00807DA0 +int32_t SpellHistory::IsOnHold(int32_t spellId, int32_t itemId) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return 0; + } + + int32_t category = spell.m_category; + + if (itemId) { + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (stats) { + for (uint32_t i = 0; i < 5; i++) { + if (stats->m_spellId[i] == static_cast(spellId) && static_cast(stats->m_spellCategory[i]) > 0) { + category = stats->m_spellCategory[i]; + } + } + } + } + + for (SPELLHISTORY* history = this->m_history.Head(); history; history = this->m_history.Next(history)) { + if (history->m_spellId == spellId && history->m_itemId == itemId && (history->m_recoveryTime || history->m_onHold) && history->m_onHold) { + return 1; + } + + if (history->m_category == category && history->m_categoryRecoveryTime && history->m_onHold) { + return 1; + } + } + + return 0; +} + +// VERIFY: 50546e74 manual +// OFFSET: 0x00807F10 +static UIErrors GetSpellFailedError(int32_t reason, const SpellRec* spell, int32_t misc) { + UIErrors error = ERR_SPELL_FAILED_S; + + switch (reason) { + case 2: + return ERR_SPELL_FAILED_ALREADY_AT_FULL_HEALTH; + + case 3: + return ERR_SPELL_FAILED_ALREADY_AT_FULL_MANA; + + case 4: + return ERR_SPELL_FAILED_ALREADY_AT_FULL_POWER_S; + + case 11: + return ERR_GENERIC_NO_TARGET; + + case 12: + if (spell->m_targets & 0x10) { + return ERR_INVALID_ITEM_TARGET; + } + + if (spell->m_targets & 0x20000) { + return ERR_INVALID_GLYPH_SLOT; + } + + return error; + + case 28: + return ERR_SPELL_FAILED_EQUIPPED_ITEM; + + case 29: + case 30: + case 31: + return ERR_SPELL_FAILED_EQUIPPED_ITEM_CLASS_S; + + case 45: + switch (spell->m_category) { + case 4: + case 9: + return ERR_POTION_COOLDOWN; + + case 10: + case 11: + return ERR_FOOD_COOLDOWN; + + default: + return ERR_ITEM_COOLDOWN; + } + + case 52: + return ERR_NOAMMO_S; + + case 67: + switch (spell->m_category) { + case 4: + case 9: + error = ERR_POTION_COOLDOWN; + break; + + case 10: + case 11: + error = ERR_FOOD_COOLDOWN; + break; + + default: + error = static_cast(((spell->m_attributes & 0x10) | 0x340) >> 4); + break; + } + + if (misc || !s_spellHistory[0].IsOnHold(spell->m_id, 0)) { + return error; + } + + s_spellHistory[0].ClearOnHold(spell->m_id, 0, true); + CGSpellBook::UpdateCooldowns(); + CGSpellBook::UpdateUsable(); + CGContainerInfo::UpdateCooldowns(); + return error; + + case 72: + return ERR_SPELL_FAILED_NOTUNSHEATHED; + + case 94: + return ERR_SPELL_FAILED_SHAPESHIFT_FORM_S; + + case 97: + return ERR_SPELL_OUT_OF_RANGE; + + case 100: + return ERR_SPELL_FAILED_REAGENTS; + + case 129: + if (misc > 0) { + error = ERR_ITEM_MAX_LIMIT_CATEGORY_COUNT_EXCEEDED_IS; + } + + return error; + + case 131: + return ERR_SPELL_FAILED_TOTEMS; + + case 148: + return ERR_PLAY_TIME_EXCEEDED; + + case 170: + return ERR_BAD_ON_USE_ENCHANT; + + case 174: + return ERR_TOO_MANY_SOCKETS; + + case 178: + return ERR_GENERIC_NO_VALID_TARGETS; + + case 184: + return ERR_MAX_SOCKETS; + + default: + return error; + } +} + +// VERIFY: 8b2b158f manual +// OFFSET: 0x00808200 +void Spell_C_SpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t misc1, int32_t misc2, bool resetCooldown) { + int32_t spellId = cast->m_data.m_spellId; + bool suppress = false; + + if (cast == s_delayedTrajectoryCast) { + s_delayedTrajectoryCast = nullptr; + } + + UpdateTradeSkillRecast(spellId); + + if (s_autoRepeatingSpell && (reason == 67 || reason == 105)) { + SpellRec autoRepeat; + + if (g_spellDB.GetRecord(s_autoRepeatingSpell, &autoRepeat) && (autoRepeat.m_attributesExC & 0x400000)) { + CDataStore msg; + msg.Put(static_cast(CMSG_CANCEL_CAST)); + msg.Put(static_cast(0)); + msg.Put(static_cast(s_autoRepeatingSpell)); + msg.Finalize(); + ClientServices::Send2(&msg); + Spell_C_CancelAutoRepeat(true); + } + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && reason != 27) { + SI2::PlaySpellFizzleSound(spellId, player); + } + + UIErrors error = GetSpellFailedError(reason, spell, misc1); + + if (player) { + if (reason == 52) { + CGTutorial::TriggerTutorial(44); + } + + bool autoRepeat = false; + + if (cast == s_targetingSpell) { + autoRepeat = spellId == s_autoRepeatingSpell; + } else if (spellId == s_autoRepeatingSpell) { + autoRepeat = true; + } else { + switch (reason) { + case 47: + case 52: + case 53: + case 54: + case 97: + case 128: + case 134: + player->CancelRangedMode(); + break; + } + } + + if (autoRepeat) { + bool cancel = reason != 27; + bool check = true; + + if (spellId == s_autoRangedCombatSpell && resetCooldown) { + switch (reason) { + case 11: + case 12: + case 23: + case 28: + case 29: + case 30: + case 31: + case 52: + case 97: + case 128: + case 134: + break; + + default: + check = false; + break; + } + } + + if (check && cancel) { + Spell_C_CancelAutoRepeat(true); + + switch (reason) { + case 29: + case 52: + case 53: + case 54: + case 97: + case 128: + case 134: + player->CancelRangedMode(); + break; + } + } + } + + if (spellId == s_autoRangedCombatSpell) { + if (reason == s_lastAutoRangedCombatError) { + suppress = true; + } + + s_lastAutoRangedCombatError = reason; + } + + uint32_t now = OsGetAsyncTimeMs(); + + if (static_cast(spellId) == unk_D397C4 && reason == s_lastFailedReason) { + if (static_cast(now - s_lastFailedTime - 3000) < 0) { + suppress = true; + } + } else { + unk_D397C4 = spellId; + s_lastFailedReason = reason; + } + + s_lastFailedTime = now; + } + + if (reason == 27) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, spell, 27); + FinishPendingSpellCast(cast, spell, unit); + } + + return; + } + + char format[1024]; + format[0] = 0; + bool pet = spell->m_effect[0] == 57 || (spell->m_effect[0] == 36 && spell->m_implicitTargetA[0] == 5); + + if (pet) { + char token[64]; + SStrPrintf(token, sizeof(token), "%s_PET", GetSpellFailedResult(reason)); + + if (player) { + SStrCopy(format, player->GetFrameScriptText(token, -1), sizeof(format)); + } else { + SStrCopy(format, FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), sizeof(format)); + } + } + + if (!format[0]) { + if (reason == 172) { + GetCustomSpellFailedString(format, sizeof(format), misc1); + suppress = true; + } + + if (!format[0]) { + if (player) { + SStrCopy(format, player->GetFrameScriptText(GetSpellFailedResult(reason), -1), sizeof(format)); + } else { + SStrCopy(format, FrameScript_GetText(GetSpellFailedResult(reason), -1, GENDER_NOT_APPLICABLE), sizeof(format)); + } + } + } + + if (resetCooldown) { + s_spellHistory[0].RemoveStartCooldown(spellId); + } + + if (spell->m_startRecoveryCategory && spell->m_startRecoveryTime) { + CGUIMacros::m_state &= ~0x4u; + } + + char text[1024]; + const char* message = format; + + switch (reason) { + case 4: { + if (!player) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + uint32_t powerType = player->m_unit->m_unitFieldBytes0[3]; + + if (powerType > 6) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + const char* power = FrameScript_GetText(GetPowerString(powerType), -1, GENDER_NOT_APPLICABLE); + + if (!power || !*power) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + SStrCopy(text, power, sizeof(text)); + message = text; + break; + } + + case 29: + case 30: + case 31: { + bool found = false; + + for (int32_t i = 0; i < g_itemSubClassMaskDB.m_numRecords; i++) { + ItemSubClassMaskRec* rec = i < 0 || i >= g_itemSubClassMaskDB.m_numRecords ? nullptr : &g_itemSubClassMaskDB.m_records[i]; + + if (rec->m_classID == misc1 && rec->m_mask == misc2) { + SStrPrintf(text, sizeof(text), format, rec->m_name); + message = text; + found = true; + break; + } + } + + if (!found) { + ItemSubClassRec* rec = FindAnyItemSubclassRec(misc1, misc2); + + if (rec) { + SStrPrintf(text, sizeof(text), format, rec->m_displayName); + message = text; + } + } + + break; + } + + case 54: { + ItemSubClassRec* rec = FindAnyItemSubclassRec(6, 1 << misc1); + + if (rec) { + SStrPrintf(text, sizeof(text), format, rec->m_displayName); + message = text; + } + + break; + } + + case 55: { + WOWGUID guid = { static_cast(static_cast(spellId)) | 0x1FE0000000000000ull }; + ItemStats_C* stats = g_itemDBCache.GetRecord(misc1, guid, SpellMissingItemsCallback, reinterpret_cast(static_cast(misc2)), false); + + if (!stats) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + SStrPrintf(text, sizeof(text), format, misc2, stats->GetName(FrameScript_GetPluralIndex(misc2))); + message = text; + break; + } + + case 85: { + PowerDisplayRec* display = g_powerDisplayDB.GetRecord(spell->m_powerDisplayID); + + if (display) { + char power[128]; + FormatString(display->m_globalStringBaseTag, -1, GENDER_NOT_APPLICABLE, power, 127); + CGGameUI::DisplayError(ERR_OUT_OF_POWER_DISPLAY, power); + } else if (spell->m_powerType == -2) { + error = ERR_OUT_OF_HEALTH; + } else { + error = s_powerErrors[spell->m_powerType]; + } + + text[0] = 0; + message = text; + break; + } + + case 94: { + uint32_t count = g_spellShapeshiftFormDB.m_numRecords; + + if (count > 64) { + count = 64; + } + + if (!count) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + char forms[512]; + bool first = true; + + for (uint32_t i = 0; i < count; i++) { + if (!SpellRec::UsableInShapeshift(spell, i)) { + continue; + } + + SpellShapeshiftFormRec* form = g_spellShapeshiftFormDB.GetRecordByIndex(i); + + if (!form || !form->m_name || !*form->m_name) { + continue; + } + + if (first) { + SStrCopy(forms, form->m_name, sizeof(forms)); + first = false; + } else { + SStrPack(forms, ", ", sizeof(forms)); + SStrPack(forms, form->m_name, sizeof(forms)); + } + } + + if (first) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + SStrPrintf(text, sizeof(text), format, forms); + message = text; + break; + } + + case 100: + case 131: { + if (reason == 100 && misc1 == -2) { + error = static_cast(0); + text[0] = 0; + message = text; + break; + } + + WOWGUID guid = { static_cast(static_cast(spellId)) | 0x1FE0000000000000ull }; + ItemStats_C* stats = g_itemDBCache.GetRecord(misc1, guid, SpellMissingItemCallback, reinterpret_cast(static_cast(reason)), false); + + if (!stats) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + SStrPrintf(text, sizeof(text), format, stats->GetName(0)); + message = text; + break; + } + + case 101: { + AreaTableRec* area = g_areaTableDB.GetRecord(misc1); + + if (area) { + SStrPrintf(text, sizeof(text), format, area->m_areaName); + message = text; + } + + break; + } + + case 102: { + SpellFocusObjectRec* focus = g_spellFocusObjectDB.GetRecord(misc1); + + if (focus) { + SStrPrintf(text, sizeof(text), format, focus->m_name); + message = text; + } + + break; + } + + case 129: { + if (!misc1) { + break; + } + + ItemLimitCategoryRec* limit = g_itemLimitCategoryDB.GetRecord(misc1); + + if (!limit) { + break; + } + + CGGameUI::DisplayError(error, limit->m_quantity, limit->m_name); + UnitCombatLogSpellFail(ClntObjMgrGetActivePlayer(), spellId, CGGameUI::LastErrorMessage()); + suppress = true; + break; + } + + case 130: { + TotemCategoryRec* totem = g_totemCategoryDB.GetRecord(misc1); + + if (!totem) { + Spell_C_FailPendingCast(cast, spell, 27); + return; + } + + SStrPrintf(text, sizeof(text), format, totem->m_name); + message = text; + break; + } + + case 147: { + SpellMechanicRec* mechanic = g_spellMechanicDB.GetRecord(misc1); + + if (mechanic) { + SStrPrintf(text, sizeof(text), format, mechanic->m_stateName); + message = text; + } + + break; + } + + case 150: { + SkillLineRec* skill = g_skillLineDB.GetRecord(misc1); + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", misc2); + message = text; + break; + } + + case 176: { + CGObject_C* object = ClntObjMgrObjectPtr(cast->m_data.m_castItem, TYPEMASK_OBJECT, __FILE__, __LINE__); + const char* name = spell->m_name; + + if (object && (object->m_obj->m_type & TYPEMASK_ITEM)) { + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(object->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (stats && stats->GetName(0)) { + name = stats->GetName(0); + } + } + + SStrPrintf(text, sizeof(text), format, name); + break; + } + + case 181: + SStrPrintf(text, sizeof(text), format, misc1); + message = text; + break; + } + + if (!suppress) { + CGGameUI::DisplayError(error, message); + + if (*message) { + UnitCombatLogSpellFail(ClntObjMgrGetActivePlayer(), spellId, message); + } else { + UnitCombatLogSpellFail(ClntObjMgrGetActivePlayer(), spellId, CGGameUI::LastErrorMessage()); + } + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + HandleSpellFailedOrGo(unit, cast, spell, reason); + FinishPendingSpellCast(cast, spell, unit); + } +} + +// VERIFY: 0c19acb4 manual +// OFFSET: 0x00808DE0 +void Spell_C_PendingItemCooldownCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + HASHKEY_NONE key; + ITEMCOOLDOWNHASHNODE* node = s_itemCooldowns.Ptr(id, key); + + if (!node) { + return; + } + + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(id, none, nullptr, nullptr, false); + + if (stats) { + uint32_t index; + + for (index = 0; index < 5; index++) { + if (stats->m_spellId[index] == static_cast(node->m_spellId)) { + break; + } + } + + if (index < 5) { + SpellRec spell; + g_spellDB.GetRecord(node->m_spellId, &spell); + int32_t recovery = static_cast(stats->m_spellCooldown[index]) >= 0 ? static_cast(stats->m_spellCooldown[index]) : spell.m_recoveryTime; + int32_t category = 0; + int32_t categoryRecovery = 0; + + if (param) { + category = static_cast(stats->m_spellCategory[index]) > 0 ? static_cast(stats->m_spellCategory[index]) : spell.m_category; + categoryRecovery = static_cast(stats->m_spellCategoryCooldown[index]) >= 0 ? static_cast(stats->m_spellCategoryCooldown[index]) : spell.m_categoryRecoveryTime; + } + + if (recovery || categoryRecovery) { + bool onHold = node->m_onHold; + int32_t spellId = node->m_spellId; + uint32_t time = node->m_time; + + if (recovery || categoryRecovery || onHold) { + SpellHistory& history = s_spellHistory[0]; + SPELLHISTORY* entry = history.m_free.Head(); + + if (entry) { + history.m_free.UnlinkNode(entry); + history.m_history.LinkToTail(entry); + } else { + entry = history.m_history.NewNode(2, 0, 8); + } + + entry->m_spellId = spellId; + entry->m_itemId = id; + entry->m_time = time; + entry->m_recoveryTime = recovery; + entry->m_category = category; + entry->m_categoryTime = time; + entry->m_categoryRecoveryTime = categoryRecovery; + entry->m_onHold = onHold; + entry->m_startRecoveryCategory = 0; + entry->m_startRecoveryTime = 0; + } + } + } + + CGSpellBook::UpdateCooldowns(); + CGContainerInfo::UpdateCooldowns(); + } + + s_itemCooldowns.Delete(node); +} + +// VERIFY: 588a8016 auto +// OFFSET: 0x00809100 +int32_t Spell_C_WasSpellRecentlyUsed(int32_t spellId, int32_t pet) { + if (!g_secureAbilityToggleCVar->m_intValue) { + return 0; + } + + return s_spellHistory[pet].RecentlyCast(spellId, 0); +} + +// VERIFY: 0adfd8d9 manual +// OFFSET: 0x00809130 +int32_t Spell_C_WasItemRecentlyUsed(int32_t itemId) { + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (!stats) { + return 0; + } + + for (uint32_t i = 0; i < sizeof(stats->m_spellId) / sizeof(stats->m_spellId[0]); i++) { + if (static_cast(stats->m_spellId[i]) > 0 && !stats->m_spellTrigger[i]) { + return s_spellHistory[0].RecentlyCast(stats->m_spellId[i], itemId); + } + } + + return 0; +} + +// VERIFY: 35a53b59 auto +// OFFSET: 0x007FFD60 +static int32_t FindAmmoByType(const CGItem_C* item, void* param) { + AmmoSearch* search = static_cast(param); + + if (item->GetClassID() == 6 && item->GetSubtypeID() == search->m_ammoType) { + if (!search->m_ammoId || item->m_obj->m_entryID == search->m_ammoId) { + search->m_item = item; + return 1; + } + } else if (const_cast(item)->GetBag() && search->m_item) { + search->m_item = const_cast(item)->GetBag()->FindItem(FindAmmoByType, search, 0); + return 1; + } + + return 0; +} + +// VERIFY: 58b676ca manual +// OFFSET: 0x007FFDE0 +bool Spell_C_IsActivePlayerCasting() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + return player && player->m_castSpellId; +} + +// VERIFY: 613e3fb2 manual +// OFFSET: 0x00800BA0 +bool OnCancelCombat() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || !(player->m_obj->m_type & TYPEMASK_PLAYER) || !(player->m_combatModeFlags & 0x4)) { + return false; + } + + player->SetCombatMode(); + return true; +} + +// VERIFY: c523775a manual +// OFFSET: 0x00803850 +static bool RangeCheck(CGUnit_C* caster, int32_t spellId, CGObject_C* target, uint8_t* tooFar) { + if (tooFar) { + *tooFar = 0; + } + + float minRange; + float maxRange; + Spell_C::GetSpellRange(caster, spellId, &minRange, &maxRange, target); + C3Vector targetPos = target->GetPosition(); + C3Vector casterPos = caster->GetPosition(); + float dx = casterPos.x - targetPos.x; + float dy = casterPos.y - targetPos.y; + float dz = casterPos.z - targetPos.z; + float distance = dx * dx + dz * dz + dy * dy; + + if (minRange * minRange > distance) { + return false; + } + + if (maxRange * maxRange >= distance) { + return true; + } + + if (tooFar) { + *tooFar = 1; + } + + return false; +} + +// VERIFY: 9b57db2a auto +// OFFSET: 0x008091D0 +bool Spell_C_HaveSpellTokens(CGUnit_C* unit, const SpellRec* spell, bool report, PendingSpellCast* cast) { + if (!unit->IsActivePlayer()) { + return true; + } + + CGPlayer_C* player = static_cast(unit); + + for (uint32_t i = 0; i < sizeof(spell->m_totem) / sizeof(spell->m_totem[0]); i++) { + if (spell->m_totem[i] && !player->m_bag.FindItemOfType(spell->m_totem[i], 0)) { + if (report) { + Spell_C_SpellFailed(cast, spell, 131, spell->m_totem[i], -1, false); + } + + return false; + } + } + + for (uint32_t i = 0; i < sizeof(spell->m_requiredTotemCategoryID) / sizeof(spell->m_requiredTotemCategoryID[0]); i++) { + if (spell->m_requiredTotemCategoryID[i] && !player->m_bag.FindTotemCategory(spell->m_requiredTotemCategoryID[i], 0)) { + if (report) { + Spell_C_SpellFailed(cast, spell, 130, spell->m_requiredTotemCategoryID[i], -1, false); + } + + return false; + } + } + + if (Spell_C_HasNoReagentCost(player, spell)) { + return true; + } + + for (uint32_t i = 0; i < sizeof(spell->m_reagent) / sizeof(spell->m_reagent[0]); i++) { + if (!spell->m_reagent[i]) { + continue; + } + + int32_t count = player->m_bag.GetItemTypeCount(spell->m_reagent[i], 0); + int32_t needed = spell->m_reagentCount[i]; + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(spell->m_reagent[i], none, nullptr, nullptr, false); + + if (stats) { + for (uint32_t j = 0; j < 5; j++) { + if (stats->m_spellId[j] == static_cast(spell->m_id) && stats->m_spellCharges[j]) { + needed++; + } + } + } + + if (count < needed) { + if (report) { + Spell_C_SpellFailed(cast, spell, 100, spell->m_reagent[i], -1, false); + } + + return false; + } + } + + return true; +} + +// VERIFY: 3e98536b auto +// OFFSET: 0x008093D0 +bool Spell_C_HaveEquippedSpellItems(CGUnit_C* unit, const SpellRec* spell, bool checkAmmo, bool report, PendingSpellCast* cast) { + if (!unit->IsActivePlayer()) { + return true; + } + + if ((spell->m_targets & 0x10) || spell->m_equippedItemClass < 0 || !spell->m_equippedItemSubclass) { + return true; + } + + uint32_t slots; + + if (spell->m_attributesExC & 0x400) { + slots = 0x8000; + } else if (spell->m_attributesExC & 0x1000000) { + slots = 0x10000; + } else { + slots = (spell->m_attributes & 0x2) ? 0x20000 : 0xFFFFFFFF; + } + + CGPlayer_C* player = static_cast(unit); + const CGItem_C* item = player->EquippedItemMeetSpellRequirements(spell, slots); + + if (!item) { + if (report) { + int32_t reason = (spell->m_attributesExC & 0x400) ? 30 : ((spell->m_attributesExC & 0x1000000) | 0xE800000) >> 23; + Spell_C_SpellFailed(cast, spell, reason, spell->m_equippedItemClass, spell->m_equippedItemSubclass, false); + } + + return false; + } + + if ((spell->m_attributesExC & 0x1000400) == 0x1000400 && !player->EquippedItemMeetSpellRequirements(spell, 0x10000)) { + if (report) { + Spell_C_SpellFailed(cast, spell, 31, spell->m_equippedItemClass, spell->m_equippedItemSubclass, false); + } + + return false; + } + + if (!checkAmmo) { + return true; + } + + uint32_t count = g_itemSubClassDB.m_numRecords; + + for (uint32_t i = 0; i < count; i++) { + ItemSubClassRec* subClass = g_itemSubClassDB.GetRecordByIndex(i); + + if (subClass->m_classID == item->GetClassID() && subClass->m_subClassID == item->GetSubtypeID()) { + if (subClass->m_flags & 0x10) { + return true; + } + + break; + } + } + + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(item->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (!stats) { + return true; + } + + int32_t ammoType = stats->m_ammoType; + + if (!ammoType) { + return true; + } + + if (!CGCharacterInfo::GetActivePlayerAmmoID(player)) { + if (report) { + Spell_C_SpellFailed(cast, spell, 52, ammoType, -1, false); + } + + return false; + } + + AmmoSearch search; + search.m_ammoType = ammoType; + search.m_ammoId = CGCharacterInfo::GetActivePlayerAmmoID(player); + search.m_item = nullptr; + + if (!player->m_bag.FindItem(FindAmmoByType, &search, 0)) { + if (report) { + Spell_C_SpellFailed(cast, spell, 52, ammoType, -1, false); + } + + return false; + } + + return true; +} + +// VERIFY: 66bd63ba manual +// OFFSET: 0x00809610 +bool Spell_C_RangeCheckSelected(CGUnit_C* caster, const SpellRec* spell, WOWGUID target, uint8_t* inRange, bool report, PendingSpellCast* cast) { + if (!target) { + target = CGGameUI::m_lockedTarget; + } + + CGObject_C* object = ClntObjMgrObjectPtr(target, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + return false; + } + + uint32_t needTargets = static_cast(spell->m_targets); + bool pet = false; + + for (uint32_t i = 0; i < sizeof(spell->m_implicitTargetA) / sizeof(spell->m_implicitTargetA[0]); i++) { + switch (spell->m_implicitTargetA[i]) { + case 1: + if (needTargets & 0x400) { + needTargets &= 0xFBFF; + } + + break; + + case 5: + pet = true; + + if (needTargets & 0x8000) { + needTargets &= 0x7FFF; + } + + break; + + case 6: + case 53: + needTargets |= 0x80; + break; + + case 21: + case 45: + needTargets |= 0x100; + break; + + case 23: + needTargets |= 0x800; + break; + + case 25: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 74: + case 75: + needTargets |= 0x2; + break; + + case 26: + needTargets |= 0x4000; + break; + + case 35: + needTargets |= 0x8; + break; + + case 57: + case 61: + needTargets |= 0x4; + break; + } + } + + if (pet && !(needTargets & 0x2)) { + object = ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + return false; + } + + needTargets |= 0x2; + } + + uint8_t flag = 0; + uint32_t type = object->m_obj->m_type; + bool check = false; + + if (type & TYPEMASK_UNIT) { + CGUnit_C* unit = static_cast(object); + + if (spell->m_attributesExE & 0x800) { + unit = Spell_C_TargetImpliedTarget(unit, spell, static_cast(needTargets), caster); + + if (!unit) { + return false; + } + + object = unit; + } + + if ((unit->m_unit->m_unitFieldFlags & 0x10000) && !(spell->m_attributesExF & 0x1000000)) { + return false; + } + + if (spell->m_targetCreatureType && (!unit->GetCreatureType() || !((1 << (unit->GetCreatureType() - 1)) & spell->m_targetCreatureType))) { + return false; + } + + int32_t health = unit->m_unit->m_unitFieldHealth; + + if (health <= 0 && !(unit->m_unit->m_unitDynamicFlags & 0x20) && !(needTargets & 0x8600) && !(spell->m_attributesExB & 0x1)) { + return false; + } + + if (health > 0 && (needTargets & 0x400)) { + return false; + } + + if ((needTargets & 0x8) && caster->IsInMyPartyOrRaid(unit) && caster->CanAssist(unit, false)) { + check = true; + } else if ((needTargets & 0x4) && caster->IsInMyParty(unit) && caster->CanAssist(unit, false)) { + check = true; + } else if ((needTargets & 0x100) && caster->CanAssist(unit, (spell->m_attributesExF >> 3) & 1)) { + check = true; + } else if ((needTargets & 0x80) && caster->CanAttack(unit)) { + check = true; + } else if ((needTargets & 0x2) && !(unit->m_unit->m_unitFieldFlags & 0x100)) { + check = true; + } else if ((needTargets & 0x8000) && unit->m_unit->m_unitFieldHealth <= 0 && ((unit->m_obj->m_type & TYPEMASK_PLAYER) || unit->m_unit->m_unitFieldPetnumber)) { + if (!caster->CanAssist(unit, false)) { + return false; + } + + check = true; + } else if ((needTargets & 0x200) && unit->m_unit->m_unitFieldHealth <= 0 && (unit->m_obj->m_type & TYPEMASK_PLAYER) && !caster->CanAssist(unit, false)) { + check = true; + } else { + return false; + } + } else if (type & TYPEMASK_GAMEOBJECT) { + if (!(needTargets & 0x4800)) { + return false; + } + + check = true; + } else if (type & TYPEMASK_CORPSE) { + const CGCorpse_C* corpse = static_cast(object); + + if ((needTargets & 0x8000) && !(corpse->m_corpse->m_corpseFieldFlags & 0x1) && caster->CanAssist(corpse)) { + flag = 1; + } + + if ((needTargets & 0x200) && !(corpse->m_corpse->m_corpseFieldFlags & 0x1) && !caster->CanAssist(corpse)) { + check = true; + } else if (flag) { + check = true; + } else { + return false; + } + } else { + return false; + } + + bool result = RangeCheck(caster, spell->m_id, object, &flag); + *inRange = result; + + if (!result && report) { + if (flag) { + Spell_C_SpellFailed(cast, spell, 97, -1, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 128, -1, -1, false); + } + } + + return true; +} + +// VERIFY: 5b621a4e auto +// OFFSET: 0x00809A60 +void Spell_C_StopTargeting() { + if (s_targetingSpell) { + Spell_C_CancelSpell(s_targetingSpell, true, true, 27); + } +} + +// VERIFY: 287a51ff manual +// OFFSET: 0x00809A80 +void Spell_C_StopCasting() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_castSpellId) { + Spell_C_CancelSpell(Spell_C_GetActivePlayerPendingCast(), true, true, 27); + } +} + +// VERIFY: 1ec35f12 auto +// OFFSET: 0x00809AC0 +void Spell_C_CancelPlayerSpells() { + WOWGUID player = ClntObjMgrGetActivePlayer(); + Spell_C_CancelSpellByCaster(player); +} + +// VERIFY: b8318ed4 manual +// OFFSET: 0x0080DDD0 +static int32_t Spell_C_Idle(const void* data, void* param) { + for (PeriodicClientTrigger* trigger = s_periodicClientTriggers.Head(); trigger; trigger = s_periodicClientTriggers.Next(trigger)) { + if (static_cast(OsGetAsyncTimeMs() - trigger->m_nextTime) < 0) { + continue; + } + + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(trigger->m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (caster) { + WOWGUID none = { 0 }; + Spell_C_CastSpell(caster, trigger->m_spellId, nullptr, none, nullptr, false); + + if (s_targetingSpell) { + Spell_C_CancelSpell(s_targetingSpell, true, true, 27); + } + } + + trigger->m_nextTime = OsGetAsyncTimeMs() + trigger->m_period; + } + + return 1; +} + +// VERIFY: b47f2bb5 manual +// OFFSET: 0x0080DF10 +void Spell_C_AddPeriodicClientTrigger(WOWGUID caster, int32_t auraSpellId, int32_t spellId, uint32_t period) { + if (!s_periodicClientTriggers.Head()) { + EventRegister(EVENT_ID_IDLE, Spell_C_Idle); + } + + PeriodicClientTrigger* trigger = s_periodicClientTriggers.NewNode(2, 0, 8); + trigger->m_auraSpellId = auraSpellId; + trigger->m_spellId = spellId; + trigger->m_period = period; + trigger->m_nextTime = OsGetAsyncTimeMs() + period; + trigger->m_caster = caster; +} + +// VERIFY: 11d8e07f manual +// OFFSET: 0x0080DFE0 +void Spell_C_RemovePeriodicClientTrigger(WOWGUID caster, int32_t auraSpellId) { + PeriodicClientTrigger* trigger = s_periodicClientTriggers.Head(); + + while (trigger) { + if (trigger->m_caster == caster && (trigger->m_auraSpellId == auraSpellId || !auraSpellId)) { + trigger = s_periodicClientTriggers.DeleteNode(trigger); + } else { + trigger = s_periodicClientTriggers.Next(trigger); + } + } + + if (!s_periodicClientTriggers.Head()) { + EventUnregister(EVENT_ID_IDLE, Spell_C_Idle); + } +} + +// VERIFY: e91e9c97 manual +// OFFSET: 0x0080E100 +void Spell_C_AddProcessedDestLocSpellCast(WOWGUID caster, uint8_t count, uint32_t time) { + CHashKeyGUID key; + key.m_guid = caster; + DESTLOCSPELLCASTINDEXHASHNODE* node = s_destLocSpellCasts.Ptr(static_cast(caster.m_guid), key); + + if (!node) { + node = s_destLocSpellCasts.New(static_cast(caster.m_guid), key, 0, 0); + } + + node->m_castCount = count; + node->m_time = time + 10000; +} + +// VERIFY: 1250aa97 auto +// OFFSET: 0x00810050 +int32_t Packet_SMSG_NOTIFY_DEST_LOC_SPELL_CAST(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + NotifyDestLocSpellCastData data; + data.m_destLocation = C3Vector(); + data.m_destPosition = C3Vector(); + msg->GetData(&data, sizeof(data)); + + if (data.m_caster) { + CHashKeyGUID key; + key.m_guid = data.m_caster; + DESTLOCSPELLCASTINDEXHASHNODE* node = s_destLocSpellCasts.Ptr(static_cast(data.m_caster.m_guid), key); + + if (node && static_cast(data.unk_0038 - node->m_castCount) <= 0) { + return 1; + } + + Spell_C_AddProcessedDestLocSpellCast(data.m_caster, data.unk_0038, OsGetAsyncTimeMs()); + } + + Spell_C_PlayDestLocVisualsWithoutCaster(&data); + return 1; +} + +// VERIFY: 97984ce5 manual +// OFFSET: 0x007FFAC0 +static bool CheckEnchantItemLevel(const PendingSpellCast* cast, const SpellRec* spell, const ItemStats_C* stats, const CGItem_C* item, int32_t* reason) { + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + *reason = 27; + return false; + } + + int32_t maxLevel = 0; + + if (cast->m_data.m_castItem != caster->m_obj->m_guid && item && (item->m_obj->m_type & TYPEMASK_ITEM)) { + maxLevel = spell->m_maxLevel; + } + + int32_t level = stats->m_requiredLevel ? stats->m_requiredLevel : stats->m_itemLevel; + + if (level < spell->m_baseLevel) { + if (!(spell->m_attributesExB & 0x8)) { + *reason = 48; + return false; + } + } else if (maxLevel > 0 && static_cast(stats->m_itemLevel) > maxLevel) { + *reason = 36; + return false; + } + + return true; +} + +// VERIFY: f6aa96ed manual +// OFFSET: 0x007FFB60 +static bool CheckItemRequirement(const PendingSpellCast* cast, const SpellRec* spell, WOWGUID itemGuid, int32_t* reason) { + if (!itemGuid) { + return true; + } + + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(itemGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (!item) { + *reason = 178; + return false; + } + + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(item->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (!stats) { + return true; + } + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + int32_t effect = spell->m_effect[i]; + + if ((effect == 53 || effect == 54 || effect == 156) && !CheckEnchantItemLevel(cast, spell, stats, item, reason)) { + return false; + } + } + + return true; +} + +// VERIFY: 126c913a manual +// OFFSET: 0x00803500 +static bool ValidateSpellTarget(CGUnit_C* caster, const SpellRec* spell, uint32_t count, CGUnit_C** targets, int32_t* reason, bool casterIncluded) { + if (!count) { + return true; + } + + int32_t targetAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_targetAuraSpell); + int32_t excludeTargetAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_excludeTargetAuraSpell); + + if (spell->m_targetAuraState || spell->m_excludeTargetAuraState || targetAura || excludeTargetAura) { + int32_t valid = 0; + uint32_t i = count; + + do { + CGUnit_C* target = targets[i - 1]; + i--; + + if (!target || !(target->m_obj->m_type & TYPEMASK_UNIT)) { + continue; + } + + if (casterIncluded && !i) { + break; + } + + if (spell->m_targetAuraState && !(target->m_unit->m_unitFieldAurastate & (1 << (spell->m_targetAuraState - 1))) && !caster->IgnoresAuraState(spell)) { + continue; + } + + if (spell->m_excludeTargetAuraState && (target->m_unit->m_unitFieldAurastate & (1 << (spell->m_excludeTargetAuraState - 1))) && !caster->IgnoresAuraState(spell)) { + continue; + } + + if (targetAura && !target->HasAuraBySpellId(targetAura)) { + continue; + } + + if (excludeTargetAura && target->HasAuraBySpellId(excludeTargetAura)) { + continue; + } + + valid++; + } while (i); + + if (!valid) { + *reason = 111; + return false; + } + } + + if (spell->m_attributesEx & 0x100) { + int32_t valid = 0; + uint32_t i = count; + + do { + CGUnit_C* target = targets[i - 1]; + i--; + + if (target && (target->m_obj->m_type & TYPEMASK_UNIT) && !(target->m_unit->m_unitFieldFlags & 0x80000)) { + valid++; + } + } while (i); + + if (!valid) { + *reason = 110; + return false; + } + } + + bool dispel = false; + bool steal = false; + + for (uint32_t j = 0; j < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); j++) { + if (spell->m_effect[j] == 38 || spell->m_effect[j] == 108) { + dispel = true; + } + + if (spell->m_effect[j] == 126) { + steal = true; + } + } + + if (!dispel && !steal) { + return true; + } + + int32_t found = 0; + bool immune = false; + uint32_t i = count; + + do { + CGUnit_C* target = targets[i - 1]; + i--; + + if (!target || !(target->m_obj->m_type & TYPEMASK_UNIT)) { + continue; + } + + for (uint32_t j = 0; j < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); j++) { + int32_t effect = spell->m_effect[j]; + + if (effect != 38 && effect != 108 && effect != 126) { + continue; + } + + int32_t misc = spell->m_effectMiscValue[j]; + bool mechanic = effect == 108; + bool isSteal = effect == 126; + int32_t harmful; + + if (spell->m_attributesEx & 0x10000) { + harmful = -1; + } else if (caster->CanAttack(target)) { + harmful = 1; + } else if (caster->CanAssist(target, false)) { + harmful = 0; + } else { + continue; + } + + if (target->HasDispellableAura(misc, harmful, mechanic, isSteal)) { + found++; + } else if ((0x20000000 << j) & spell->m_attributesExD) { + immune = true; + } + } + } while (i); + + if (found) { + return true; + } + + if (!immune) { + for (uint32_t j = 0; j < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); j++) { + int32_t effect = spell->m_effect[j]; + + if (effect && effect != 38 && effect != 108 && effect != 126) { + return true; + } + } + } + + *reason = dispel ? 86 : 87; + return false; +} + +// VERIFY: 48f3382c manual +// OFFSET: 0x0080AC90 +void Spell_C::SendPendingCast(PendingSpellCast* cast, bool hideVisuals) { + WOWGUID castItem = cast->m_data.m_castItem == cast->m_data.m_caster ? WOWGUID{ 0 } : cast->m_data.m_castItem; + + if (s_spellWorldObject) { + World::ObjectDestroy(s_spellWorldObject); + s_spellWorldObject = nullptr; + } + + if (s_spellWorldModel) { + s_spellWorldModel->Release(); + s_spellWorldModel = nullptr; + } + + CursorSetResetMode(1); + CursorSetMode(1); + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + if (cast == s_targetingSpell) { + s_targetingSpell = nullptr; + CGInputControl* input = CGInputControl::GetActive(); + input->m_mouseModeFlags &= ~0x10u; + input->UpdateMouseMode(0); + } + + ReleasePendingSpellCast(cast); + return; + } + + if (!castItem) { + CGSpellBook::GetAppropriateSpellRank(&cast->m_data.m_spellId, caster, static_cast(ClntObjMgrObjectPtr(cast->m_data.m_objectTarget, TYPEMASK_UNIT, __FILE__, __LINE__))); + } + + SpellRec spell; + g_spellDB.GetRecord(cast->m_data.m_spellId, &spell); + CGUnit_C** targets = static_cast(alloca(sizeof(CGUnit_C*) * 2)); + uint32_t count = 0; + bool casterIncluded = false; + + for (uint32_t i = 0; i < sizeof(spell.m_implicitTargetA) / sizeof(spell.m_implicitTargetA[0]); i++) { + if (spell.m_implicitTargetA[i] == 1 || spell.m_implicitTargetB[i] == 1) { + count = 1; + targets[0] = caster; + casterIncluded = true; + break; + } + } + + if (cast->m_data.m_objectTarget) { + targets[count++] = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_objectTarget, TYPEMASK_UNIT, __FILE__, __LINE__)); + } + + int32_t reason; + + if (!ValidateSpellTarget(caster, &spell, count, targets, &reason, casterIncluded) || (cast->m_data.m_itemTarget && !(cast->m_data.m_targetFlags & 0x1000) && !CheckItemRequirement(cast, &spell, cast->m_data.m_itemTarget, &reason))) { + Spell_C_SpellFailed(cast, &spell, reason, -1, -1, false); + return; + } + + if (!(spell.m_attributes & 0x8000000) && caster->GetClientStandState()) { + if (!caster->CanAutoStand()) { + Spell_C_SpellFailed(cast, &spell, 69, -1, -1, false); + return; + } + + caster->ChangeStandState(0); + } + + if (!(spell.m_attributes & 0x1000000) && static_cast(caster->m_unit->m_unitFieldMountdisplayid) > 0 && !caster->MountedCombatAllowed() && caster->m_mountDisplayId > 0 && !(caster->m_clientFlags & 0x10000000)) { + if (!caster->CanAutoDismount()) { + Spell_C_SpellFailed(cast, &spell, 64, -1, -1, false); + return; + } + + caster->Dismount(); + } + + if (caster->HasVehicleTransport() && !(spell.m_attributesExF & 0x1000)) { + caster->CheckVehicleExitOnCast(); + } + + if (!caster->CheckShapeshiftRules(&spell, &reason)) { + if (reason == 94 || !caster->CanAutoUnshift()) { + Spell_C_SpellFailed(cast, &spell, reason, -1, -1, false); + return; + } + + caster->CancelShapeshift(); + } + + for (uint32_t i = 0; i < sizeof(spell.m_effectAura) / sizeof(spell.m_effectAura[0]); i++) { + if (spell.m_effectAura[i] == 78) { + if (!caster->CanCurrentFormMount() && caster->CanAutoUnshift()) { + caster->CancelShapeshiftForMount(); + } + + break; + } + } + + if (caster->m_movement->m_flags & 0x2000000) { + if ((static_cast(caster->m_unit->m_unitFieldMountdisplayid) > 0 && (caster->m_mountDisplayId <= 0 || (caster->m_clientFlags & 0x10000000))) || caster->m_shapeshiftSuppressed) { + if ((spell.m_attributesEx & 0x44) && (spell.m_channelInterruptFlags & 0x18)) { + Spell_C_SpellFailed(cast, &spell, 51, -1, -1, false); + return; + } + + if ((spell.m_interruptFlags & 0x1) && !(spell.m_attributesExB & 0x20) && (SpellRec::GetCastTime(&spell, caster->m_unit->m_unitFieldPetnumber != 0, 0, 0) || (spell.m_auraInterruptFlags & 0x18))) { + Spell_C_SpellFailed(cast, &spell, 51, -1, -1, false); + return; + } + } + } + + CDataStore msg; + uint8_t castFlags = 0; + + if (castItem) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(castItem, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (!item) { + ConsoleWrite("Casting item not found", DEFAULT_COLOR); + Spell_C_SpellFailed(cast, &spell, 32, -1, -1, false); + return; + } + + CGObject_C* container = ClntObjMgrObjectPtr(item->m_item->m_itemFieldContained, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!container) { + ConsoleWrite("Casting item's container not found", DEFAULT_COLOR); + Spell_C_SpellFailed(cast, &spell, 32, -1, -1, false); + return; + } + + int32_t slot = container->GetBag()->FindItemSlot(item->m_obj->m_guid); + + if (slot < 0) { + ConsoleWrite("Casting item not found in container", DEFAULT_COLOR); + Spell_C_SpellFailed(cast, &spell, 32, -1, -1, false); + return; + } + + CGPlayer_C* owner = static_cast(ClntObjMgrObjectPtr(item->m_item->m_itemFieldOwner, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!owner) { + ConsoleWrite("Active player not found", DEFAULT_COLOR); + Spell_C_SpellFailed(cast, &spell, 32, -1, -1, false); + return; + } + + uint8_t bag = owner->FindSlotIndex(item->m_item->m_itemFieldContained); + + if (item->GetInventoryType() && (bag != 0xFF || slot > 18)) { + Spell_C_SpellFailed(cast, &spell, 28, -1, -1, false); + return; + } + + msg.Put(static_cast(CMSG_USE_ITEM)); + msg.Put(bag); + msg.Put(static_cast(slot)); + msg.Put(cast->m_data.m_castCount); + msg.Put(static_cast(cast->m_data.m_spellId)); + msg.Put(castItem.m_guid); + msg.Put(cast->m_data.unk_0124); + } else if (caster->IsActivePlayer() && !(spell.m_attributesExF & 0x40000)) { + msg.Put(static_cast(CMSG_CAST_SPELL)); + msg.Put(cast->m_data.m_castCount); + msg.Put(static_cast(cast->m_data.m_spellId)); + } else { + msg.Put(static_cast(CMSG_PET_CAST_SPELL)); + msg.Put(cast->m_petGuid.m_guid); + msg.Put(cast->m_data.m_castCount); + msg.Put(static_cast(cast->m_data.m_spellId)); + } + + SpellMissileRec* missile = g_spellMissileDB.GetRecord(spell.m_spellMissileID); + CGUnit_C* mover = static_cast(ClntObjMgrObjectPtr(CGUnit_C::s_activeMover, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (missile && (missile->m_flags & 0x1)) { + if (mover != caster) { + ConsoleWrite("Missile trajectory does not have active mover caster", DEFAULT_COLOR); + Spell_C_SpellFailed(cast, &spell, 27, -1, -1, false); + return; + } + + castFlags = 2; + CGUnit_C::SetMissileTrajectoryTargetingSpell(spell.m_id); + } + + msg.Put(castFlags); + + if (castFlags & 0x2) { + float pitch; + float speed; + + if (!Spell_C_PrepareMissileTrajectoryCast(caster, cast, &spell, &count, &pitch, &speed)) { + return; + } + + Spell_C_EncodeSequenceIntoMissileTrajectory(reinterpret_cast(&pitch), reinterpret_cast(&speed), reinterpret_cast(&cast->m_data.m_sourcePos), reinterpret_cast(&cast->m_data.m_destPos)); + PendingSpellCastData::WriteTargetInfo(&cast->m_data, &msg); + msg.Put(pitch); + msg.Put(speed); + WriteMovementPacket(mover, MSG_MOVE_STOP, &msg, 1); + caster->PreStartUpdatingMissileTrajectory(cast->m_data.m_spellId, OsGetAsyncTimeMs()); + } else { + PendingSpellCastData::WriteTargetInfo(&cast->m_data, &msg); + } + + if (cast == s_delayedTrajectoryCast) { + s_delayedTrajectoryCast = nullptr; + } + + if (mover && mover == caster && (spell.m_attributesExG & 0x80)) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_vehiclePassenger) { + player->m_vehiclePassenger->StopMovement(); + } + + mover->OnMoveStopLocal(FrameTime::s_curTimeMs); + } + + msg.Finalize(); + ClientServices::Send2(&msg); + s_targetingSpell = nullptr; + CGInputControl* input = CGInputControl::GetActive(); + input->m_mouseModeFlags &= ~0x10u; + input->UpdateMouseMode(0); + + if (caster->IsActivePlayer()) { + FrameScript_SignalEvent(SCRIPT_EVENT_UNIT_SPELLCAST_SENT, "%s%s%s%s", "player", spell.m_name, spell.m_nameSubtext, cast->m_data.m_objectTarget ? GetObjectNameFromGuid(cast->m_data.m_objectTarget) : ""); + } + + if (!hideVisuals) { + StartSpellCastVisuals(caster, cast, &spell, 0, true); + } + + Spell_C_StartSpellCooldown(&spell, caster); +} + +// VERIFY: 42f238a6 auto +// OFFSET: 0x009AB8B0 +void PendingSpellCastData::WriteTargetInfo(const PendingSpellCastData* data, CDataStore* msg) { + msg->Put(data->m_targetFlags); + + if (data->m_targetFlags & 0x18A02) { + SmartGUID guid; + guid.m_guid = data->m_objectTarget.m_guid; + *msg << guid; + } + + if (data->m_targetFlags & 0x1010) { + SmartGUID guid; + guid.m_guid = data->m_itemTarget.m_guid; + *msg << guid; + } + + if (data->m_targetFlags & 0x20) { + SmartGUID guid; + guid.m_guid = data->m_sourceTarget.m_guid; + *msg << guid; + msg->Put(data->m_sourcePos.x); + msg->Put(data->m_sourcePos.y); + msg->Put(data->m_sourcePos.z); + } + + if (data->m_targetFlags & 0x40) { + SmartGUID guid; + guid.m_guid = data->m_destTarget.m_guid; + *msg << guid; + msg->Put(data->m_destPos.x); + msg->Put(data->m_destPos.y); + msg->Put(data->m_destPos.z); + } + + if (data->m_targetFlags & 0x2000) { + msg->PutArray(reinterpret_cast(data->m_targetString), sizeof(data->m_targetString)); + } +} + +// VERIFY: 7abd47d0 auto +// OFFSET: 0x007FD410 +static void Spell_C_ClearMacroCooldownState(const SpellRec* spell) { + if (spell->m_startRecoveryCategory && spell->m_startRecoveryTime) { + CGUIMacros::m_state &= ~0x4u; + } +} + +// VERIFY: 2a122241 manual +// OFFSET: 0x007FE940 +static int32_t Spell_C_UpdateSpellWorldObject(void* param, uint32_t a2, uint64_t a3, uintptr_t a4) { + if (s_spellWorldModel) { + C44Matrix matrix(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, s_cursorWorldObjectPosition.x, s_cursorWorldObjectPosition.y, s_cursorWorldObjectPosition.z, 1.0f); + matrix.RotateAroundZ(s_cursorWorldObjectFacing); + matrix.Scale(s_cursorWorldObjectScale); + s_spellWorldModel->m_fFlags |= 0x8000; + s_spellWorldModel->m_worldTransform = matrix; + } + + return 1; +} + +// VERIFY: d383a005 manual +// OFFSET: 0x007FE9E0 +static void Spell_C_CreateSpellWorldObject(const GameObjectDisplayInfoRec* display) { + s_spellWorldModel = World::s_m2Scene->CreateModel(display->m_modelName, 0); + + if (s_spellWorldModel) { + s_spellWorldObject = CMap::ObjectCreate(s_spellWorldModel, Spell_C_UpdateSpellWorldObject, nullptr, 0, 0, 10); + } +} + +// VERIFY: f7a09138 auto +// OFFSET: 0x007FFE20 +static void GameObjectStatsCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (!s_targetingSpell || s_targetingSpell->m_data.m_castCount != static_cast(reinterpret_cast(param))) { + return; + } + + WOWGUID none = { 0 }; + GameObjectStats_C* stats = g_gameObjectDBCache.GetRecord(id, none, nullptr, nullptr, false); + + if (!stats) { + return; + } + + GameObjectDisplayInfoRec* display = g_gameObjectDisplayInfoDB.GetRecord(stats->m_displayID); + + if (display) { + s_cursorWorldObjectScale = stats->m_scale; + Spell_C_CreateSpellWorldObject(display); + } +} + +// VERIFY: 95fdd19a manual +// OFFSET: 0x00805F60 +static bool Spell_C_IsSpellPending(const WOWGUID& castItem, int32_t spellId, const PendingSpellCast* except) { + for (PendingSpellCast* cast = s_pendingSpellCasts.Head(); cast; cast = s_pendingSpellCasts.Next(cast)) { + if (cast != except && (!castItem || cast->m_data.m_castItem == castItem) && cast->m_data.m_spellId == static_cast(spellId)) { + return true; + } + } + + return false; +} + +// VERIFY: 6fd9b453 manual +// OFFSET: 0x0080C790 +static bool Spell_C_BeginCast(CGUnit_C* caster, const SpellRec* spell, WOWGUID target, PendingSpellCast* cast, bool confirmed) { + uint32_t needTargets = spell->m_targets; + s_needTargets = needTargets; + bool noTarget = false; + + switch (spell->m_implicitTargetA[0]) { + case 1: + if (needTargets & 0x400) { + s_needTargets = needTargets & ~0x400u; + } + + break; + + case 5: + if (needTargets & 0x8000) { + s_needTargets = needTargets & ~0x8000u; + } + + break; + + case 6: + case 53: + s_needTargets = needTargets | 0x80; + break; + + case 16: + noTarget = true; + break; + + case 21: + case 45: + s_needTargets = needTargets | 0x100; + break; + + case 23: + s_needTargets = needTargets | 0x800; + break; + + case 25: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 74: + case 75: + s_needTargets = needTargets | 0x2; + break; + + case 26: + s_needTargets = needTargets | 0x4000; + break; + + case 35: + s_needTargets = needTargets | 0x8; + break; + + case 57: + case 61: + s_needTargets = needTargets | 0x4; + break; + + case 89: { + SpellMissileRec* missile = g_spellMissileDB.GetRecord(spell->m_spellMissileID); + + if (missile && (missile->m_flags & 0x1)) { + s_needTargets = needTargets & ~0x40u; + } + + break; + } + + case 90: + s_needTargets = needTargets | 0x10000; + break; + } + + if ((s_needTargets & 0x2000) && s_targetString[0]) { + SStrPrintf(cast->m_data.m_targetString, sizeof(cast->m_data.m_targetString), "%s", s_targetString); + s_needTargets &= ~0x2000u; + s_targetString[0] = 0; + cast->m_data.m_targetFlags |= 0x2000; + } + + if (!s_needTargets) { + Spell_C::SendPendingCast(cast, false); + return true; + } + + if (spell->m_attributesExE & 0x800) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + CGUnit_C* implied = unit ? Spell_C_TargetImpliedTarget(unit, spell, s_needTargets, caster) : nullptr; + + if (implied) { + if (implied != unit) { + target = implied->m_obj->m_guid; + } + } else if ((s_needTargets & 0x8) | 0x104) { + s_needTargets |= 0x80; + } else if (s_needTargets & 0x80) { + s_needTargets |= 0x100; + } + } + + if (noTarget || (static_cast(target.m_guid) & static_cast(target.m_guid >> 32)) == 0xFFFFFFFF || target.m_guid == 0xFFFFFFFFFFFFFFFEull) { + return false; + } + + if ((caster->m_obj->m_type & TYPEMASK_PLAYER) && (spell->m_attributes & 0x200)) { + CGPlayer_C* player = static_cast(caster); + bool found = false; + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + if (spell->m_effect[i] != 54) { + continue; + } + + CGItem_C* items[2]; + items[0] = player->m_bag.GetItemPointer(15); + items[1] = player->m_bag.GetItemPointer(16); + + if (spell->m_equippedItemSubclass) { + for (uint32_t j = 0; j < 2; j++) { + CGItem_C* item = items[j]; + + if (item && (spell->m_equippedItemClass != item->GetClassID() || !((1 << item->GetSubtypeID()) & spell->m_equippedItemSubclass))) { + items[j] = nullptr; + } + } + } + + CGItem_C* mainHand = items[0]; + CGItem_C* offHand = items[1]; + uint32_t mainEnchant = mainHand ? mainHand->GetEnchantmentId(1) : 0; + uint32_t offEnchant = offHand ? offHand->GetEnchantmentId(1) : 0; + CGItem_C* chosen = offHand; + + if (mainHand) { + if (offHand) { + if (!mainEnchant) { + chosen = mainHand; + } else if (offEnchant) { + uint32_t misc = spell->m_effectMiscValue[i]; + + if (mainEnchant == misc) { + if (offEnchant == misc) { + if (mainHand->GetEnchantmentDuration(1) <= offHand->GetEnchantmentDuration(1)) { + chosen = mainHand; + } + } else { + chosen = mainHand; + } + } else if (offEnchant != misc) { + continue; + } + } + } else { + chosen = mainHand; + } + } else if (!offHand) { + continue; + } + + if (!chosen) { + continue; + } + + if (chosen->IsBound() && !chosen->IsPermanentlyBoundForTrade() && !confirmed) { + CGGameUI::SetLastItemSpellTarget(chosen->m_obj->m_guid); + CGGameUI::SetLastEnchantSpellID(cast->m_data.m_spellId); + ReleasePendingSpellCast(cast); + FrameScript_SignalEvent(SCRIPT_EVENT_REPLACE_ENCHANT, "%s", "spellenchant"); + return true; + } + + target = chosen->m_obj->m_guid; + + if (target) { + found = true; + break; + } + } + + if (!found) { + target.m_guid = player->m_bag.m_numSlots > 15 ? player->m_bag.m_slots[15].m_guid : 0; + } + } else if (!target) { + target = CGGameUI::m_lockedTarget; + } + + CGObject_C* object = ClntObjMgrObjectPtr(target, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (target && !object) { + float minRange; + float maxRange; + Spell_C::GetSpellRange(caster, spell->m_id, &minRange, &maxRange, nullptr); + + if (100.0f < maxRange) { + cast->m_data.m_objectTarget = target; + Spell_C::SendPendingCast(cast, false); + return true; + } + } + + if (Spell_C_HandleSpriteClick(object, cast)) { + return true; + } + + if (!g_autoSelfCastCVar->m_intValue) { + return false; + } + + if (target && (!object || !(object->m_obj->m_type & TYPEMASK_UNIT) || caster->CanAssist(static_cast(object), false))) { + return false; + } + + if (Spell_C_HandleSpriteClick(ClntObjMgrGetActivePlayerObj(), cast)) { + return true; + } + + if (caster->IsActivePlayer()) { + return false; + } + + return Spell_C_HandleSpriteClick(caster, cast); +} + +// VERIFY: 0e25cbb1 manual +// OFFSET: 0x0080CCE0 +bool Spell_C_CastSpell(CGUnit_C* caster, int32_t spellId, const CGItem_C* item, WOWGUID target, PendingSpellCast* cast, bool confirmed) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x40)) { + return false; + } + + CGUnit_C* unit = caster; + WOWGUID petGuid = caster ? caster->m_obj->m_guid : WOWGUID{ 0 }; + + if (!caster) { + return false; + } + + if (spell.m_attributesExF & 0x40000) { + CGUnitData* data = caster->m_unit; + const WOWGUID* owner = &data->m_unitFieldCharmedby; + + if (!*owner) { + owner = &data->m_unitFieldCreatedby; + } + + unit = static_cast(ClntObjMgrObjectPtr(*owner, TYPEMASK_UNIT, __FILE__, __LINE__)); + } + + if (!unit || unit->IsAlteredFormTransitionPreventingMovement()) { + return false; + } + + if (!cast) { + cast = CreatePendingSpellCast(true); + cast->m_data.m_spellId = spellId; + cast->m_data.m_castItem = item ? item->m_obj->m_guid : unit->m_obj->m_guid; + cast->m_data.m_caster = unit->m_obj->m_guid; + } + + cast->m_petGuid = petGuid; + bool melee; + + if (spell.m_effect[0] == 78 || (spell.m_attributes & 0x2) || (spell.m_attributesExB & 0x20)) { + melee = true; + } else { + melee = false; + + if (!item && (unit->m_obj->m_type & TYPEMASK_PLAYER)) { + int16_t overrideId = static_cast(static_cast(unit)->m_player->m_playerFieldBytes2); + + if (overrideId) { + OverrideSpellDataRec* rec = g_overrideSpellDataDB.GetRecord(overrideId); + + if (rec && !(rec->m_flags & 0x4) && !Spell_C_IsOverride(spellId, rec)) { + Spell_C_SpellFailed(cast, &spell, 173, -1, -1, false); + return false; + } + } + } + } + + if (!IsTutorialFlagged(5)) { + s_meleeTutorialActive = 1; + s_meleeTutorialCount = 0; + } + + if ((unit->m_obj->m_type & TYPEMASK_PLAYER) && s_meleeTutorialActive && IsTutorialFlagged(5)) { + if (melee) { + s_meleeTutorialCount++; + } else { + s_meleeTutorialActive = 0; + } + + if (s_meleeTutorialCount > 10) { + CGTutorial::TriggerTutorial(59); + } + } + + if (unit->HasVehicleTransport()) { + WOWGUID transport = { unit->GetTransportGUID() }; + CGUnit_C* vehicle = static_cast(ClntObjMgrObjectPtr(transport, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (vehicle) { + VehicleSeatRec* seat = vehicle->GetVehicleSeatRec(unit->m_movementData.m_transportSeat); + + if (seat) { + uint32_t required = 0; + + if (SpellAppliesNonStanceShapeshift(&spell)) { + required = 0x2000; + } + + if (SpellRec::HasAura(&spell, 78)) { + required |= 0x1000; + } + + if (!required) { + required = 0x4000; + } + + if (!(spell.m_attributesExF & 0x1000) && !(spell.m_attributes & 0x1000000) && (seat->m_flags & required) != required) { + Spell_C_SpellFailed(cast, &spell, 173, -1, -1, false); + return false; + } + + if ((unit->m_obj->m_type & TYPEMASK_PLAYER) && (seat->m_flags & 0x40000800)) { + for (uint32_t i = 0; i < sizeof(spell.m_effect) / sizeof(spell.m_effect[0]); i++) { + for (int32_t j = 0; j < 4; j++) { + if (spell.m_effect[i] != j) { + continue; + } + + SummonPropertiesRec* properties = g_summonPropertiesDB.GetRecord(spell.m_effectMiscValueB[i]); + + if (properties && properties->m_control) { + Spell_C_SpellFailed(cast, &spell, 173, -1, -1, false); + return false; + } + } + } + } + } + } + } + + int32_t effect = spell.m_effect[0]; + + if (effect != 83 && effect != 152 && effect != 162 && !CGSpellBook::IsTrackingSpell(spellId) && !SpellRec::WillSummonCritter(&spell)) { + uint32_t action = spell.m_effect[0] == 47 || (spell.m_attributes & 0x20) ? 6 : 2; + + if (!CGGameUI::CanPerformAction(action)) { + ReleasePendingSpellCast(cast); + return false; + } + } + + effect = spell.m_effect[0]; + + if (spell.m_startRecoveryTime && !CGUIMacros::IsActionAllowed(2)) { + ReleasePendingSpellCast(cast); + return false; + } + + if (effect == 47) { + CGTradeSkillInfo::SetTradeSkill(spell.m_id, unit->m_obj->m_guid, 0, 0, 0); + Spell_C_FailPendingCast(cast, &spell, 187); + return false; + } + + if (unit->m_obj->m_type & TYPEMASK_PLAYER) { + uint32_t flags = static_cast(unit)->m_player->m_playerFlags; + + if (flags & 0x1000000) { + if (melee || Spell_C_IsRestrictedAbility(&spell)) { + Spell_C_SpellFailed(cast, &spell, 173, -1, -1, false); + return false; + } + } else if (!melee && (flags & 0x800000)) { + Spell_C_SpellFailed(cast, &spell, 173, -1, -1, false); + return false; + } + } + + if (unit->IsDeadOrGhost() && !(spell.m_attributes & 0x800000)) { + Spell_C_SpellFailed(cast, &spell, 23, -1, -1, false); + return false; + } + + effect = spell.m_effect[0]; + + if (effect == 78) { + if (unit->OnAttackIconPressed(target, 0)) { + Spell_C_FailPendingCast(cast, &spell, 187); + return false; + } + + Spell_C_ClearMacroCooldownState(&spell); + ReleasePendingSpellCast(cast); + return false; + } + + if ((effect == 99 || effect == 127 || effect == 158) && unit->GetComboPointTarget()) { + Spell_C_SpellFailed(cast, &spell, 74, -1, -1, false); + return false; + } + + if (((effect == 53 || effect == 54 || effect == 92 || effect == 156) && unit->GetComboPointTarget()) || unit->unk_09CC) { + Spell_C_SpellFailed(cast, &spell, 105, -1, -1, false); + return false; + } + + WOWGUID casterGuid = unit->m_obj->m_guid; + + if (Spell_C_IsSpellPending(casterGuid, spellId, cast)) { + if (Spell_C_GetSpellCooldown(spellId, !unit->IsActivePlayer(), nullptr, nullptr, nullptr) || (spell.m_attributes & 0x404)) { + if (s_enableErrorSpeechCVar && s_enableErrorSpeechCVar->m_intValue) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_suppressorMode = 2; + SI2::PlaySoundKit("igPlayerInviteDecline", nullptr, nullptr, &properties); + } + + ReleasePendingSpellCast(cast); + return false; + } + } + + Spell_C_StopTargeting(); + + if (item) { + const_cast(item)->HasUseEffect(); + } + + if ((spell.m_attributesExG & 0x8) && !(unit->m_unit->m_unitFieldFlags2 & 0x40000)) { + Spell_C_SpellFailed(cast, &spell, 107, -1, -1, false); + return false; + } + + if ((!item || !(const_cast(item)->GetItemStaticFlags(0) & 0x10000000)) && !Spell_C_HaveSpellTokens(unit, &spell, true, cast)) { + ReleasePendingSpellCast(cast); + return false; + } + + if (!Spell_C_HaveEquippedSpellItems(unit, &spell, true, true, cast)) { + ReleasePendingSpellCast(cast); + return false; + } + + if (spell.m_attributes & 0x2) { + bool usable; + + if (unit->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGItem_C* weapon = static_cast(ClntObjMgrObjectPtr(WOWGUID{ static_cast(unit)->m_bag.GetItemGuid(17) }, TYPEMASK_ITEM, __FILE__, __LINE__)); + usable = weapon && weapon->IsUsable(); + } else { + usable = unit->GetVirtualItem(2, false) != nullptr; + } + + if (!usable) { + Spell_C_SpellFailed(cast, &spell, 28, spell.m_equippedItemClass, spell.m_equippedItemSubclass, false); + return false; + } + } + + if (spell.m_attributesEx & 0x500000) { + bool noComboPoints; + + if (unit->m_obj->m_guid == ClntObjMgrGetActivePlayer() && !CGGameUI::GetComboPoints(target)) { + noComboPoints = true; + } else { + noComboPoints = unit->m_obj->m_guid == CGPetInfo::GetPet(0) && !CGPetInfo::GetComboPoints(target); + } + + if (noComboPoints && !unit->IgnoresAuraState(&spell)) { + Spell_C_SpellFailed(cast, &spell, unit->m_unit->m_unitFieldBytes0[1] == 1 ? 22 : 78, -1, -1, false); + return false; + } + } + + bool autoAttack = false; + + if (Spell_C_IsRestrictedAbility(&spell)) { + bool face = !((spell.m_attributesExF >> 28) & 1); + + if (!unit->IsInMelee() && !unit->VerifyAttackIconPressed(&target, 0, 0, face, true)) { + Spell_C_ClearMacroCooldownState(&spell); + ReleasePendingSpellCast(cast); + return false; + } + + if (!(spell.m_attributesExB & 0x100000)) { + autoAttack = true; + } + } + + uint8_t inRange; + + if (Spell_C_RangeCheckSelected(unit, &spell, target, &inRange, true, cast) && !inRange) { + ReleasePendingSpellCast(cast); + return false; + } + + if (!unit->CheckAndReportSpellInhibitFlags(cast, &spell, item)) { + ReleasePendingSpellCast(cast); + return false; + } + + if (item) { + SndInterfacePlayItemSound(2, const_cast(item)); + } else if (spell.m_attributes & 0x10) { + SI2::PlaySoundKit("GAMEABILITYACTIVATE", nullptr, nullptr, nullptr); + } else { + SI2::PlaySoundKit("GAMESPELLACTIVATE", nullptr, nullptr, nullptr); + } + + if (!Spell_C_BeginCast(unit, &spell, target, cast, confirmed)) { + if (target.m_guid == 0xFFFFFFFFFFFFFFFEull) { + Spell_C_SpellFailed(cast, &spell, 11, -1, -1, false); + return false; + } + + if ((spell.m_attributes & 0x200) && (!(unit->m_obj->m_type & TYPEMASK_PLAYER) || !static_cast(unit)->m_bag.GetItemGuid(15))) { + Spell_C_SpellFailed(cast, &spell, 50, -1, -1, false); + return false; + } + + if ((s_needTargets & 0x80) && (static_cast(target.m_guid) & static_cast(target.m_guid >> 32)) != 0xFFFFFFFF && (!(spell.m_attributesExE & 0x800) || !(s_needTargets & 0x10C))) { + Spell_C_SpellFailed(cast, &spell, CGGameUI::m_lockedTarget ? 12 : 11, -1, -1, false); + return false; + } + + s_targetingSpell = cast; + CursorSetResetMode(2); + CursorSetMode(28); + CGSpellBook::UpdateSelection(); + CGInputControl* input = CGInputControl::GetActive(); + input->m_mouseModeFlags |= 0x10; + input->UpdateMouseMode(0); + s_cursorWorldObjectFacing = 0.0f; + s_cursorWorldObjectHousing = 0; + s_cursorWorldObjectScale = 1.0f; + + for (uint32_t i = 0; i < sizeof(spell.m_effect) / sizeof(spell.m_effect[0]); i++) { + int32_t objectEffect = spell.m_effect[i]; + + if (objectEffect == 50 || objectEffect == 104 || objectEffect == 105 || objectEffect == 106 || objectEffect == 107 || objectEffect == 76 || objectEffect == 81) { + if (objectEffect == 81) { + s_cursorWorldObjectHousing = 1; + } + + WOWGUID guid = { static_cast(static_cast(spell.m_id)) | 0x1FE0000000000000ull }; + GameObjectStats_C* stats = g_gameObjectDBCache.GetRecord(spell.m_effectMiscValue[i], guid, GameObjectStatsCallback, reinterpret_cast(static_cast(s_targetingSpell->m_data.m_castCount)), false); + + if (stats) { + GameObjectDisplayInfoRec* display = g_gameObjectDisplayInfoDB.GetRecord(stats->m_displayID); + + if (display) { + s_cursorWorldObjectScale = stats->m_scale; + Spell_C_CreateSpellWorldObject(display); + } + } + + break; + } + } + + CSimpleTop::s_instance->m_checkFocus = 1; + } + + if (!s_targetingSpell) { + if (autoAttack && !unit->IsInMelee() && unit->IsActivePlayer()) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player->IsInMelee()) { + unit->OnAttackIconPressed(target, 0); + } + + player->MeleeModeEnter(target); + } + + if (!s_targetingSpell && spellId == GetModalNextSpell() && unit->IsActivePlayer() && !ClntObjMgrGetActivePlayerObj()->IsInMelee()) { + unit->OnAttackIconPressed(target, 0); + } + } + + if (spell.m_attributesExB & 0x20) { + if (unit->IsActivePlayer()) { + Spell_C_SetAutoRepeatingSpell(spellId); + return true; + } + } else if (s_autoRepeatingSpell) { + SpellRec autoRepeat; + + if (g_spellDB.GetRecord(s_autoRepeatingSpell, &autoRepeat) && autoRepeat.m_equippedItemClass == 2 && (autoRepeat.m_equippedItemSubclass & 0x80000)) { + Spell_C_CancelAutoRepeat(true); + } + } + + return true; +} + +// VERIFY: 5c215492 manual +// OFFSET: 0x0080DA40 +bool Spell_C::CastSpell(int32_t spellId, const CGItem_C* item, WOWGUID target, bool confirmed) { + return Spell_C_CastSpell(ClntObjMgrGetActivePlayerObj(), spellId, item, target, nullptr, confirmed); +} + +// VERIFY: e8a1babb manual +// OFFSET: 0x0080BC80 +bool Spell_C_HandleSpriteClick(CGObject_C* object, PendingSpellCast* cast) { + if (!cast) { + cast = s_targetingSpell; + } + + if (!object || !cast) { + return false; + } + + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(cast->m_data.m_caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!caster) { + return false; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(cast->m_data.m_spellId, &spell)) { + return false; + } + + uint32_t needTargets = s_needTargets; + + if (spell.m_effect[0] != 83) { + uint32_t action = spell.m_effect[0] == 47 || (spell.m_attributes & 0x20) ? 6 : 2; + + if (!CGGameUI::CanPerformAction(action)) { + return false; + } + } + + bool result = false; + uint32_t type = object->m_obj->m_type; + + if (type & TYPEMASK_UNIT) { + CGUnit_C* unit = static_cast(object); + + if (spell.m_attributesExE & 0x800) { + unit = Spell_C_TargetImpliedTarget(unit, &spell, s_needTargets, caster); + + if (!unit) { + return false; + } + + object = unit; + + if (s_needTargets & 0x10C) { + s_needTargets &= ~0x80u; + } else if (s_needTargets & 0x80) { + s_needTargets &= ~0x100u; + } + } + + if (unit->m_obj->m_guid == cast->m_data.m_caster && (spell.m_attributesEx & 0x80000)) { + return false; + } + + if ((unit->m_unit->m_unitFieldFlags & 0x10000) && !(spell.m_attributesExF & 0x1000000)) { + return false; + } + + if (spell.m_targetCreatureType && (!unit->GetCreatureType() || !((1 << (unit->GetCreatureType() - 1)) & spell.m_targetCreatureType))) { + return false; + } + + int32_t health = unit->m_unit->m_unitFieldHealth; + + if (health <= 0 && !(unit->m_unit->m_unitDynamicFlags & 0x20) && !(s_needTargets & 0x8600) && !(spell.m_attributesExB & 0x1)) { + return false; + } + + if (health > 0 && (s_needTargets & 0x400)) { + return false; + } + + if ((s_needTargets & 0x8) && caster->IsInMyPartyOrRaid(unit) && caster->CanAssist(unit, false)) { + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x8u; + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + + if (unit->m_unit->m_unitFieldHealth <= 0) { + s_needTargets &= ~0x400u; + } + + result = true; + } else if ((s_needTargets & 0x4) && caster->IsInMyParty(unit) && caster->CanAssist(unit, false)) { + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x4u; + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + + if (unit->m_unit->m_unitFieldHealth <= 0) { + s_needTargets &= ~0x400u; + } + + result = true; + } else if ((s_needTargets & 0x100) && caster->CanAssist(unit, (spell.m_attributesExF >> 3) & 1)) { + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x100u; + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + + if (unit->m_unit->m_unitFieldHealth <= 0) { + s_needTargets &= ~0x400u; + } + + result = true; + } else if ((s_needTargets & 0x80) && caster->CanAttack(unit)) { + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x80u; + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + + if (unit->m_unit->m_unitFieldHealth <= 0) { + s_needTargets &= ~0x400u; + } + + result = true; + } else if ((s_needTargets & 0x2) && (!(unit->m_unit->m_unitFieldFlags & 0x100) || (spell.m_attributesExC & 0x10000000) || (spell.m_attributesExE & 0x200000))) { + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x2; + uint32_t remaining = s_needTargets & ~0x2u; + s_needTargets = remaining; + + if (unit->m_unit->m_unitFieldHealth <= 0) { + s_needTargets = remaining & 0xFFFF79FF; + } + + result = true; + } else if ((s_needTargets & 0x8000) && unit->m_unit->m_unitFieldHealth <= 0 && ((unit->m_obj->m_type & TYPEMASK_PLAYER) || unit->m_unit->m_unitFieldPetnumber)) { + if (!caster->CanAssist(unit, false)) { + return result; + } + + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x8000u; + result = true; + } else if ((s_needTargets & 0x200) && unit->m_unit->m_unitFieldHealth <= 0 && (unit->m_obj->m_type & TYPEMASK_PLAYER)) { + if (caster->CanAssist(unit, false)) { + return result; + } + + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x2; + s_needTargets &= ~0x200u; + result = true; + } else if (s_needTargets & 0x10000) { + if (unit->GetCreatureType() != 12) { + return result; + } + + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x10000; + s_needTargets &= ~0x10000u; + result = true; + } else if ((s_needTargets & 0x100) && (spell.m_attributesExF & 0x200) && unit->IsCharmed() && !caster->CanAttack(unit)) { + cast->m_data.m_objectTarget = unit->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x100; + s_needTargets &= ~0x100u; + result = true; + } else { + return result; + } + } else if (type & TYPEMASK_ITEM) { + if (!(s_needTargets & 0x4010)) { + return result; + } + + cast->m_data.m_itemTarget = object->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x10; + s_needTargets &= 0xFFFFBFEF; + result = true; + } else if (type & TYPEMASK_GAMEOBJECT) { + if (!(s_needTargets & 0x4800)) { + return result; + } + + cast->m_data.m_objectTarget = object->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x800; + s_needTargets &= 0xFFFFB7FF; + result = true; + } else if (type & TYPEMASK_CORPSE) { + CGCorpse_C* corpse = static_cast(object); + + if ((s_needTargets & 0x8000) && !(corpse->m_corpse->m_corpseFieldFlags & 0x1) && caster->CanAssist(corpse)) { + cast->m_data.m_objectTarget = object->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x8000; + s_needTargets &= ~0x8000u; + result = true; + } + + if ((s_needTargets & 0x200) && !(corpse->m_corpse->m_corpseFieldFlags & 0x1) && !caster->CanAssist(corpse)) { + cast->m_data.m_objectTarget = object->m_obj->m_guid; + cast->m_data.m_targetFlags |= 0x200; + s_needTargets &= ~0x200u; + result = true; + } else if (!result) { + return result; + } + } else { + return result; + } + + if ((cast->m_data.m_targetFlags & 0x18202) && cast->m_data.m_objectTarget == object->m_obj->m_guid) { + uint8_t tooFar; + + if (!RangeCheck(caster, cast->m_data.m_spellId, object, &tooFar)) { + Spell_C_SpellFailed(cast, &spell, tooFar ? 97 : 128, -1, -1, false); + cast->m_data.m_objectTarget = WOWGUID{ 0 }; + s_needTargets = needTargets; + return false; + } + } + + if (!s_needTargets) { + Spell_C::SendPendingCast(cast, false); + } + + return result; +} + +// VERIFY: 0d56c0f6 manual +// OFFSET: 0x0080C3E0 +bool Spell_C_HandleGlyphClick(int32_t socket) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return false; + } + + SpellRec spell; + PendingSpellCast* cast = s_targetingSpell; + + if (!cast || !g_spellDB.GetRecord(cast->m_data.m_spellId, &spell)) { + return false; + } + + CGPlayerLocalData* data = static_cast(player->m_player); + + if (!((1 << socket) & data->m_playerGlyphsEnabled)) { + Spell_C_SpellFailed(cast, &spell, 177, -1, -1, false); + return false; + } + + for (uint32_t i = 0; i < sizeof(spell.m_effect) / sizeof(spell.m_effect[0]); i++) { + if (spell.m_effect[i] != 74) { + continue; + } + + GlyphPropertiesRec* properties = g_glyphPropertiesDB.GetRecord(spell.m_effectMiscValue[i]); + GlyphSlotRec* slot = g_glyphSlotDB.GetRecord(data->m_playerFieldGlyphSlots1[socket]); + + if (!properties || !slot) { + cast = s_targetingSpell; + continue; + } + + if (slot->m_type != properties->m_glyphSlotFlags) { + Spell_C_SpellFailed(s_targetingSpell, &spell, 175, -1, -1, false); + return false; + } + + for (uint32_t j = 0; j < sizeof(data->m_playerFieldGlyphs1) / sizeof(data->m_playerFieldGlyphs1[0]); j++) { + if (data->m_playerFieldGlyphs1[j] == static_cast(spell.m_effectMiscValue[i])) { + Spell_C_SpellFailed(s_targetingSpell, &spell, 176, -1, -1, false); + return false; + } + } + + cast = s_targetingSpell; + cast->m_data.unk_0124 = socket; + bool result = false; + + if (s_needTargets & 0x20000) { + cast->m_data.m_targetFlags |= 0x20000; + s_needTargets &= ~0x20000u; + result = true; + + if (!s_needTargets) { + Spell_C::SendPendingCast(cast, false); + } + } + + return result; + } + + Spell_C_SpellFailed(cast, &spell, 175, -1, -1, false); + return false; +} + +// VERIFY: d31bf1c5 auto +// OFFSET: 0x0080C5F0 +int32_t Spell_C_TargetTradeItem() { + if (!(s_needTargets & 0x4010) || !CGTradeInfo::m_targetItemID[6]) { + return 0; + } + + PendingSpellCast* cast = s_targetingSpell; + cast->m_data.m_targetFlags |= 0x1000; + s_needTargets &= 0xFFFFBFEF; + cast->m_data.m_itemTarget.m_guid = 6; + + if (!s_needTargets) { + Spell_C::SendPendingCast(cast, true); + Spell_C_CancelSpell(cast, false, false, 27); + } + + return 1; +} + +// VERIFY: 25171a69 manual +// OFFSET: 0x0080DA80 +void Spell_C_ClickSpell(int32_t spellId, const CGItem_C* item, WOWGUID target) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + if (Spell_C_IsActiveSpell(&spell, player)) { + if (!g_secureAbilityToggleCVar->m_intValue || !s_spellHistory[0].RecentlyCast(spellId, 0)) { + Spell_C_CancelAura(&spell, player, -1); + } + + return; + } + + if (spellId == GetModalNextSpell()) { + WOWGUID none = { 0 }; + player->OnAttackIconPressed(none, 0); + return; + } + + if (spellId == s_autoRepeatingSpell) { + Spell_C_CancelAutoRepeat(true); + return; + } + + if (spellId == Spell_C_GetTargetingSpell()) { + Spell_C_StopTargeting(); + return; + } + + Spell_C::CastSpell(spellId, item, target, false); +} + +// VERIFY: 0ae47ac1 manual +// OFFSET: 0x0080DBD0 +bool Spell_C_TargetUnitByGuid(const WOWGUID& guid) { + return Spell_C_HandleSpriteClick(ClntObjMgrObjectPtr(guid, TYPEMASK_OBJECT, __FILE__, __LINE__), nullptr); +} + +// VERIFY: 88279f66 manual +// OFFSET: 0x0080DCF0 +bool Spell_C_HandleItemDrop(CGItem_C* item, CGUnit_C* unit) { + if (!item || !unit || !unit->m_unit->m_unitFieldPetnumber || !s_feedPetSpell) { + return false; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || unit->m_unit->m_unitFieldCreatedby != player->m_obj->m_guid) { + return false; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(s_feedPetSpell, &spell)) { + return false; + } + + WOWGUID none = { 0 }; + + if (!Spell_C::CastSpell(spell.m_id, nullptr, none, false)) { + return false; + } + + return Spell_C_HandleSpriteClick(item, nullptr); +} + +// VERIFY: 6676674c manual +// OFFSET: 0x007FFFB0 +void CreateMissilesForTargets(const TSStackArray& targets, CGUnit_C* unit, const SpellRec* spell, const SpellVisualRec* visual, uint32_t ammoDisplayId, uint32_t ammoInventoryType, PendingSpellCastData* data, const TSStackArray* missReasons, const TSStackArray* reflectResults, uint32_t delay) { + if (!unit || (!visual->m_hasMissile && !ammoDisplayId)) { + return; + } + + uint32_t targetFlags = data->m_targetFlags; + int32_t hit = missReasons == nullptr; + bool unitTargets = !(targetFlags & 0x60) || (visual->m_flags & 0x1); + + if (targets.m_count && (targetFlags & 0x802) && unitTargets) { + for (uint32_t i = 0; i < targets.m_count; i++) { + if (ClntObjMgrObjectPtr(targets.m_data[i], TYPEMASK_OBJECT, __FILE__, __LINE__)) { + uint32_t reflectResult = reflectResults ? reflectResults->m_data[i] : 0; + uint32_t missReason = missReasons ? missReasons->m_data[i] : 1; + unit->CreateMissile(&targets.m_data[i], data, ammoDisplayId, ammoInventoryType, hit, missReason, reflectResult, visual, spell->m_id, &targets, nullptr, nullptr, delay); + } + } + } else if ((targetFlags & 0x60) && (targets.m_count || !(visual->m_flags & 0x100))) { + WOWGUID none = { 0 }; + unit->CreateMissile(&none, data, ammoDisplayId, ammoInventoryType, missReasons == nullptr, 1, 0, visual, spell->m_id, &targets, missReasons, reflectResults, delay); + } +} + +// VERIFY: 9a06bb93 auto +// OFFSET: 0x00800120 +void CreateMissilesForTargetPoints(const TSStackArray& points, CGUnit_C* unit, const SpellRec* spell, const SpellVisualRec* visual, uint32_t ammoDisplayId, uint32_t ammoInventoryType, PendingSpellCastData* data, uint32_t delay) { + if (!unit || (!visual->m_hasMissile && !ammoDisplayId)) { + return; + } + + for (uint32_t i = 0; i < points.m_count; i++) { + unit->CreateMissile(&points.m_data[i], data, ammoDisplayId, ammoInventoryType, visual, spell->m_id, delay); + } +} + +// VERIFY: 8b98e965 manual +// OFFSET: 0x00800180 +void LaunchMissileVisual(const TSStackArray& hits, const TSStackArray& misses, CGUnit_C* unit, const SpellRec* spell, const SpellVisualRec* visual, uint32_t ammoDisplayId, uint32_t ammoInventoryType, PendingSpellCastData* data, const TSStackArray& missReasons, const TSStackArray& reflectResults, uint32_t delay) { + if (!unit || (!visual->m_hasMissile && !ammoDisplayId)) { + return; + } + + uint32_t count = hits.m_count + misses.m_count; + + TSStackArray targets(static_cast(alloca(sizeof(WOWGUID) * count)), count, 0); + + TSStackArray reasons(static_cast(alloca(sizeof(uint32_t) * count)), count, 0); + + TSStackArray reflects(static_cast(alloca(sizeof(uint32_t) * count)), count, 0); + + uint32_t index = 0; + + if (!(data->m_castFlags & 0x400)) { + for (; index < hits.m_count; index++) { + targets.m_data[index] = hits.m_data[index]; + reasons.m_data[index] = 0; + reflects.m_data[index] = 0; + } + + for (uint32_t i = 0; i < misses.m_count; i++, index++) { + targets.m_data[index] = misses.m_data[i]; + reasons.m_data[index] = missReasons.m_data[i]; + reflects.m_data[index] = reflectResults.m_data[i]; + } + } else { + for (uint32_t i = 0; i < misses.m_count; i++, index++) { + targets.m_data[index] = misses.m_data[index]; + reasons.m_data[index] = missReasons.m_data[index]; + reflects.m_data[index] = reflectResults.m_data[index]; + } + + for (uint32_t i = 0; i < hits.m_count; i++, index++) { + targets.m_data[index] = hits.m_data[i]; + reasons.m_data[index] = 0; + reflects.m_data[index] = 0; + } + } + + WOWGUID none = { 0 }; + unit->CreateMissile(&none, data, ammoDisplayId, ammoInventoryType, 1, 1, 0, visual, spell->m_id, &targets, &reasons, &reflects, delay); +} + +// VERIFY: 7426a6ef auto +// OFFSET: 0x00804420 +void Spell_C_ClearPetCooldowns() { + s_spellHistory[1].ClearAll(); +} + +// VERIFY: 9daeef29 manual +// OFFSET: 0x00801F10 +void PlayImpactVisual(const SpellRec* spell, const TSStackArray& targets, CGUnit_C* unit, const SpellVisualRec* visual) { + if (!spell || !visual || !targets.m_count) { + return; + } + + SpellVisualKitRec* casterKit = g_spellVisualKitDB.GetRecord(visual->m_casterImpactKit); + + if (!casterKit) { + casterKit = g_spellVisualKitDB.GetRecord(visual->m_impactKit); + } + + SpellVisualKitRec* targetKit = g_spellVisualKitDB.GetRecord(visual->m_targetImpactKit); + + if (!targetKit) { + targetKit = g_spellVisualKitDB.GetRecord(visual->m_impactKit); + } + + if (!casterKit && !targetKit) { + return; + } + + for (uint32_t i = 0; i < targets.m_count; i++) { + CGObject_C* object = ClntObjMgrObjectPtr(targets.m_data[i], TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + continue; + } + + SpellVisualKitRec* kit = object == unit ? casterKit : targetKit; + + if (kit) { + PlaySpellVisuaKitData data(spell, kit, 1); + data.unk_001C = SpellRec::IsHelpfulOrHarmful(spell) == 2; + object->PlaySpellVisualKit(data); + } + } +} + +// VERIFY: 7d12c6fb auto +// OFFSET: 0x007FE500 +PendingSpellCast* Spell_C_GetDelayedTrajectoryCast() { + return s_delayedTrajectoryCast; +} diff --git a/WoW/Source/Magic/MagicClient/Spell_C.h b/WoW/Source/Magic/MagicClient/Spell_C.h index 42506bd..f96f48c 100644 --- a/WoW/Source/Magic/MagicClient/Spell_C.h +++ b/WoW/Source/Magic/MagicClient/Spell_C.h @@ -8,6 +8,7 @@ #include "_Triage/PendingSpellCastData.h" #include "Engine/Source/Storm/H/stpl.h" #include "Engine/Source/Tempest/C3Vector.h" +#include "WoW/Source/Object/ObjectClient/Object_C.h" struct lua_State; class CGGameObject_C; @@ -15,6 +16,8 @@ class CGCorpse_C; class CDataStore; class SpellRec; class SpellVisualRec; +class SpellVisualKitRec; +class ItemSubClassRec; class CMapEntity; class ItemStats_C; @@ -23,6 +26,7 @@ class CGItem_C; class CGObject_C; class CGPlayer_C; class CGUnit_C; +class CM2Model; class CTerrainClickEvent; class PendingSpellCast : public TSLinkedNode { public: @@ -31,8 +35,7 @@ class PendingSpellCast : public TSLinkedNode { /* 0139 */ uint8_t unk_0139; /* 013A */ uint8_t unk_013A [2]; /* 013C */ uint32_t m_dwordC; - /* 0140 */ uint32_t unk_0140; - /* 0144 */ uint32_t unk_0144; + /* 0140 */ WOWGUID m_petGuid; PendingSpellCast(); void OnSpellStartPacket(CDataStore* msg); @@ -95,6 +98,37 @@ class SpellHistory { void ClearOnHold(int32_t spellId, uint32_t time, bool remove); void GarbageCollect(uint32_t time); bool GetSpellCooldown(int32_t spellId, int32_t itemId, uint32_t* duration, uint32_t* start, uint32_t* enable); + void ClearAll(); + void RemoveStartCooldown(int32_t startRecoveryCategory); + void DelayCooldown(int32_t spellId, int32_t delay); + int32_t RecentlyCast(int32_t spellId, int32_t itemId); +}; + +struct AmmoSearch { + /* 0000 */ int32_t m_ammoType; + /* 0004 */ int32_t m_ammoId; + /* 0008 */ const CGItem_C* m_item; +}; + +struct PeriodicClientTrigger : public TSLinkedNode { + /* 0008 */ int32_t m_auraSpellId; + /* 000C */ int32_t m_spellId; + /* 0010 */ uint32_t m_nextTime; + /* 0014 */ uint32_t m_period; + /* 0018 */ WOWGUID m_caster; +}; + +struct DESTLOCSPELLCASTINDEXHASHNODE : public TSHashObject { + /* 0020 */ uint8_t m_castCount; + /* 0021 */ uint8_t unk_0021[3]; + /* 0024 */ uint32_t m_time; +}; + +struct ITEMCOOLDOWNHASHNODE : public TSHashObject { + /* 0018 */ int32_t m_spellId; + /* 001C */ uint32_t m_time; + /* 0020 */ bool m_onHold; + /* 0021 */ uint8_t unk_0021[3]; }; class Spell_C { @@ -102,9 +136,10 @@ class Spell_C { /* 0000 */ uint8_t unk_0000[8]; /* 0008 */ uint32_t unk_0008; - static void SendPendingCast(bool a1); + static void SendPendingCast(PendingSpellCast* cast, bool hideVisuals); static void GetSpellRange(CGUnit_C* caster, int32_t spellId, float* minRange, float* maxRange, CGObject_C* target); static bool HandleSpriteRay(const WOWGUID& guid, bool checkRange); + static bool CastSpell(int32_t spellId, const CGItem_C* item, WOWGUID target, bool confirmed); }; int32_t Packet_Group_30(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); @@ -151,7 +186,7 @@ bool Spell_C_TargetingSpellAllowsTerrain(); bool Spell_C_CanTargetCorpse(const CGCorpse_C* corpse); bool Spell_C_CanTargetObject(const CGGameObject_C* object); bool Spell_C_IsTargeting(); -bool Spell_C_RangeCheckSelected(CGUnit_C* caster, const SpellRec* spell, WOWGUID target, uint8_t* inRange, int32_t a5, int32_t a6); +bool Spell_C_RangeCheckSelected(CGUnit_C* caster, const SpellRec* spell, WOWGUID target, uint8_t* inRange, bool report, PendingSpellCast* cast); extern PendingSpellCast* s_targetingSpell; extern uint32_t s_needTargets; int32_t Spell_C_IsCursorWorldObjectHousing(); @@ -166,16 +201,21 @@ void Spell_C_CancelSpellByCaster(const WOWGUID& caster); void Spell_C_CancelCastingSpellByMovement(); void Spell_C_CancelChannelSpell(int32_t spellId); int32_t Spell_C_GetAutoRepeatingSpell(); -void Spell_C_SetCooldownLeft(int32_t spellId, uint32_t itemId, uint32_t category, int32_t a4, int32_t cooldown, bool a6, int32_t a7); +void Spell_C_SetCooldownLeft(int32_t spellId, uint32_t itemId, uint32_t category, int32_t cooldownLeft, int32_t categoryCooldownLeft, bool onHold, int32_t pet); int32_t Spell_C_GetMinMaxPoints(const SpellRec* spell, uint32_t effectIndex, int32_t* minPoints, int32_t* maxPoints, int32_t a5, int32_t a6, int32_t a7, int32_t a8); void Spell_C_CancelAutoRepeat(bool a1); void Spell_C_CancelSpellsWithId(int32_t spellId); void Spell_C_SetAutoRangedCombatSpell(int32_t spellId); int32_t Spell_C_GetAutoRangedCombatSpell(); +PendingSpellCast* Spell_C_GetDelayedTrajectoryCast(); +int32_t Spell_C_SendDelayedMissileTrajectoryCast(CGUnit_C* unit); void Spell_C_ClearLastAutoRangedCombatError(); bool Spell_C_HandleTerrainClick(const CTerrainClickEvent& evt); -void Spell_C_HandleSpriteClick(CGObject_C* object, PendingSpellCast* spell); -int32_t Spell_C_HandleItemDrop(CGItem_C* item, CGUnit_C* unit); +bool Spell_C_HandleSpriteClick(CGObject_C* object, PendingSpellCast* cast); +bool Spell_C_HandleGlyphClick(int32_t socket); +int32_t Spell_C_TargetTradeItem(); +bool Spell_C_TargetUnitByGuid(const WOWGUID& guid); +bool Spell_C_HandleItemDrop(CGItem_C* item, CGUnit_C* unit); void Spell_C_CancelMeleeSpells(); bool Spell_C_IsRestrictedAbility(const SpellRec* spell); bool Spell_C_HasEffect(const SpellRec* spell, int32_t effect); @@ -186,10 +226,15 @@ int32_t Spell_C_IsActionOnHold(const int32_t* spellId, int32_t index); int32_t Spell_C_NeedsCooldownEvent(int32_t itemId); bool Spell_C_IsUsableAction(CGUnit_C* unit, const SpellRec* spell, const WOWGUID& target, const ItemStats_C* item, bool ignoreControl); bool Spell_C_GetSpellModifiers(const SpellRec* spell, int32_t modifier, int32_t& flat, int32_t& pct); -int32_t Spell_C_CancelsAuraEffect(const SpellRec* spell, int32_t auraType, int32_t a3); -int32_t Spell_C_CancelsCharm(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); -int32_t Spell_C_HaveSpellTokens(CGUnit_C* unit, const SpellRec* spell, bool a3, PendingSpellCast* cast); -int32_t Spell_C_HaveEquippedSpellItems(CGUnit_C* unit, const SpellRec* spell, bool a3, PendingSpellCast* cast); +bool Spell_C_CancelsAuraEffect(const CGUnit_C* unit, const SpellRec* spell, int32_t auraType, int32_t* reason); +bool Spell_C_CancelsStun(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_CancelsSilence(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_CancelsPacify(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_CancelsFear(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_CancelsConfuse(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_CancelsCharm(const CGUnit_C* unit, const SpellRec* spell, int32_t* reason); +bool Spell_C_HaveSpellTokens(CGUnit_C* unit, const SpellRec* spell, bool report, PendingSpellCast* cast); +bool Spell_C_HaveEquippedSpellItems(CGUnit_C* unit, const SpellRec* spell, bool checkAmmo, bool report, PendingSpellCast* cast); float GetGameTableValue(int32_t table, int32_t index, int32_t a3); void ItemCheckCooldownCallback(int32_t id, const WOWGUID& guid, void* param, bool success); @@ -197,9 +242,14 @@ class QuestTextParser { public: static int32_t Spell_C_SpellGetSpellIDForDifficulty(int32_t spellId); }; -void Spell_C_RemovePeriodicClientTrigger(WOWGUID guid, int32_t a2); +void Spell_C_RemovePeriodicClientTrigger(WOWGUID caster, int32_t auraSpellId); +void Spell_C_AddPeriodicClientTrigger(WOWGUID caster, int32_t auraSpellId, int32_t spellId, uint32_t period); +void Spell_C_StopCasting(); +bool Spell_C_IsActivePlayerCasting(); +bool OnCancelCombat(); void Spell_C_ClearCooldowns(); +void Spell_C_ClearPetCooldowns(); const SpellVisualRec* GetSpellVisual(const SpellRec* spell); void Spell_C_Destroy(); void Spell_C_Initialize(); @@ -238,21 +288,17 @@ int32_t Spell_C_GetDuration(const SpellRec* spell, int32_t isPet, int32_t isUnit bool Spell_C_HasNoReagentCost(CGPlayer_C* player, const SpellRec* spell); int32_t Spell_C_GetTargetingSpell(); bool Spell_C_GetItemCooldown(CGItem_C* item, uint32_t* duration, uint32_t* start, uint32_t* enable); -void Spell_C_SpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t a4, int32_t a5, bool a6); -int32_t Spell_C_CastSpell(CGUnit_C* caster, int32_t spellId, const CGItem_C* item, WOWGUID target, PendingSpellCast* cast, bool a6); +void Spell_C_SpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t misc1, int32_t misc2, bool resetCooldown); +bool Spell_C_CastSpell(CGUnit_C* caster, int32_t spellId, const CGItem_C* item, WOWGUID target, PendingSpellCast* cast, bool confirmed); void UnitCombatLogCastStart(const WOWGUID& caster, const WOWGUID& target, int32_t spellId); void Spell_C_StopTargeting(); void SpellTableDestroy(); void SpellTableInitialize(); -int32_t Script_SpellTargetItem(lua_State* L); -int32_t Script_SpellCanTargetUnit(lua_State* L); -int32_t Script_SpellTargetUnit(lua_State* L); -int32_t Script_SpellStopTargeting(lua_State* L); -int32_t Script_SpellStopCasting(lua_State* L); int32_t Script_CancelUnitBuff(lua_State* L); int32_t Script_CancelItemTempEnchantment(lua_State* L); void SpellRegisterScriptFunctions(); +void SpellUnregisterScriptFunctions(); bool SpellIsTrackingAura(const SpellRec* spell); bool SpellHasAuraEffect(const SpellRec* spell, int32_t aura); @@ -263,8 +309,43 @@ int32_t Spell_C_GetSpellReagentUses(const SpellRec* spell); int32_t Spell_C_GetSpellReagentUses(int32_t spellId); bool Spell_C_IsCurrentItem(int32_t itemId); bool Spell_C_IsCurrentSpell(int32_t spellId); -void Spell_C_GetItemCooldown(const CGItem_C* item, uint32_t* duration, uint32_t* start, uint32_t* enable); -void Spell_C_GetItemCooldown(int32_t itemId, uint32_t* duration, uint32_t* start, uint32_t* enable); +bool Spell_C_GetItemCooldown(int32_t itemId, uint32_t* duration, uint32_t* start, uint32_t* enable); +const char* GetSpellFailedResult(int32_t reason); +bool Spell_C_SpellUsesReagent(const SpellRec* spell, int32_t itemId); +PendingSpellCast* Spell_C_GetTargetingSpellCast(); +int32_t Spell_C_CanTargetItems(); +CM2Model* Spell_C_GetCursorWorldObjectModel(); +void Spell_C_SetCursorWorldObjectPosition(const C3Vector& position); +const C3Vector& Spell_C_GetCursorWorldObjectPosition(); +float Spell_C_GetCursorWorldObjectFacing(); +uint32_t GetRequiredAuraVisionBitmask(const SpellRec* spell); +void SpellMissingItemCallback(int32_t itemId, const WOWGUID& guid, void* param, bool success); +void SpellMissingItemsCallback(int32_t itemId, const WOWGUID& guid, void* param, bool success); +void GetCustomSpellFailedString(char* buffer, uint32_t size, int32_t customError); +void Spell_C_PetSpellFailedUpdateCooldowns(int32_t spellId); +void Spell_C_ClearInTransitList(); +int32_t Spell_C_PrepareMissileTrajectoryCast(CGUnit_C* caster, PendingSpellCast* cast, const SpellRec* spell, uint32_t* count, float* pitch, float* speed); +uint32_t Spell_C_EncodeSequenceIntoMissileTrajectory(uint32_t* pitch, uint32_t* speed, uint32_t* source, uint32_t* dest); +ItemSubClassRec* FindAnyItemSubclassRec(int32_t classId, int32_t subclassMask); +void ShowPetSpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t misc1, int32_t misc2); +void Spell_C_StartSpellCooldown(const SpellRec* spell, CGUnit_C* unit); +int32_t Spell_C_WasSpellRecentlyUsed(int32_t spellId, int32_t pet); +int32_t Spell_C_WasItemRecentlyUsed(int32_t itemId); +bool Spell_C_IsCastingInterruptedByCombat(const WOWGUID& guid); +int32_t Spell_C_HandleTerrainRay(const CTerrainClickEvent& evt, bool checkRange); +void Spell_C_FailPendingCast(PendingSpellCast* cast, const SpellRec* spell, int32_t reason); +bool Spell_C_IsModal(const WOWGUID& item); +PendingSpellCast* Spell_C_GetActivePlayerPendingCast(); +void Spell_C_CancelSpell(PendingSpellCast* cast, bool stopRecast, bool notifyServer, int32_t reason); +void Spell_C_CancelRangedSpells(); +void Spell_C_CancelAura(const SpellRec* spell, CGUnit_C* unit, int32_t auraIndex); +void Spell_C_PetTameFailure(uint8_t reason); +bool SpellAppliesNonStanceShapeshift(const SpellRec* spell); +void Spell_C_SetAutoRepeatingSpell(int32_t spellId); +SpellVisualKitRec* Spell_C_GetAppropriateImpactKit(const SpellVisualRec* visual, int32_t caster); +float Spell_C_GetSpellRadius(); +void Spell_C_ModifyCooldown(int32_t spellId, uint32_t time, int32_t index, int32_t remove); +void Spell_C_DelayCooldown(int32_t index, int32_t spellId, int32_t delay); bool Spell_C_GetSpellCooldown(int32_t spellId, int32_t petSpell, uint32_t* duration, uint32_t* start, uint32_t* enable); bool Spell_C_IsActiveSpell(const SpellRec* spell, const CGUnit_C* unit); uint32_t Spell_C_GetPowerDisplayMod(uint32_t powerType); diff --git a/WoW/Source/Magic/MagicClient/Spell_C_Scripts.cpp b/WoW/Source/Magic/MagicClient/Spell_C_Scripts.cpp index 701f1d0..d79a4fe 100644 --- a/WoW/Source/Magic/MagicClient/Spell_C_Scripts.cpp +++ b/WoW/Source/Magic/MagicClient/Spell_C_Scripts.cpp @@ -4,6 +4,12 @@ #include "Engine/Source/FrameScript/FrameScript_Object.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" // VERIFY: bf97997d auto // OFFSET: 0x007FDCD0 @@ -55,6 +61,137 @@ static int32_t Script_CannotBeResurrected(lua_State* L) { return 1; } +// VERIFY: 7914559b manual +// OFFSET: 0x008007E0 +static int32_t Script_SpellTargetItem(lua_State* L) { + if (!CGGameUI::CanPerformAction(2) || !s_targetingSpell || !(s_needTargets & 0x4010)) { + return 0; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return 0; + } + + CGItem_C* item; + + if (lua_isnumber(L, 1)) { + item = player->m_bag.FindItemOfType(static_cast(lua_tonumber(L, 1)), 0); + } else if (lua_isstring(L, 1)) { + item = player->m_bag.FindItemByName(lua_tolstring(L, 1, nullptr), 0); + } else { + luaL_error(L, "Usage: SpellTargetItem(itemID|\"name\"|\"itemlink\")"); + return 0; + } + + if (item) { + CGGameUI::CastItemSpell(item->m_obj->m_guid, 0); + } + + return 0; +} + +// VERIFY: 7282e805 manual +// OFFSET: 0x0080DC00 +static int32_t Script_SpellTargetUnit(lua_State* L) { + if (!lua_isstring(L, 1)) { + return luaL_error(L, "Usage: SpellTargetUnit(\"unit\")"); + } + + if (!CGGameUI::CanPerformAction(2) || !s_targetingSpell) { + return 0; + } + + CGUnit_C* unit = GetUnitFromName(lua_tolstring(L, 1, nullptr)); + + if (unit && (unit->m_obj->m_type & TYPEMASK_UNIT)) { + WOWGUID guid = unit->m_obj->m_guid; + Spell_C_TargetUnitByGuid(guid); + return 0; + } + + SpellRec spell; + PendingSpellCast* cast = s_targetingSpell; + g_spellDB.GetRecord(cast->m_data.m_spellId, &spell); + Spell_C_SpellFailed(cast, &spell, 97, -1, -1, false); + return 0; +} + +// VERIFY: dc844493 auto +// OFFSET: 0x00804190 +static int32_t Script_SpellCanTargetUnit(lua_State* L) { + if (!lua_isstring(L, 1)) { + return luaL_error(L, "Usage: SpellCanTargetUnit(\"unit\")"); + } + + WOWGUID guid = GetGuidByKeyword(lua_tolstring(L, 1, nullptr)); + + if (guid && Spell_C::HandleSpriteRay(guid, true)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: a88df190 auto +// OFFSET: 0x00809E30 +static int32_t Script_SpellStopTargeting(lua_State* L) { + if (CGGameUI::CanPerformAction(2)) { + bool targeting = s_targetingSpell != nullptr; + + if (s_targetingSpell) { + Spell_C_CancelSpell(s_targetingSpell, true, true, 27); + } + + if (targeting) { + lua_pushnumber(L, 1.0); + return 1; + } + } + + lua_pushnil(L); + return 1; +} + +// VERIFY: 0e0daa18 manual +// OFFSET: 0x00809EA0 +static int32_t Script_SpellStopCasting(lua_State* L) { + if (!CGGameUI::CanPerformAction(2)) { + lua_pushnil(L); + return 1; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_unit->m_unitFieldCharmedby) { + lua_pushnil(L); + return 1; + } + + if (OnCancelCombat()) { + lua_pushnumber(L, 1.0); + return 1; + } + + if (Spell_C_IsActivePlayerCasting()) { + Spell_C_StopCasting(); + lua_pushnumber(L, 1.0); + return 1; + } + + if (!Spell_C_GetAutoRepeatingSpell()) { + lua_pushnil(L); + return 1; + } + + Spell_C_CancelAutoRepeat(true); + lua_pushnumber(L, 1.0); + return 1; +} + // STATIC: 0x00AF51C8 static FrameScript_Method s_ScriptFunctions[] = { { "SpellIsTargeting", &Script_SpellIsTargeting }, @@ -77,3 +214,11 @@ void SpellRegisterScriptFunctions() { FrameScript_RegisterFunction(s_ScriptFunctions[i].m_name, s_ScriptFunctions[i].m_method); } } + +// VERIFY: 302aa8ec auto +// OFFSET: 0x007FDDE0 +void SpellUnregisterScriptFunctions() { + for (uint32_t i = 0; i < sizeof(s_ScriptFunctions) / sizeof(s_ScriptFunctions[0]); i++) { + FrameScript_UnregisterFunction(s_ScriptFunctions[i].m_name); + } +} diff --git a/WoW/Source/Magic/Spell.cpp b/WoW/Source/Magic/Spell.cpp new file mode 100644 index 0000000..87ff419 --- /dev/null +++ b/WoW/Source/Magic/Spell.cpp @@ -0,0 +1,128 @@ +#include "Spell.h" +#include +#include "Engine/Source/Tempest/C3Vector.h" + +// VERIFY: cbd89f17 auto +// OFFSET: 0x0076BD50 +bool Spell_IsAuraEffect(int32_t effect) { + switch (effect) { + case 6: + case 27: + case 35: + case 65: + case 119: + case 128: + case 129: + case 143: + return true; + + default: + return false; + } +} + +// VERIFY: 64431913 auto +// OFFSET: 0x0076BE10 +bool Spell_IsUnitAuraEffect(int32_t effect) { + switch (effect) { + case 6: + case 35: + case 65: + case 119: + case 128: + case 129: + case 143: + return true; + + default: + return false; + } +} + +// VERIFY: 0c750047 auto +// OFFSET: 0x0076BED0 +bool Spell_IsAreaAuraEffect(int32_t effect) { + switch (effect) { + case 27: + case 35: + case 65: + case 119: + case 128: + case 129: + case 143: + return true; + + default: + return false; + } +} + +// VERIFY: 7a1110db auto +// OFFSET: 0x0076BF80 +float SpellUtils_ComputeMissileTrajectoryTravelTime(float pitch, float speed, const C3Vector* delta, float gravity) { + bool hasGravity = fabs(gravity) > 0.0001f; + float horizontal = cos(pitch) * speed; + + if (horizontal > 0.0001f) { + return sqrt(delta->y * delta->y + delta->x * delta->x) / horizontal; + } + + if (speed <= 0.0001f) { + if (!hasGravity) { + return -1.0f; + } + } else if (!hasGravity) { + return fabs(delta->z) / speed; + } + + float vertical = speed * sin(pitch); + float discriminant = vertical * vertical - (delta->z * gravity + delta->z * gravity); + + if (discriminant < 0.0f) { + return -1.0f; + } + + float root = sqrt(discriminant); + float scale = -1.0f / gravity; + float first = (root - vertical) * scale; + float second = scale * (-vertical - root); + + if (first >= 0.0f && (second < 0.0f || first < second)) { + return first; + } + + return second; +} + +// VERIFY: 7fc1a99f auto +// OFFSET: 0x0076C070 +int32_t SpellUtils_ComputeMissileTrajectory(float pitch, const C3Vector* delta, float gravity, float* speed, float* time, C3Vector* velocity) { + float c = cos(pitch); + float s = sin(pitch); + float horizontal = sqrt(delta->y * delta->y + delta->x * delta->x); + + if (fabs(c) < 0.0001f || fabs(horizontal) < 0.0001f || fabs(gravity) < 0.0001f) { + return 1; + } + + float half = (1.0f / c * horizontal * s - delta->z) / gravity; + float squared = half + half; + + if (squared <= 0.01f) { + return 0; + } + + float t = sqrt(squared); + *time = t; + float v = 1.0f / c * (horizontal / t); + *speed = v; + + if (velocity) { + float inverse = 1.0f / horizontal; + velocity->x = v * delta->x * inverse * c; + velocity->y = c * (inverse * *speed) * delta->y; + velocity->z = s * *speed; + } + + return 2; +} diff --git a/WoW/Source/Magic/Spell.h b/WoW/Source/Magic/Spell.h new file mode 100644 index 0000000..51a4584 --- /dev/null +++ b/WoW/Source/Magic/Spell.h @@ -0,0 +1,15 @@ +#ifndef WOW_SOURCE_MAGIC_SPELL_H +#define WOW_SOURCE_MAGIC_SPELL_H + +#include +#include + +class C3Vector; + +bool Spell_IsAuraEffect(int32_t effect); +bool Spell_IsUnitAuraEffect(int32_t effect); +bool Spell_IsAreaAuraEffect(int32_t effect); +float SpellUtils_ComputeMissileTrajectoryTravelTime(float pitch, float speed, const C3Vector* delta, float gravity); +int32_t SpellUtils_ComputeMissileTrajectory(float pitch, const C3Vector* delta, float gravity, float* speed, float* time, C3Vector* velocity); + +#endif diff --git a/WoW/Source/Net/NetClient/NetClient.cpp b/WoW/Source/Net/NetClient/NetClient.cpp index 3ca116a..974273b 100644 --- a/WoW/Source/Net/NetClient/NetClient.cpp +++ b/WoW/Source/Net/NetClient/NetClient.cpp @@ -247,6 +247,12 @@ void NetClient::SetLoginData(LoginData* loginData) { memcpy(&this->m_loginData, loginData, sizeof(this->m_loginData)); } +// VERIFY: 10a620f0 auto +// OFFSET: 0x00631F90 +uint8_t* NetClient::GetSessionKey() { + return this->m_loginData.m_sessionKey; +} + // VERIFY: f1080d7c auto // OFFSET: 0x00631FA0 void NetClient::SetMessageHandler(NETMESSAGE msgId, MESSAGE_HANDLER handler, void* param) { diff --git a/WoW/Source/Object/Item.h b/WoW/Source/Object/Item.h index e1e6fb4..bed826b 100644 --- a/WoW/Source/Object/Item.h +++ b/WoW/Source/Object/Item.h @@ -21,6 +21,8 @@ class CGItem { virtual uint32_t GetItemStaticFlags(int32_t a1) = 0; int32_t IsUsable() const; + uint32_t GetEnchantmentId(int32_t slot); + uint32_t GetEnchantmentDuration(int32_t slot); uint32_t GetDurability() const; uint32_t GetMaxDurability() const; int32_t GetPetitionSignatures(); diff --git a/WoW/Source/Object/ObjectClient/AuraData.h b/WoW/Source/Object/ObjectClient/AuraData.h index ee3a34a..f569caa 100644 --- a/WoW/Source/Object/ObjectClient/AuraData.h +++ b/WoW/Source/Object/ObjectClient/AuraData.h @@ -25,8 +25,8 @@ class AuraData { class SortedAuraInfo { public: - /* 0000 */ uint32_t unk_0000; - /* 0004 */ uint32_t unk_0004; + /* 0000 */ uint32_t m_auraIndex; + /* 0004 */ int32_t m_spellId; }; #pragma pack(pop) diff --git a/WoW/Source/Object/ObjectClient/Bag_C.cpp b/WoW/Source/Object/ObjectClient/Bag_C.cpp index 55630c9..a20fb35 100644 --- a/WoW/Source/Object/ObjectClient/Bag_C.cpp +++ b/WoW/Source/Object/ObjectClient/Bag_C.cpp @@ -5,6 +5,8 @@ #include "WoW/Source/Object/ObjectClient/Item_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/CGBankInfo.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/Types.h" // STATIC: 0x00A37B10 static const BAGSLOTRANGE s_bagSlotRanges[8] = { { 23, 38 }, { 19, 22 }, { 86, 117 }, { 39, 66 }, { 67, 73 }, { 118, 149 }, { 0, 18 }, { 74, 85 } }; @@ -321,3 +323,140 @@ uint64_t CGBag_C::GetItemGuid(uint32_t slot) const { return 0; } + +// VERIFY: cfc4d837 auto +// OFFSET: 0x00754CD0 +CGItem_C* CGBag_C::FindItem(int32_t (*callback)(const CGItem_C* item, void* param), void* param, uint32_t flags) { + WOWGUID container; + return this->FindItem(callback, param, container, flags, flags); +} + +// VERIFY: 35fbcc70 manual +// OFFSET: 0x007546F0 +CGItem_C* CGBag_C::FindItem(int32_t (*callback)(const CGItem_C* item, void* param), void* param, WOWGUID& container, uint32_t& slot, uint32_t flags) { + if (this->m_hasBank && !(flags & 0x247)) { + flags |= 0x247; + } + + container = WOWGUID(); + slot = 0; + uint32_t numSlots = this->m_numSlots; + CGItem_C* best = nullptr; + uint32_t index = this->m_hasBank ? 23 : 0; + + if (index >= numSlots) { + return best; + } + + while (true) { + if (!this->m_hasBank || SlotMatchesSearchFlags(index, flags)) { + WOWGUID guid = index < numSlots ? this->m_slots[index] : WOWGUID(); + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (item && !(item->m_modelFlags & 0x10000) && ((flags & 0x80) || (((item->m_item->m_itemFieldFlags & 0x8) || !item->m_item->m_itemFieldMaxdurability || item->m_item->m_itemFieldDurability) && !(item->m_item->m_itemFieldFlags & 0x10))) && (!(flags & 0x20) || (item->GetBag() && !(flags & 0x10)) || (item->GetEnchantmentSpell(0) && item->GetCurrentSpellCharges()))) { + if (callback(item, param)) { + container = this->m_guid; + slot = index; + } else if (item->GetBag() && !(flags & 0x10)) { + item = item->GetBag()->FindItem(callback, param, container, slot, flags); + } else { + item = nullptr; + } + + if (item) { + if (!(flags & 0x100)) { + return item; + } + + if (!best || item->m_item->m_itemFieldStackCount < best->m_item->m_itemFieldStackCount) { + best = item; + } + } + } + } + + numSlots = this->m_numSlots; + + if (index >= numSlots) { + index = numSlots; + } else if (this->m_hasBank) { + uint32_t range = 0; + + while (s_bagSlotRanges[range].m_last != index) { + if (++range >= 8) { + break; + } + } + + if (range >= 8) { + index++; + } else if (range >= 7) { + index = numSlots; + } else { + index = s_bagSlotRanges[range + 1].m_first; + } + } else { + index++; + } + + if (index >= numSlots) { + return best; + } + } +} + +// VERIFY: 82130edd auto +// OFFSET: 0x00754590 +int32_t GetItemLimitCategoryCallback(const CGItem_C* item, void* param) { + int32_t* data = static_cast(param); + + if (item && item->GetStats() && static_cast(item->GetStats()->m_itemLimitCategory) == data[0]) { + data[1] += item->m_item->m_itemFieldStackCount; + } + + return 0; +} + +// VERIFY: 2670f6b3 auto +// OFFSET: 0x00754DD0 +bool CGBag_C::ItemCountValid(int32_t itemId, const ItemStats_C* stats, int32_t count, bool showError) { + if (stats->m_maxCount) { + int32_t current; + + if (itemId == -2) { + current = this->GetNumFreeInvSlots(); + } else { + int32_t data[2] = { itemId, 0 }; + WOWGUID container; + uint32_t slot; + this->FindItem(GetItemTypeCountCallback, data, container, slot, 79); + current = data[1]; + } + + if (count + current > static_cast(stats->m_maxCount)) { + if (showError) { + CGGameUI::DisplayError(ERR_ITEM_MAX_COUNT); + } + + return false; + } + } + + if (stats->m_itemLimitCategory) { + ItemLimitCategoryRec* category = g_itemLimitCategoryDB.GetRecord(stats->m_itemLimitCategory); + int32_t data[2] = { static_cast(stats->m_itemLimitCategory), 0 }; + WOWGUID container; + uint32_t slot; + this->FindItem(GetItemLimitCategoryCallback, data, container, slot, 79); + + if (count + data[1] > category->m_quantity) { + if (showError) { + CGGameUI::DisplayError(ERR_ITEM_MAX_LIMIT_CATEGORY_COUNT_EXCEEDED_IS, category->m_quantity, category->m_name); + } + + return false; + } + } + + return true; +} diff --git a/WoW/Source/Object/ObjectClient/Bag_C.h b/WoW/Source/Object/ObjectClient/Bag_C.h index ca6d20d..e53d580 100644 --- a/WoW/Source/Object/ObjectClient/Bag_C.h +++ b/WoW/Source/Object/ObjectClient/Bag_C.h @@ -17,6 +17,8 @@ struct ItemTypeCountParam { /* 0004 */ int32_t m_count; }; +class ItemStats_C; + class CGBag_C { public: /* 0000 */ int32_t m_numSlots; @@ -44,11 +46,14 @@ class CGBag_C { CGItem_C* FindItemOfType(int32_t itemId, WOWGUID& container, uint32_t& slot, uint32_t flags); int32_t GetItemTypeCount(int32_t itemId, uint32_t flags); int32_t GetItemTypeCharges(int32_t itemId, uint32_t flags); + bool ItemCountValid(int32_t itemId, const ItemStats_C* stats, int32_t count, bool showError); }; int32_t GetItemTypeCountCallback(const CGItem_C* item, void* param); int32_t GetItemTypeChargesCallback(const CGItem_C* item, void* param); int32_t FindItemIDCallback(const CGItem_C* item, void* param); int32_t FindItemClassCallback(const CGItem_C* item, void* param); +int32_t GetItemLimitCategoryCallback(const CGItem_C* item, void* param); +int32_t GetDisplayErrorByInventoryError(int32_t error); #endif diff --git a/WoW/Source/Object/ObjectClient/Effect_C.cpp b/WoW/Source/Object/ObjectClient/Effect_C.cpp index 7033fa8..091a655 100644 --- a/WoW/Source/Object/ObjectClient/Effect_C.cpp +++ b/WoW/Source/Object/ObjectClient/Effect_C.cpp @@ -8,6 +8,26 @@ #include "Engine/Source/Services/ParticleSystem2.h" #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/Object/ObjectClient/Object_C.h" +#include "WoW/Source/WorldClient/World.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/DB/Rec/SpellVisualEffectNameRec.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "WoW/Source/DB/Rec/SpellVisualKitRec.h" +#include "WoW/Source/Magic/MagicClient/SpellVisuals.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Common/ComponentCore/CharacterComponent.h" +#include "WoW/Source/WorldClient/FrameTime.h" +#include "Engine/Source/Tempest/C44Matrix.h" +#include "Engine/Source/Tempest/CMath.h" +#include "Engine/Source/Tempest/CAaBox.h" +#include "WoW/Source/Object/ObjectClient/Movement_C.h" +#include "WoW/Source/WorldClient/Map.h" +#include "WoW/Source/DB/Rec/CreatureModelDataRec.h" +#include "WoW/Source/DB/Rec/SpellVisualKitModelAttachRec.h" +#include "WoW/Source/Ui/WorldFrame.h" +#include "WoW/Source/DB/Rec/SpellRec.h" // STATIC: 0x00ADA764 static const char* s_specialUnitEffectNames[] = { @@ -229,7 +249,7 @@ void CEffect::AddFishingLine(CGObject_C* object, const WOWGUID& target) { this->m_targetGuid = target; } -// VERIFY: e993f4c6 manual +// VERIFY: d3ed0a31 manual // OFFSET: 0x006F9D70 CEffect::CEffect() { this->m_attachmentId = -1; @@ -241,29 +261,28 @@ CEffect::CEffect() { this->m_kitRec = nullptr; this->m_effectNameRec = nullptr; this->m_flags = 0; - this->unk_004C = 0; - this->unk_0050 = 0; - this->unk_0054 = 0; - this->unk_0058 = 0; - this->unk_005C = 0; - this->unk_0060 = 0; - this->unk_0064 = 0; - this->unk_0068 = 0; - this->unk_006C = 0; - this->unk_0070 = 0; - this->unk_0074 = 0; - this->unk_0078 = 0; + this->m_lightning[0] = nullptr; + this->m_lightning[1] = nullptr; + this->m_lightning[2] = nullptr; + this->m_lightning[3] = nullptr; + this->m_lightning[4] = nullptr; + this->m_lightning[5] = nullptr; + this->m_lightning[6] = nullptr; + this->m_lightning[7] = nullptr; + this->m_lightning[8] = nullptr; + this->m_lightning[9] = nullptr; + this->m_lightning[10] = nullptr; + this->m_lightning[11] = nullptr; this->unk_0080 = 0; this->unk_0084 = 0; - this->unk_0088 = 0.0f; + this->m_facing = 0.0f; this->unk_008C = -1; - this->unk_0090 = 0; - this->unk_0094 = 0; - this->unk_0098 = 0; - this->unk_009C = 12; + this->m_mountTransition = nullptr; + this->m_pendingCacheId = 0; + this->m_displayId = 0; + this->m_itemSlot = 12; this->unk_00A0 = 0; - this->unk_00C0 = 0; - this->unk_00C4 = 0; + this->m_transportGuid = WOWGUID(); this->unk_00C8 = 0; this->unk_00CC = 0; this->unk_00D0 = 0; @@ -273,7 +292,7 @@ CEffect::CEffect() { this->unk_00E0 = 0.0f; this->unk_00E4 = 0.0f; this->unk_00E8 = 0.0f; - this->unk_00F0 = 0; + this->m_mapEntity = nullptr; this->m_refCount = 1; this->unk_00F8 = 0; this->m_lightningState = 0; @@ -295,3 +314,1089 @@ void CEffect::Release() { delete this; } } + +// VERIFY: 07c58fd0 manual +// OFFSET: 0x006F7C40 +void CEffect::InitFromUnit(C3Vector position, uint32_t time, int32_t spellId, const SpellVisualKitRec* kit, const SpellVisualEffectNameRec* effectName, const WOWGUID* guid, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), uint32_t a9, const SpellVisualKitModelAttachRec* attach, WOWGUID transport) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + this->m_effectNameRec = effectName; + this->m_sourceGuid = *guid; + this->m_position = position; + this->m_flags = flags | 0x8002; + this->m_transportGuid = transport; + this->m_kitRec = kit; + this->m_spellId = spellId; + this->unk_00C8 = time; + this->unk_00A0 = a9; + this->m_facing = unit->GetSmoothFacing(); + this->m_attachRec = attach; + this->m_model = World::s_m2Scene->CreateModel(this->m_effectNameRec->m_fileName, 0); + + if (this->m_model) { + this->m_refCount++; + this->m_model->SetLoadedCallback(&CEffect::CreateModelFromEffect, this); + this->m_model->SetSequenceCallback(reinterpret_cast(callback), reinterpret_cast(this)); + this->m_model->SetEventCallback(reinterpret_cast(&CEffect::EffectEvent), reinterpret_cast(this)); + + if (this->m_flags & 0x400000) { + this->SetEmissionRateIgnoresDistance(1); + } + } + + this->LinkTo(&unit->m_effectList); +} + +// VERIFY: 2e373253 auto +// OFFSET: 0x006F7680 +void CEffect::CreateModelFromEffect(CM2Model* model, void* arg) { + CEffect* effect = static_cast(arg); + + if (effect->m_flags & 0x400000) { + effect->SetEmissionRateIgnoresDistance(1); + } + + model->SetBoneSequence(0xFFFFFFFF, 0, 0xFFFFFFFF, 0, 1.0f, 1, 1); +} + +// VERIFY: 392d7fa2 manual +// OFFSET: 0x006F7B00 +void CEffect::EffectEvent(CM2Model* model, uint32_t boneId, uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time, uint64_t param) { + CEffect* effect = reinterpret_cast(static_cast(param)); + CGUnit_C* object = static_cast(ClntObjMgrObjectPtr(effect->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__)); + + if (!object) { + return; + } + + if (eventId == 0x444E5324) { + if ((object->m_obj->m_type & 0x8) && object->IsActiveMover()) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + + int32_t listenerAtCharacter = s_listenerAtCharacter->m_intValue; + + if (listenerAtCharacter) { + properties.m_volumeScale = 0.64999998f; + } + + properties.m_priority = 110; + SI2::PlaySoundKit(data, listenerAtCharacter ? nullptr : position, &effect->m_soundKitObject, &properties, 0, nullptr, 1, 0); + } else { + SI2::PlaySoundKit(data, position, &effect->m_soundKitObject, nullptr, 0, nullptr, 1, 0); + } + + if (!(effect->m_flags & 0x200000)) { + SI2::AttachToObject(&effect->m_soundKitObject, object->m_obj->m_guid); + } + } else if (eventId == 0x54494824 && (object->m_obj->m_type & 0x8)) { + object->PlayWoundAnimKit(0); + } +} + +// VERIFY: ac84d6f6 manual +// OFFSET: 0x006F94C0 +void CEffect::AddEffect(int32_t attachType, int32_t spellId, const SpellVisualKitRec* kit, const SpellVisualEffectNameRec* effectName, const WOWGUID* target, const WOWGUID* source, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), const C3Vector* position, uint32_t a10, const SpellVisualKitModelAttachRec* attach) { + CGObject_C* object = static_cast(ClntObjMgrObjectPtr(*source, TYPEMASK_OBJECT, __FILE__, __LINE__)); + + if (!object) { + return; + } + + this->m_effectNameRec = effectName; + CEffect::DestroyMatchingEffects(object, effectName, attachType, spellId, kit ? kit->m_id : 0, attach); + + if (attachType == -1) { + DebugLog("**** CEffect::AddEffect called with ATTACH_NONE\n"); + } + + this->m_attachmentId = attachType; + this->m_sourceGuid = *target; + this->m_targetGuid = *source; + this->m_kitRec = kit; + this->unk_00A0 = a10; + this->m_attachRec = attach; + this->m_spellId = spellId; + this->m_effectNameRec = effectName; + this->m_flags = flags; + + if (position) { + this->m_offset = *position; + this->m_flags = flags | 0x10000; + } + + this->m_model = World::s_m2Scene->CreateModel(effectName->m_fileName, 0); + + if (this->m_model) { + this->m_refCount++; + this->m_model->SetLoadedCallback(&CEffect::CreateModelFromEffect, this); + this->m_model->SetSequenceCallback(reinterpret_cast(callback), reinterpret_cast(this)); + this->m_model->SetEventCallback(reinterpret_cast(&CEffect::EffectEvent), reinterpret_cast(this)); + + if (this->m_flags & 0x400000) { + this->SetEmissionRateIgnoresDistance(1); + } + } + + this->LinkTo(&object->m_effectList); +} + +// VERIFY: 2eb5c934 auto +// OFFSET: 0x006F8A60 +void __stdcall CEffect::DestroyMatchingEffects(CGObject_C* object, const SpellVisualEffectNameRec* effectName, int32_t attachType, int32_t spellId, int32_t kitId, const SpellVisualKitModelAttachRec* attach) { + if (attachType == -1) { + return; + } + + CEffect* effect = object->m_effectList; + + while (effect) { + CEffect* next = effect->m_next; + + if (effect->m_effectNameRec && effect->m_effectNameRec->m_id == effectName->m_id && (!effect->m_kitRec || effect->m_kitRec->m_id == kitId) && (!effect->m_attachRec || effect->m_attachRec == attach) && (!spellId || effect->m_spellId == static_cast(spellId)) && effect->m_attachmentId == attachType) { + effect->MoveToDestroyList(); + } + + effect = next; + } +} + +// VERIFY: 579c63d5 manual +// OFFSET: 0x006F7E40 +void CEffect::AddSoundEffect(int32_t soundId, int32_t a2, int32_t spellId, const C3Vector* position, CGObject_C* object, uint32_t a6) { + if (!object) { + return; + } + + this->LinkTo(&object->m_effectList); + this->m_refCount++; + this->unk_00CC = a2; + this->m_spellId = spellId; + this->m_sourceGuid = object->m_obj->m_guid; + this->unk_00A0 = a6; + + const C3Vector* soundPosition = position; + + if (position) { + this->m_position = *position; + } else { + this->m_position = object->GetPosition(); + soundPosition = &this->m_position; + } + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (this->m_flags & 0x1) { + properties.m_loopMode = 1; + properties.m_noRandomStart = 1; + } else { + properties.m_maxAudibleBehavior = 0; + properties.m_loopMode = 2; + + if (CGUnit_C::s_activeMover == this->m_sourceGuid) { + properties.m_priority = 110; + } + } + + SI2::PlaySoundKit(soundId, soundPosition, &this->m_soundKitObject, &properties, 0, nullptr, 1, 0); + + if (!(this->m_flags & 0x200000)) { + SI2::AttachToObject(&this->m_soundKitObject, object->m_obj->m_guid); + } + + this->m_flags |= 0x100800; +} + +// VERIFY: 561572d5 manual +// OFFSET: 0x006F7FD0 +void CEffect::AddAnimKitEffect(int32_t spellId, const SpellVisualKitRec* kit, const WOWGUID* guid, uint32_t flags, uint32_t a5) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + this->LinkTo(&unit->m_effectList); + this->m_refCount++; + this->m_spellId = spellId; + this->m_sourceGuid = *guid; + this->m_flags |= flags | 0x800; + this->m_kitRec = kit; + this->unk_00A0 = a5; +} + +// STATIC: 0x00A32AF4 +static const int32_t s_specialUnitEffectAttachments[] = { 50, 50, 17, 17, 19, 19, 19, 17, 19, 19, 34, 19 }; + +// VERIFY: e6c5c900 manual +// OFFSET: 0x006F9260 +void CEffect::AddSpecialEffect(int32_t type, const WOWGUID& target, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit || static_cast(type) >= 12) { + return; + } + + int32_t attachment = s_specialUnitEffectAttachments[type]; + + if (attachment == 50 || !unit->m_worldModel) { + return; + } + + this->m_sourceGuid = target; + this->m_targetGuid = target; + this->m_flags = 0; + this->m_attachmentId = attachment; + + if (unit->m_worldModel->IsLoaded(0, 0) && !unit->m_worldModel->HasAttachment(this->m_attachmentId)) { + this->m_attachmentId = 19; + } + + this->m_effectNameRec = g_spellVisualEffectNameDB.GetRecord(s_specialUnitEffectIDs[type]); + CEffect::DestroyMatchingEffects(unit, this->m_effectNameRec, attachment, 0, 0, nullptr); + this->m_model = World::s_m2Scene->CreateModel(this->m_effectNameRec->m_fileName, 0); + + if (this->m_model) { + this->m_refCount++; + this->m_model->SetLoadedCallback(&CEffect::CreateModelFromEffect, this); + this->m_model->SetSequenceCallback(reinterpret_cast(callback), reinterpret_cast(this)); + this->m_model->SetEventCallback(reinterpret_cast(&CEffect::EffectEvent), reinterpret_cast(this)); + } + + this->LinkTo(&unit->m_effectList); +} + +// VERIFY: 3f5d1803 manual +// OFFSET: 0x006F93A0 +void CEffect::AddSpecialByPosition(int32_t type, C3Vector position, const WOWGUID* guid, uint32_t flags, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + this->m_sourceGuid = *guid; + this->m_position.x = position.x; + this->m_flags = flags | 2; + this->m_position.y = position.y; + this->m_position.z = position.z; + this->m_transportGuid = WOWGUID(); + this->m_effectNameRec = g_spellVisualEffectNameDB.GetRecord(s_specialUnitEffectIDs[type]); + this->m_model = World::s_m2Scene->CreateModel(this->m_effectNameRec->m_fileName, 0); + + if (this->m_model) { + this->m_refCount++; + this->m_model->SetLoadedCallback(&CEffect::CreateModelFromEffect, this); + this->m_model->SetSequenceCallback(reinterpret_cast(callback), reinterpret_cast(this)); + this->m_model->SetEventCallback(reinterpret_cast(&CEffect::EffectEvent), reinterpret_cast(this)); + + if (this->m_flags & 0x400000) { + this->SetEmissionRateIgnoresDistance(1); + } + } + + this->LinkTo(&unit->m_effectList); +} + +// VERIFY: 097c23de auto +// OFFSET: 0x006F74F0 +void CEffect::ClearLightning() { + for (uint32_t i = 0; i < sizeof(this->m_lightning) / sizeof(this->m_lightning[0]); i++) { + if (this->m_lightning[i]) { + LightningObjectReleaseRef(this->m_lightning[i]); + } + + this->m_lightning[i] = nullptr; + } +} + +// VERIFY: 4c42526f auto +// OFFSET: 0x006F8600 +void CEffect::ApplyItemVisualByItemId(int32_t id, const WOWGUID& guid, void* param, bool success) { + ItemRec* item = g_itemDB.GetRecord(id); + + if (!item) { + return; + } + + CEffect* effect = static_cast(param); + effect->m_itemSlot = CCharacterComponent::GetItemSlotForInvType(static_cast(item->m_inventoryType)); + effect->m_displayId = item->m_displayInfoID; + effect->ApplyItemVisual(); +} + +// VERIFY: 57136c38 manual +// OFFSET: 0x006F8700 +void CEffect::ClearItemVisualEffect() { + if (!(this->m_flags & 0x80000)) { + return; + } + + if (this->m_itemSlot < 12) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (unit->m_characterComponent) { + unit->m_characterComponent->RemoveItem(static_cast(this->m_itemSlot)); + unit->RefreshComponentItem(this->m_itemSlot); + CGGameUI::UnitModelUpdate(this->m_sourceGuid, 3); + } + + this->m_itemSlot = 12; + } + } + + if (this->m_pendingCacheId) { + g_itemDBCache.CancelCallback(this->m_pendingCacheId, CEffect::ApplyItemVisualByItemId, nullptr); + this->m_pendingCacheId = 0; + } + + this->m_flags &= 0x80000; + this->m_itemSlot = 12; +} + +// VERIFY: 899e5338 manual +// OFFSET: 0x006F87C0 +void CEffect::MoveToDestroyList() { + this->LinkTo(&s_destroyedEffects); + this->m_flags |= 0x900; + + if (this->m_flags & 0x4) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (this->unk_00D8 && unit->m_mountModel) { + unit->m_mountModel->m_lastAnimTime = 0; + this->unk_00D8 = 0; + } + + if (this->unk_00D4 && unit->m_worldModel) { + unit->m_worldModel->m_lastAnimTime = 0; + this->unk_00D4 = 0; + } + + unit->UpdateBaseAnimation(0, -1); + } + } + + if (SI2::IsLooping(&this->m_soundKitObject)) { + SI2::StopSound(&this->m_soundKitObject, 0, 0.15000001f, 1); + } else { + SI2::Detach(&this->m_soundKitObject); + } + + if (this->m_mountTransition) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (SpellVisualsIsMountTransitionFinished(this->m_mountTransition)) { + unit->CompleteMountTransition(); + } else { + unit->StopMountTransition(); + } + + unit->UpdateBaseAnimation(0, -1); + } + + SpellVisualsCancelMountTransition(this->m_mountTransition); + this->m_mountTransition = nullptr; + } + + if (this->m_model) { + this->m_model->SetSequenceCallback(nullptr, 0); + this->m_model->SetEventCallback(nullptr, 0); + this->m_model->SetLoadedCallback(nullptr, nullptr); + CM2Model* model = this->m_model; + + if (model->m_attachParent) { + model->m_fFlags &= ~0x80u; + } else { + model->m_fFlags &= ~0x8u; + } + + if (model->m_attachParent) { + model->m_fFlags &= ~0x20000u; + } else { + model->m_fFlags &= ~0x10000u; + } + + if (this->m_model->m_attachParent) { + this->m_model->m_fFlags |= 0x20000; + } else { + this->m_model->m_fFlags |= 0x10000; + } + + this->m_model->SetEmittersEnabled(0); + } + + this->ClearItemVisualEffect(); + this->ClearLightning(); + + if (!this->m_prevLink) { + this->m_refCount++; + } +} + +// VERIFY: 7b7099ce manual +// OFFSET: 0x006F9EC0 +CEffect::~CEffect() { + if (this->m_model) { + if (this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + this->m_model->SetSequenceCallback(nullptr, 0); + this->m_model->SetEventCallback(nullptr, 0); + this->m_model->SetLoadedCallback(nullptr, nullptr); + CM2Model* model = this->m_model; + + if (model->m_attachParent) { + model->m_fFlags &= ~0x80u; + } else { + model->m_fFlags &= ~0x8u; + } + + if (model->m_attachParent) { + model->m_fFlags &= ~0x20000u; + } else { + model->m_fFlags &= ~0x10000u; + } + + this->m_model->Release(); + this->m_model = nullptr; + } + + if (this->m_lineModel) { + this->m_lineModel->m_fFlags |= 0x20; + this->m_lineModel->m_drawCallback = nullptr; + this->m_lineModel->m_drawArg = nullptr; + this->m_lineModel->Release(); + } + + this->UnLinkSelf(); + + if (this->m_mapEntity) { + World::ObjectDestroy(this->m_mapEntity); + } + + if (SI2::IsLooping(&this->m_soundKitObject)) { + SI2::StopSound(&this->m_soundKitObject, 0, 0.15000001f, 1); + } else { + SI2::Detach(&this->m_soundKitObject); + } + + if (this->m_mountTransition) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->StopMountTransition(); + unit->UpdateBaseAnimation(0, -1); + } + + SpellVisualsCancelMountTransition(this->m_mountTransition); + this->m_mountTransition = nullptr; + + if (this->m_pendingCacheId) { + g_creatureDBCache.CancelCallback(this->m_pendingCacheId, CEffect::MountTransitionCacheCB, this); + this->m_pendingCacheId = 0; + } + } + + this->ClearItemVisualEffect(); + this->ClearLightning(); +} + +// VERIFY: 2377a38a manual +// OFFSET: 0x006FA450 +void CEffect::CleanUpStaticLists() { + uint32_t now = FrameTime::s_curTimeMs; + CEffect* effect = s_orphanedEffects; + + while (effect) { + CEffect* next = effect->m_next; + + if (!effect->unk_00C8 || static_cast(now - effect->unk_00C8) > 0) { + effect->EffectUpdate(); + } + + if (effect->unk_00CC && static_cast(now - effect->unk_00CC) > 0) { + effect->UnLinkSelf(); + + if (effect->m_refCount-- == 1) { + delete effect; + } + } + + effect = next; + } + + effect = s_destroyedEffects; + + while (effect) { + CEffect* next = effect->m_next; + + if (!effect->m_model || !(effect->m_model->m_fFlags & 0x400)) { + effect->UnLinkSelf(); + + if (effect->m_refCount-- == 1) { + delete effect; + } + } + + effect = next; + } +} + +// VERIFY: f8d5c444 manual +// OFFSET: 0x006FA5B0 +void CEffect::AddLootEffect(CGUnit_C* unit, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)) { + this->m_sourceGuid = unit->m_obj->m_guid; + this->m_flags = 0x8; + this->m_attachmentId = 19; + const SpellVisualEffectNameRec* effectName = GetSpecialSpellVisualEffectNameRec(4); + this->m_effectNameRec = effectName; + this->m_model = World::s_m2Scene->CreateModel(effectName->m_fileName, 0); + + if (!this->m_model) { + delete this; + return; + } + + if (this->m_flags & 0x400000) { + this->SetEmissionRateIgnoresDistance(1); + } + + this->m_model->SetLoadedCallback(&CEffect::CreateModelFromEffect, this); + this->m_model->SetSequenceCallback(reinterpret_cast(callback), reinterpret_cast(this)); + this->m_model->SetEventCallback(reinterpret_cast(&CEffect::EffectEvent), reinterpret_cast(this)); + this->LinkTo(&unit->m_effectList); + this->m_refCount++; +} + +// VERIFY: 7e81c241 manual +// OFFSET: 0x006F7720 +C3Vector CEffect::TransformPositionByTransport() { + if (!this->m_transportGuid) { + return this->m_position; + } + + C44Matrix transport; + + if (MovementGetTransportMtxSafe(this->m_transportGuid, &transport)) { + this->m_worldPosition = this->m_position * transport; + return this->m_worldPosition; + } + + this->m_position = this->m_worldPosition; + this->m_transportGuid = WOWGUID(); + return this->m_worldPosition; +} + +// VERIFY: f3d1c304 manual +// OFFSET: 0x006F7950 +float __stdcall CEffect::ComputeModelScaleFromTarget(CGObject_C* object) { + CM2Model* model = object->GetObjectModel(); + + if (model && !model->IsLoaded(0, 1)) { + return 1.0f; + } + + float scale = 1.0f; + + if (object->m_obj->m_type & TYPEMASK_UNIT) { + CreatureModelDataRec* modelData = static_cast(object)->GetModelData(); + + if (modelData) { + scale = modelData->m_worldEffectScale; + } + } + + CAaBox box = model->GetBoundingBox(); + float size = box.t.x - box.b.x; + float depth = box.t.y - box.b.y; + + if (depth <= size) { + size = depth; + } + + size *= 0.30000001f; + + if (size <= 1.0f) { + return 1.0f * scale; + } + + return size * scale; +} + +// VERIFY: bf2f00fc manual +// OFFSET: 0x006F84F0 +void CEffect::ApplyModelAttachRecToMatrix(const SpellVisualKitModelAttachRec* attach, C44Matrix& matrix, float facing) { + float x = matrix.d0; + float y = matrix.d1; + float z = matrix.d2; + matrix.d0 = 0.0f; + matrix.d1 = 0.0f; + matrix.d2 = 0.0f; + + if (0.0f != attach->m_yaw) { + matrix.RotateAroundZ(-attach->m_yaw); + } + + if (0.0f != attach->m_pitch) { + matrix.RotateAroundY(attach->m_pitch); + } + + if (0.0f != attach->m_roll) { + matrix.RotateAroundX(attach->m_roll); + } + + if (facing == 0.0f) { + matrix.d0 = attach->m_offset[0] + x; + matrix.d1 = y - attach->m_offset[1]; + } else { + float s; + float c; + CMath::sincos_(facing - 1.5707964f, &s, &c); + matrix.d0 = c * attach->m_offset[1] + x - attach->m_offset[0] * s; + matrix.d1 = c * attach->m_offset[0] + s * attach->m_offset[1] + y; + } + + matrix.d2 = attach->m_offset[2] + z; +} + +// VERIFY: 9308087b manual +// OFFSET: 0x006F8AE0 +C44Matrix* CEffect::TransformPosition(C44Matrix* matrix, CGObject_C* object) { + *matrix = C44Matrix(); + C3Vector position = this->TransformPositionByTransport(); + matrix->d0 = position.x; + matrix->d1 = position.y; + matrix->d2 = position.z; + float facing = 0.0f; + + if (object) { + if (object->m_obj->m_type & TYPEMASK_UNIT) { + facing = static_cast(object)->GetSmoothFacing(); + } else { + facing = object->GetFacing(); + } + } + + if (this->m_flags & 0x8000) { + matrix->RotateAroundZ(this->m_facing); + } else if (object) { + matrix->RotateAroundZ(facing); + } + + float scale = 1.0f; + + if ((this->m_flags & 0x200) && object) { + float targetScale = CEffect::ComputeModelScaleFromTarget(object); + scale = object->GetTrueScale() * targetScale; + } + + if (this->m_effectNameRec) { + float minScale = this->m_effectNameRec->m_minAllowedScale; + float effectScale = scale * this->m_effectNameRec->m_scale; + scale = this->m_effectNameRec->m_maxAllowedScale; + + if (effectScale < minScale) { + scale = minScale; + } else if (effectScale < scale) { + scale = effectScale; + } + } + + if (scale <= 0.0f) { + scale = 1.0f; + } + + matrix->Scale(scale); + + if (this->m_attachRec) { + CEffect::ApplyModelAttachRecToMatrix(this->m_attachRec, *matrix, (this->m_flags & 0x8000) ? this->m_facing : facing); + } + + return matrix; +} + +// VERIFY: 03a1abb4 manual +// OFFSET: 0x006F8C50 +int32_t CEffect::UpdateAttachment() { + if (this->m_attachmentId == -1) { + if (this->m_model && this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + return 1; + } + + CGObject_C* object; + + if (this->m_targetGuid) { + object = ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + } else if (this->m_sourceGuid) { + object = ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + } else { + object = nullptr; + } + + if (!object) { + if (this->m_model && this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + return 0; + } + + CM2Model* parent = object->m_worldModel; + + if (parent && !parent->IsLoaded(0, 0)) { + DebugLog("**** CEffect::UpdateAttachment() called before %s finished loading\n", parent->m_shared->m_fileNameWithoutPath); + + if (this->m_model && this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + this->MoveToDestroyList(); + return 0; + } + + CreatureModelDataRec* modelData = (object->m_obj->m_type & TYPEMASK_UNIT) ? static_cast(object)->GetModelData() : nullptr; + + if ((this->m_attachmentId == 2 || this->m_attachmentId == 1) && modelData) { + CreatureModelDataRec* data = static_cast(object)->GetModelData(); + + if (data && (data->m_flags & 0x10)) { + this->DetachFromParent(); + return 0; + } + } + + if (!parent || !parent->HasAttachment(this->m_attachmentId)) { + if (this->m_model && this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + this->MoveToDestroyList(); + return 0; + } + + float scale = 1.0f; + + if (modelData) { + scale = modelData->m_attachedEffectScale; + } + + if (this->m_effectNameRec) { + scale *= this->m_effectNameRec->m_scale; + float effectScale = scale; + float worldScale = parent->GetAttachmentWorldScale(this->m_attachmentId) * scale; + + if (worldScale > 0.000001f) { + if (this->m_effectNameRec->m_maxAllowedScale < worldScale) { + scale = effectScale / worldScale * this->m_effectNameRec->m_maxAllowedScale; + } else if (this->m_effectNameRec->m_minAllowedScale > worldScale) { + scale = this->m_effectNameRec->m_minAllowedScale / worldScale * effectScale; + } + } + } + + if (this->m_model && (1.0f != scale || this->m_attachRec)) { + C44Matrix transform; + + if (this->m_attachRec) { + CEffect::ApplyModelAttachRecToMatrix(this->m_attachRec, transform, 0.0f); + } + + transform.Scale(scale); + this->m_model->SetWorldTransform(transform); + } + + if (this->m_flags & 0x10000) { + if (this->m_model && (this->m_model->m_attachParent != parent || this->m_model->m_attachmentId != static_cast(this->m_attachmentId))) { + this->DetachFromParent(); + this->m_model->AttachToParent(parent, this->m_attachmentId, &this->m_offset, 0); + } + + this->m_position = this->m_offset; + } else { + if (this->m_model && (this->m_model->m_attachParent != parent || this->m_model->m_attachmentId != static_cast(this->m_attachmentId))) { + this->DetachFromParent(); + this->m_model->AttachToParent(parent, this->m_attachmentId, nullptr, 0); + } + + this->m_position = parent->GetAttachmentPosition(this->m_attachmentId); + } + + this->m_transportGuid = WOWGUID(); + + if (this->m_flags & 0x2000000) { + this->m_model->m_fFlags |= 0x100000; + } + + object->SetBoundsDirty(); + return 1; +} + +// VERIFY: 1bc858d5 manual +// OFFSET: 0x006FA050 +void CEffect::EffectUpdate() { + if (!(this->m_flags & 0x900)) { + this->PostInitialize(); + } + + if ((this->m_flags & 0x40000) && this->m_lightningState > 0 && !--this->m_lightningState && this->m_model) { + this->m_model->unk_017C = 0.0f; + this->m_model->SetEmittersEnabled(0); + this->m_model->SetRibbonsEnabled(0); + } + + if ((this->m_flags & 0x4000) || ((this->m_flags & 0x2) && this->m_transportGuid)) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && this->m_mapEntity && this->m_model) { + if (this->m_flags & 0x4000) { + this->m_position = unit->GetRawPosition(); + + if (unit->m_movement->m_flags & 0x40000000) { + this->m_position.z -= unit->m_unit->m_unitFieldHoverheight; + } + + this->m_transportGuid.m_guid = unit->GetTransportGUID(); + } + + C44Matrix transform; + this->TransformPosition(&transform, unit); + CAaBox box; + CAaSphere sphere; + C3Vector light; + + if (this->m_model->IsLoaded(0, 0)) { + box = this->m_model->GetBoundingBox(); + sphere = this->m_model->GetBoundingSphere(); + light = sphere.c; + } + + light.z = 1.0f; + this->m_model->m_fFlags |= 0x8000; + this->m_model->m_worldTransform = transform; + C44Matrix world = this->m_model->m_worldTransform; + CMap::ObjectUpdate(this->m_mapEntity, world, box, sphere, light, false, 0xFFFFFFFF); + } + } + + if ((this->m_flags & 0x4) && this->unk_00CC && static_cast(FrameTime::s_curTimeMs - this->unk_00CC) > 0) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + if (this->unk_00D8 && unit->m_mountModel) { + unit->m_mountModel->m_lastAnimTime = 0; + this->unk_00D8 = 0; + } + + if (this->unk_00D4 && unit->m_worldModel) { + unit->m_worldModel->m_lastAnimTime = 0; + this->unk_00D4 = 0; + } + + unit->UpdateBaseAnimation(0, -1); + this->MoveToDestroyList(); + } else if (this->unk_00D0 && static_cast(FrameTime::s_curTimeMs - this->unk_00D0) > 0) { + CGObject_C* object = ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + return; + } + + object->m_scaleChangeTime = 0; + object->m_scaleModifier = 1.0f; + this->MoveToDestroyList(); + } else if (!(this->m_flags & 0x20) && this->unk_00CC && static_cast(FrameTime::s_curTimeMs - this->unk_00CC) > 0) { + this->MoveToDestroyList(); + } + + if ((this->m_flags & 0x100000) && !SI2::IsPlaying(&this->m_soundKitObject)) { + this->MoveToDestroyList(); + } +} + +// VERIFY: a9069759 manual +// OFFSET: 0x006F8970 +void CEffect::UpdateWorldObject(float elapsed, uint32_t flags) { + if ((!this->unk_00C8 || static_cast(FrameTime::s_curTimeMs - this->unk_00C8) > 0) && this->m_model) { + this->m_model->SetAnimating(1); + + if (!(this->m_flags & 0x100) && this->m_model->IsLoaded(0, 0)) { + CM2Model* model = this->m_model; + CM2Model* parent = model->m_attachParent; + uint32_t visible = flags & 1; + + if (parent) { + model->m_fFlags = (model->m_fFlags & ~0x80u) | (visible << 7); + } else { + model->m_fFlags = (model->m_fFlags & ~0x8u) | (visible << 3); + } + + if (parent) { + model->m_fFlags = (model->m_fFlags & ~0x20000u) | (visible << 17); + } else { + model->m_fFlags = (model->m_fFlags & ~0x10000u) | (visible << 16); + } + + this->unk_00C8 = 0; + } + } + + if (this->unk_00CC && static_cast(FrameTime::s_curTimeMs - this->unk_00CC) > 0) { + this->MoveToDestroyList(); + } +} + +// VERIFY: d4130505 manual +// OFFSET: 0x006F9840 +void CEffect::PostInitialize() { + if (this->m_model && !this->m_model->IsLoaded(0, 0)) { + return; + } + + this->m_flags |= 0x800; + int32_t hasSound = !(this->m_flags & 0x400) && this->m_kitRec && this->m_kitRec->m_soundID && this->m_kitRec->m_soundID != -1; + + if ((this->m_flags & 0x2) && !this->m_mapEntity && this->m_model) { + CGObject_C* source = ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + C44Matrix transform; + C44Matrix* matrix = this->TransformPosition(&transform, source); + this->m_model->m_fFlags |= 0x8000; + this->m_model->m_worldTransform = *matrix; + C44Matrix world = this->m_model->m_worldTransform; + this->m_mapEntity = CMap::ObjectCreateStatic(this->m_model, world, &CGWorldFrame::SpellEffectEnumProc, nullptr, reinterpret_cast(this)); + CAaBox box; + CAaSphere sphere; + C3Vector light; + + if (this->m_model->IsLoaded(0, 0)) { + box = this->m_model->GetBoundingBox(); + sphere = this->m_model->GetBoundingSphere(); + light = sphere.c; + } + + light.z = 1.0f; + world = this->m_model->m_worldTransform; + CMap::ObjectUpdate(this->m_mapEntity, world, box, sphere, light, false, 0xFFFFFFFF); + int32_t animating = !this->unk_00C8 || static_cast(FrameTime::s_curTimeMs - this->unk_00C8) > 0; + this->m_model->SetAnimating(animating); + CM2Model* model = this->m_model; + CM2Model* parent = model->m_attachParent; + uint32_t visible = animating & 1; + + if (parent) { + model->m_fFlags = (model->m_fFlags & ~0x80u) | (visible << 7); + } else { + model->m_fFlags = (model->m_fFlags & ~0x8u) | (visible << 3); + } + + if (parent) { + model->m_fFlags = (model->m_fFlags & ~0x20000u) | (visible << 17); + } else { + model->m_fFlags = (model->m_fFlags & ~0x10000u) | (visible << 16); + } + } + + SpellRec spell; + + if (this->m_spellId && g_spellDB.GetRecord(this->m_spellId, &spell) && (spell.m_attributesExE & 0x40000000)) { + this->m_model->m_fFlags |= 0x4; + } + + if (!this->UpdateAttachment()) { + return; + } + + if ((this->m_flags & 0x10) && this->m_kitRec && this->m_kitRec->m_shakeID > 0) { + C3Vector position = this->TransformPositionByTransport(); + SpellVisualsPlayCameraShakeID(this->m_kitRec->m_shakeID, &position); + } + + if (!hasSound) { + return; + } + + CGObject_C* object = nullptr; + + if (this->m_targetGuid) { + object = ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + } else if (this->m_sourceGuid && !(this->m_flags & 0x2000)) { + object = ClntObjMgrObjectPtr(this->m_sourceGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + } + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + int32_t focus = CGObject_C::GetFocusObject() == object; + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + int32_t listenerAtCharacter = 0; + + if (focus && s_listenerAtCharacter->m_intValue && !(this->m_flags & 0x200000)) { + listenerAtCharacter = 1; + } + + if (focus || this->m_sourceGuid == CGUnit_C::s_activeMover) { + properties.m_priority = 110; + } + + if (CGGameUI::SequenceMusicIsPlaying()) { + return; + } + + if (this->m_flags & 0x1) { + if (!object) { + C3Vector position = this->TransformPositionByTransport(); + SI2::PlaySoundKit(this->m_kitRec->m_soundID, &position, &this->m_soundKitObject, nullptr, 0, nullptr, 1, 0); + return; + } + + C3Vector position = object->GetPosition(); + + if (this->m_flags & 0x1000) { + properties.m_streaming = true; + properties.m_maxAudibleBehavior = 0; + } + + properties.m_noRandomStart = 1; + SI2::PlaySoundKit(this->m_kitRec->m_soundID, &position, &this->m_soundKitObject, &properties, 0, nullptr, 1, 0); + + if (!(this->m_flags & 0x200000)) { + SI2::AttachToObject(&this->m_soundKitObject, object->m_obj->m_guid); + } + + return; + } + + C3Vector position = C3Vector(); + const C3Vector* soundPosition = nullptr; + properties.m_loopMode = 2; + properties.m_maxAudibleBehavior = 0; + + if (listenerAtCharacter) { + properties.m_volumeScale = 0.64999998f; + } else { + position = this->TransformPositionByTransport(); + soundPosition = &position; + } + + SI2::PlaySoundKit(this->m_kitRec->m_soundID, soundPosition, &this->m_soundKitObject, &properties, 0, nullptr, 1, 0); + + if (!listenerAtCharacter && !(this->m_flags & 0x200000) && object) { + SI2::AttachToObject(&this->m_soundKitObject, object->m_obj->m_guid); + } +} diff --git a/WoW/Source/Object/ObjectClient/Effect_C.h b/WoW/Source/Object/ObjectClient/Effect_C.h index 8204e55..9307590 100644 --- a/WoW/Source/Object/ObjectClient/Effect_C.h +++ b/WoW/Source/Object/ObjectClient/Effect_C.h @@ -8,15 +8,33 @@ #include "Engine/Source/Tempest/CImVector.h" #include "WoW/Source/SoundInterface/SoundInterface2.h" +class C44Matrix; class CGObject_C; +class CGUnit_C; +class CMapEntity; +class LightningObject; +class MountTransitionObject; class CM2Lighting; class CM2Model; class SpellVisualEffectNameRec; +class SpellVisualKitModelAttachRec; class SpellVisualKitRec; class CEffect { public: void ApplyItemVisual(); + static void ApplyItemVisualByItemId(int32_t id, const WOWGUID& guid, void* param, bool success); + static void MountTransitionCacheCB(int32_t id, const WOWGUID& guid, void* param, bool success); + void LoadMountTransitionModel(); + void ClearItemVisualEffect(); + void ClearLightning(); + C3Vector TransformPositionByTransport(); + static float __stdcall ComputeModelScaleFromTarget(CGObject_C* object); + static void ApplyModelAttachRecToMatrix(const SpellVisualKitModelAttachRec* attach, C44Matrix& matrix, float facing); + C44Matrix* TransformPosition(C44Matrix* matrix, CGObject_C* object); + void PostInitialize(); + void UpdateWorldObject(float elapsed, uint32_t flags); + void AddLootEffect(CGUnit_C* unit, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)); static void CleanUpStaticLists(); static void Destroy(); static void DrawFishingString(CM2Model* model, const CM2Lighting* lighting, void* arg); @@ -32,33 +50,21 @@ class CEffect { /* 0028 */ C3Vector m_offset; /* 0034 */ SE2SoundKitObject m_soundKitObject; /* 0048 */ uint32_t m_flags; - /* 004C */ uint32_t unk_004C; - /* 0050 */ uint32_t unk_0050; - /* 0054 */ uint32_t unk_0054; - /* 0058 */ uint32_t unk_0058; - /* 005C */ uint32_t unk_005C; - /* 0060 */ uint32_t unk_0060; - /* 0064 */ uint32_t unk_0064; - /* 0068 */ uint32_t unk_0068; - /* 006C */ uint32_t unk_006C; - /* 0070 */ uint32_t unk_0070; - /* 0074 */ uint32_t unk_0074; - /* 0078 */ uint32_t unk_0078; + /* 004C */ LightningObject* m_lightning [12]; /* 007C */ uint32_t unk_007C; /* 0080 */ uint32_t unk_0080; /* 0084 */ uint32_t unk_0084; - /* 0088 */ float unk_0088; + /* 0088 */ float m_facing; /* 008C */ int32_t unk_008C; - /* 0090 */ uint32_t unk_0090; - /* 0094 */ uint32_t unk_0094; - /* 0098 */ uint32_t unk_0098; - /* 009C */ uint32_t unk_009C; + /* 0090 */ MountTransitionObject* m_mountTransition; + /* 0094 */ int32_t m_pendingCacheId; + /* 0098 */ int32_t m_displayId; + /* 009C */ int32_t m_itemSlot; /* 00A0 */ uint32_t unk_00A0; /* 00A4 */ C3Vector m_position; - /* 00B0 */ C3Vector unk_00B0; + /* 00B0 */ C3Vector m_worldPosition; /* 00BC */ uint32_t unk_00BC; - /* 00C0 */ uint32_t unk_00C0; - /* 00C4 */ uint32_t unk_00C4; + /* 00C0 */ WOWGUID m_transportGuid; /* 00C8 */ uint32_t unk_00C8; /* 00CC */ uint32_t unk_00CC; /* 00D0 */ uint32_t unk_00D0; @@ -69,11 +75,11 @@ class CEffect { /* 00E4 */ float unk_00E4; /* 00E8 */ float unk_00E8; /* 00EC */ CImVector m_color; - /* 00F0 */ uint32_t unk_00F0; + /* 00F0 */ CMapEntity* m_mapEntity; /* 00F4 */ int32_t m_refCount; /* 00F8 */ uint32_t unk_00F8; /* 00FC */ int32_t m_lightningState; - /* 0100 */ void* m_attachRec; + /* 0100 */ const SpellVisualKitModelAttachRec* m_attachRec; /* 0104 */ CEffect** m_prevLink; /* 0108 */ CEffect* m_next; /* 010C */ uint32_t unk_010C; @@ -81,7 +87,15 @@ class CEffect { CEffect(); ~CEffect(); void AddFishingLine(CGObject_C* object, const WOWGUID& target); + static void CreateModelFromEffect(CM2Model* model, void* arg); + void AddAnimKitEffect(int32_t spellId, const SpellVisualKitRec* kit, const WOWGUID* guid, uint32_t flags, uint32_t a5); + void AddSoundEffect(int32_t soundId, int32_t a2, int32_t spellId, const C3Vector* position, CGObject_C* object, uint32_t a6); + static void __stdcall DestroyMatchingEffects(CGObject_C* object, const SpellVisualEffectNameRec* effectName, int32_t attachType, int32_t spellId, int32_t kitId, const SpellVisualKitModelAttachRec* attach); + static void EffectEvent(CM2Model* model, uint32_t boneId, uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time, uint64_t param); + void AddEffect(int32_t attachType, int32_t spellId, const SpellVisualKitRec* kit, const SpellVisualEffectNameRec* effectName, const WOWGUID* target, const WOWGUID* source, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), const C3Vector* position, uint32_t a10, const SpellVisualKitModelAttachRec* attach); + void InitFromUnit(C3Vector position, uint32_t time, int32_t spellId, const SpellVisualKitRec* kit, const SpellVisualEffectNameRec* effectName, const WOWGUID* guid, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), uint32_t a9, const SpellVisualKitModelAttachRec* attach, WOWGUID transport); void AddSpecialEffect(int32_t type, const WOWGUID& target, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)); + void AddSpecialByPosition(int32_t type, C3Vector position, const WOWGUID* guid, uint32_t flags, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param)); void ConnectToLightningThisFrame(); void DetachFromParent(); int32_t UpdateAttachment(); diff --git a/WoW/Source/Object/ObjectClient/GameObject_C.cpp b/WoW/Source/Object/ObjectClient/GameObject_C.cpp index 8be6a82..738f186 100644 --- a/WoW/Source/Object/ObjectClient/GameObject_C.cpp +++ b/WoW/Source/Object/ObjectClient/GameObject_C.cpp @@ -2121,3 +2121,19 @@ void CGGameObject_C_Type_TransportBase::AddPassenger(CPassenger* passenger, int3 int32_t CGGameObject_C::GetPageTextMaterial() const { return this->GetPropertyValue(CGameObjectDef::GetPropNum(this->m_gameObject->m_typeID, 17)); } + +// VERIFY: d9d6f845 manual +// OFFSET: 0x0070EDD0 +int32_t CGGameObject_C::ObjectReaction(const CGUnit_C* unit) const { + CGUnit_C* creator = static_cast(ClntObjMgrObjectPtr(this->m_gameObject->m_createdBy, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (creator) { + return creator->UnitReaction(unit); + } + + if (this->m_gameObject->m_faction) { + return CGUnit_C::UnitReaction(this->m_gameObject->m_faction, unit); + } + + return 3; +} diff --git a/WoW/Source/Object/ObjectClient/GameObject_C.h b/WoW/Source/Object/ObjectClient/GameObject_C.h index 3a56e03..f0e017f 100644 --- a/WoW/Source/Object/ObjectClient/GameObject_C.h +++ b/WoW/Source/Object/ObjectClient/GameObject_C.h @@ -333,6 +333,7 @@ class CGGameObject_C : public CGObject_C, public CGGameObject { void PostInit(uint32_t time, const CClientObjCreate& create, bool reenable); void ResetDisplayState(); void SetDisplayState(int32_t state); + int32_t ObjectReaction(const CGUnit_C* unit) const; LockRec* GetLockRec() const; bool IsValidTargetForSpell(const WOWGUID& item, int32_t spellId) const; int32_t CanChangeCursor() const; diff --git a/WoW/Source/Object/ObjectClient/Item_C.cpp b/WoW/Source/Object/ObjectClient/Item_C.cpp index d2a1339..a902eca 100644 --- a/WoW/Source/Object/ObjectClient/Item_C.cpp +++ b/WoW/Source/Object/ObjectClient/Item_C.cpp @@ -42,6 +42,7 @@ #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include #include +#include "WoW/Source/Ui/ItemTextFrame.h" // STATIC: 0x00CA1140 static TSHashTable s_inventoryArt; @@ -1381,3 +1382,311 @@ int32_t CGItem_C::GetRandomPropertyValue(int32_t slot) { int32_t CGItem_C::CanBeUsed() { return this->GetEnchantmentSpell(0) != 0; } + +// VERIFY: 2efe0bae auto +// OFFSET: 0x006081E0 +static int32_t FindItemCallback(const CGItem_C* item, void* param) { + return item == param; +} + +// VERIFY: cb205c40 manual +// OFFSET: 0x0060BFE0 +void CGItem_C::SignalEvent(CGItem_C* item, uint32_t event) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + CGBag_C* bag = &player->m_bag; + + if (!bag) { + return; + } + + WOWGUID container; + uint32_t slot; + + if (!bag->FindItem(FindItemCallback, item, container, slot, 136)) { + return; + } + + if (container == player->m_bag.m_guid) { + if (slot <= 22) { + FrameScript_SignalEvent(event, "%d", slot + 1); + } else if (slot - 23 <= 15) { + FrameScript_SignalEvent(event, "%d%d", 0, slot - 22); + } else if ((slot >= 39 && slot <= 66) || slot - 67 <= 6) { + FrameScript_SignalEvent(event, "%d%d", -1, slot - 38); + } else if (slot - 86 <= 31) { + FrameScript_SignalEvent(event, "%d%d", -2, slot - 85); + } else if (slot - 118 <= 31) { + FrameScript_SignalEvent(event, "%d%d", -4, slot - 117); + } + + return; + } + + for (uint32_t i = 0; i < 4; i++) { + WOWGUID guid = i + 19 < static_cast(bag->m_numSlots) ? bag->m_slots[i + 19] : WOWGUID(); + + if (guid == container) { + FrameScript_SignalEvent(event, "%d%d", i + 1, slot + 1); + return; + } + } + + for (uint32_t i = 0; i < 7; i++) { + WOWGUID guid = i + 67 < static_cast(bag->m_numSlots) ? bag->m_slots[i + 67] : WOWGUID(); + + if (guid == container) { + FrameScript_SignalEvent(event, "%d%d", i + 5, slot + 1); + return; + } + } +} + +// VERIFY: 06278cc4 auto +// OFFSET: 0x00706FE0 +void CGItem_C::Lock() { + if (!(this->m_itemFlags & 1)) { + this->m_itemFlags |= 1; + CGItem_C::SignalEvent(this, SCRIPT_EVENT_ITEM_LOCK_CHANGED); + CGItem_C::SignalEvent(this, SCRIPT_EVENT_ITEM_LOCKED); + } +} + +// VERIFY: 8c3234ae auto +// OFFSET: 0x00707020 +void CGItem_C::Unlock() { + if (this->m_itemFlags & 1) { + this->m_itemFlags &= ~1u; + CGItem_C::SignalEvent(this, SCRIPT_EVENT_ITEM_LOCK_CHANGED); + CGItem_C::SignalEvent(this, SCRIPT_EVENT_ITEM_UNLOCKED); + } +} + +// STATIC: 0x00CA1128 +WOWGUID CGItem_C::s_bindOnUseTarget; + +// STATIC: 0x00CA1138 +WOWGUID CGItem_C::s_bindOnUseItem; + +// VERIFY: 92b5a602 manual +// OFFSET: 0x00708C20 +int32_t CGItem_C::UseItem(WOWGUID* target, int32_t a2) { + if ((this->m_obj->m_type & TYPEMASK_CONTAINER) || (this->m_itemFlags & 1)) { + return 0; + } + + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(this->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (!stats) { + return 0; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return 0; + } + + int32_t spellId = this->GetEnchantmentSpell(0); + SpellRec spell; + int32_t hasSpell = g_spellDB.GetRecord(spellId, &spell); + int16_t overrideId = static_cast(player->m_player->m_playerFieldBytes2); + + if (overrideId) { + OverrideSpellDataRec* overrideRec = g_overrideSpellDataDB.GetRecord(overrideId); + + if (overrideRec && !(overrideRec->m_flags & 1)) { + CGGameUI::DisplayError(ERR_CLIENT_LOCKED_OUT); + return 0; + } + } + + if (player->HasVehicleTransport() && !hasSpell) { + WOWGUID transport; + transport.m_guid = player->GetTransportGUID(); + CGUnit_C* vehicle = static_cast(ClntObjMgrObjectPtr(transport, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (vehicle) { + VehicleSeatRec* seat = vehicle->GetVehicleSeatRec(player->m_movementData.m_transportSeat); + + if (seat && !(seat->m_flags & 0x4000)) { + CGGameUI::DisplayError(ERR_CLIENT_LOCKED_OUT); + return 0; + } + } + } + + if (Spell_C_IsTargeting() && Spell_C_CanTargetItems()) { + CGGameUI::CastItemSpell(this->m_obj->m_guid, 0); + return 0; + } + + if (stats->m_flags[0] & 0x200) { + if (this->m_item->m_itemFieldFlags & 0x8) { + player->OpenWrappedItem(this); + } else { + CGPlayer_C::StartGiftWrap(this); + } + + return 0; + } + + if (stats->m_startQuest) { + CGPlayer_C::QueryQuest(this->m_obj->m_guid, stats->m_startQuest); + return 0; + } + + MapRec* map = g_mapDB.GetRecord(CGGameUI::m_iCurrentMapID); + + if (map && map->m_instanceType == 4 && !(stats->m_flags[0] & 0x200000)) { + uint32_t cooldown; + uint32_t categoryCooldown; + uint32_t category; + + if (stats->m_bonding == 4 || (stats->m_flags[0] & 0x4000000) || (this->GetSpellCooldownInfo(cooldown, categoryCooldown, category), this->GetUsableSpellCharges() < 0) || cooldown > 900000 || categoryCooldown > 900000) { + CGGameUI::DisplayError(ERR_CANT_USE_ITEM_IN_ARENA); + return 0; + } + } + + int32_t error = ERR_MAX_VALUE; + + if (!player->CanUseItem(stats, error)) { + if (error != ERR_CANT_EQUIP_LEVEL_I) { + CGGameUI::DisplayError(static_cast(error)); + } else { + CGGameUI::DisplayError(ERR_CANT_EQUIP_LEVEL_I, stats->m_requiredLevel); + } + + return 0; + } + + uint32_t enchantId = this->GetSpellItemEnchantmentId(); + + if (enchantId) { + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(enchantId); + + if (enchant && enchant->m_requiredSkillID && static_cast(player->GetSkillValue(player->GetSkillIndex(enchant->m_requiredSkillID))) < enchant->m_requiredSkillRank) { + CGGameUI::DisplayError(static_cast(GetDisplayErrorByInventoryError(2))); + return 0; + } + } + + if (stats->m_pageText || (this->m_item->m_itemFieldFlags & 0x200)) { + CGItemText::SetItem(this->m_obj->m_guid, 0); + return 0; + } + + if (!CGGameUI::m_hasControl) { + int32_t allowed = 0; + + if (!hasSpell) { + CGGameUI::DisplayError(ERR_CLIENT_LOCKED_OUT); + return 0; + } + + if ((player->m_unit->m_unitFieldFlags & 0x800000) && ((spell.m_attributesExE & 0x20000) || Spell_C_CancelsFear(player, &spell, 0))) { + allowed = 1; + } + + if ((player->m_unit->m_unitFieldFlags & 0x400000) && ((spell.m_attributesExE & 0x40000) || Spell_C_CancelsConfuse(player, &spell, 0))) { + allowed = 1; + } + + int32_t charmAllowed = player->IsCharmed() && Spell_C_CancelsCharm(player, &spell, 0) ? 1 : allowed; + + if ((!(player->m_unit->m_unitFieldFlags & 0x100000) || !(spell.m_attributes & 0x1000000)) && !charmAllowed) { + CGGameUI::DisplayError(ERR_CLIENT_LOCKED_OUT); + return 0; + } + } + + if (stats->m_flags[0] & 0x4) { + player->OpenLootItem(this); + return 0; + } + + if (stats->m_flags[0] & 0x2000) { + CGPlayer_C::RequestPetitionSignatures(this->m_obj->m_guid); + return 0; + } + + if (!this->GetEnchantmentSpell(0)) { + return 0; + } + + if (this->GetInventoryType()) { + if (this->m_item->m_itemFieldContained != ClntObjMgrGetActivePlayer()) { + CGGameUI::DisplayError(ERR_MUST_EQUIP_ITEM); + return 0; + } + + if (this->GetMaxDurability() && !this->GetDurability()) { + CGGameUI::DisplayError(ERR_MUST_REPAIR_DURABILITY); + return 0; + } + + int32_t slot = player->GetBag()->FindItemSlot(this->m_obj->m_guid); + + if (slot == 15) { + if (player->IsDisarmed(0)) { + CGGameUI::DisplayError(ERR_CANT_USE_DISARMED); + return 0; + } + } else if (slot == 16) { + if (player->IsDisarmed(1)) { + CGGameUI::DisplayError(ERR_CANT_USE_DISARMED); + return 0; + } + } else if (slot >= 23) { + CGGameUI::DisplayError(ERR_MUST_EQUIP_ITEM); + return 0; + } + } + + if (hasSpell) { + if (Spell_C_IsActiveSpell(&spell, player)) { + if (!Spell_C_WasItemRecentlyUsed(this->m_obj->m_entryID)) { + Spell_C_CancelAura(&spell, player, -1); + } + + return 0; + } + + if (this->GetUsableSpellCharges() > 0 && !this->GetCurrentSpellCharges()) { + CGGameUI::DisplayError(ERR_SPELL_FAILED_S, FrameScript_GetText("SPELL_FAILED_NO_CHARGES_REMAIN", -1, GENDER_NOT_APPLICABLE)); + return 0; + } + + if (SpellRec::HasAura(&spell, 78) && !player->CanCurrentFormMount() && player->CanAutoUnshift()) { + player->CancelShapeshiftForMount(); + } + } + + if (player->IsShapeShifted()) { + SpellShapeshiftFormRec* form = g_spellShapeshiftFormDB.GetRecord(player->GetShapeshiftForm()); + + if (form && !(form->m_flags & 0x80) && (!(form->m_flags & 0x40) || !this->GetInventoryType()) && !(stats->m_flags[0] & 0x800000)) { + if (!player->CanAutoUnshift()) { + CGGameUI::DisplayError(ERR_NO_ITEMS_WHILE_SHAPESHIFTED); + return 0; + } + + player->CancelShapeshift(); + } + } + + if (stats->m_bonding != 3 || this->IsBound() || a2) { + return Spell_C::CastSpell(spellId, this, *target, false); + } + + CGItem_C::s_bindOnUseItem = this->m_obj->m_guid; + CGItem_C::s_bindOnUseTarget = *target; + FrameScript_SignalEvent(SCRIPT_EVENT_USE_BIND_CONFIRM, nullptr); + return 0; +} diff --git a/WoW/Source/Object/ObjectClient/Item_C.h b/WoW/Source/Object/ObjectClient/Item_C.h index bcfa7a1..fc290d3 100644 --- a/WoW/Source/Object/ObjectClient/Item_C.h +++ b/WoW/Source/Object/ObjectClient/Item_C.h @@ -20,6 +20,8 @@ struct INVENTORYART : public TSHashObject { struct ITEMBYNAME : public TSHashObject { }; +int32_t GetItemIDByName(const char* name); + class CGItem_C : public CGObject_C, public CGItem { public: static void Initialize(); @@ -65,6 +67,8 @@ class CGItem_C : public CGObject_C, public CGItem { uint32_t GetDisplayID() const; uint32_t GetEnchantmentTimeLeft(int32_t slot) const; int32_t UseItem(WOWGUID* target, int32_t a2); + static WOWGUID s_bindOnUseTarget; + static WOWGUID s_bindOnUseItem; int32_t CanBeUsed(); uint32_t GetExpirationTimeLeft() const; char* GetFullItemName(char* buffer, uint32_t size) const; @@ -85,6 +89,8 @@ class CGItem_C : public CGObject_C, public CGItem { int32_t HasUseEffect(); bool IsBound(); void Unlock(); + void Lock(); + static void SignalEvent(CGItem_C* item, uint32_t event); static int32_t GetUseSpell(int32_t itemId); static int32_t GetRandomPropertyValue(int32_t slot, int32_t randomPropertiesId, int32_t points); static int32_t IsLocked(const LockRec* lock, int32_t itemLevel, int32_t* spellId, int32_t* skillValue, int32_t* requiredSkill, int32_t* lockIndex, CGItem_C** key, int32_t* entry); diff --git a/WoW/Source/Object/ObjectClient/LootRoll.cpp b/WoW/Source/Object/ObjectClient/LootRoll.cpp index c1cebde..939069a 100644 --- a/WoW/Source/Object/ObjectClient/LootRoll.cpp +++ b/WoW/Source/Object/ObjectClient/LootRoll.cpp @@ -1,6 +1,11 @@ #include "LootRoll.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/Types.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/Object/ItemStats.h" +#include "WoW/Source/WowServices/WDataStore.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/Net/Types.h" // STATIC: 0x00ADA7B4 TSExplicitList s_pendingLootRolls; @@ -54,3 +59,97 @@ void LootRollShowPending() { } } } + +// VERIFY: 4f4e9712 manual +// OFFSET: 0x006FBC70 +void LootRoll(int32_t id, int32_t rollType, bool confirmed) { + for (PendingLootRoll* roll = s_pendingLootRolls.Head(); roll; roll = s_pendingLootRolls.Next(roll)) { + if (roll->m_id != id) { + continue; + } + + if (roll->unk_0042) { + return; + } + + if (rollType && !confirmed) { + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(roll->m_itemId, none, nullptr, nullptr, false); + + if (stats) { + if (rollType == 3) { + if (stats->m_quality >= 3) { + FrameScript_SignalEvent(SCRIPT_EVENT_CONFIRM_DISENCHANT_ROLL, "%d%d", roll->m_id, 3); + return; + } + } else if (stats->m_bonding == 1) { + FrameScript_SignalEvent(SCRIPT_EVENT_CONFIRM_LOOT_ROLL, "%d%d", roll->m_id, rollType); + return; + } + } + } + + if ((1 << rollType) & roll->m_voteMask) { + WDataStore msg; + msg.Put(static_cast(CMSG_LOOT_ROLL)); + msg.Put(roll->m_lootGuid.m_guid); + msg.Put(roll->m_slot); + msg.Put(static_cast(rollType)); + msg.Finalize(); + ClientServices::Send2(&msg); + roll->unk_0030 = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CANCEL_LOOT_ROLL, "%d", roll->m_id); + s_numShownLootRolls--; + roll->unk_0042 = 1; + LootRollShowPending(); + } + + return; + } +} + +// VERIFY: f5032c00 manual +// OFFSET: 0x006FAF40 +void LootRollDestroy() { + PendingLootRoll* roll; + + while ((roll = s_pendingLootRolls.Head())) { + s_pendingLootRolls.DeleteNode(roll); + } +} + +// VERIFY: ab7c1274 auto +// OFFSET: 0x006FAFB0 +void LootRollShutdown() { + LootRollDestroy(); + s_numShownLootRolls = 0; +} + +// VERIFY: 59202aa4 manual +// OFFSET: 0x006FAFD0 +void CloseAllLootRolls() { + PendingLootRoll* roll = s_pendingLootRolls.Head(); + + while (roll) { + PendingLootRoll* next = s_pendingLootRolls.Next(roll); + + if (!roll->unk_0042) { + WDataStore msg; + msg.Put(static_cast(CMSG_LOOT_ROLL)); + msg.Put(roll->m_lootGuid.m_guid); + msg.Put(roll->m_slot); + msg.Put(static_cast(0)); + msg.Finalize(); + ClientServices::Send2(&msg); + + if (!roll->m_showPending) { + FrameScript_SignalEvent(SCRIPT_EVENT_CANCEL_LOOT_ROLL, "%d", roll->m_id); + } + } + + roll = next; + } + + LootRollDestroy(); + s_numShownLootRolls = 0; +} diff --git a/WoW/Source/Object/ObjectClient/LootRoll.h b/WoW/Source/Object/ObjectClient/LootRoll.h index 2db4a1e..f7fdc62 100644 --- a/WoW/Source/Object/ObjectClient/LootRoll.h +++ b/WoW/Source/Object/ObjectClient/LootRoll.h @@ -39,8 +39,10 @@ extern uint32_t s_numShownLootRolls; PendingLootRoll* FindRoll(int32_t id); WOWGUID GetMasterLootCandidate(uint32_t index); void LootRollShowPending(); +void LootRoll(int32_t id, int32_t rollType, bool confirmed); void CloseAllLootRolls(); void LootRollDestroy(); +void LootRollShutdown(); #endif diff --git a/WoW/Source/Object/ObjectClient/Missile_C.cpp b/WoW/Source/Object/ObjectClient/Missile_C.cpp index ea0f2a9..48131ff 100644 --- a/WoW/Source/Object/ObjectClient/Missile_C.cpp +++ b/WoW/Source/Object/ObjectClient/Missile_C.cpp @@ -7,10 +7,52 @@ #include "Engine/Source/Tempest/C44Matrix.h" #include "WoW/Source/Object/ObjectClient/Movement_C.h" #include "WoW/Source/Object/ObjectClient/SimpleScript.h" +#include "Engine/Source/Tempest/C33Matrix.h" +#include "Engine/Source/Tempest/CRandom.h" +#include "Engine/Source/Model2/M2Model.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Object/Movement.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/WorldClient/World.h" +#include "Engine/Source/Model2/M2Scene.h" +#include "WoW/Source/Object/ObjectClient/UnitMissileTrajectory_C.h" +#include "WoW/Source/WorldClient/MapEntity.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/Tempest/C2Vector.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/DB/Rec/SpellMissileRec.h" +#include "WoW/Source/DB/Rec/SpellVisualRec.h" +#include "WoW/Source/DB/Rec/SpellVisualKitRec.h" +#include "WoW/Source/Magic/Spell.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/ObjectClient/UnitCombatLog_C.h" +#include "WoW/Source/Object/ObjectClient/VehiclePassenger_C.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/Tempest/CMath.h" +#include "Engine/Source/Services/ParticleSystem2.h" +#include "WoW/Source/Object/ObjectClient/Effect_C.h" +#include "WoW/Source/Ui/WorldFrame.h" +#include "WoW/Source/WorldClient/Map.h" +#include "WoW/Source/DB/Rec/SpellMissileMotionRec.h" // STATIC: 0x00CA0B58 CMissile* CMissile::s_inFlightMissileList; +// STATIC: 0x00CA0B5C +CMissile* CMissile::s_missileDestroyList; + +// STATIC: 0x00ADA828 +static SimpleScriptIO s_msfIO; + +// STATIC: 0x00ADA7C0 +static const char* s_msfArgs[] = { "progress", "time", "missileIndex", "missileCount", "distanceToFirePos", "distanceToImpactPos", "startDistance", "totalDistance", "rand1", "rand2", "rand3", "spellID", nullptr }; + +// STATIC: 0x00ADA7F4 +static const char* s_msfReturns[] = { "transAngle", "transMag", "transRight", "transFront", "transUp", "modelYaw", "modelPitch", "modelRoll", "speedAbs", "speedScalar", "speedOffset", "scale", nullptr }; + // STATIC: 0x00CA0B60 uint32_t* CMissile::s_missileHeap; @@ -253,13 +295,13 @@ C3Vector CMissile::TransformPositionByTransport() { return this->m_worldImpactPos; } -// VERIFY: e84e0383 manual +// VERIFY: e2196867 manual // OFFSET: 0x006FFED0 void CMissile::UpdateProgress(float distance) { C3Vector impact = this->TransformPositionByTransport(); - float dx = impact.x - this->m_position.x; - float dy = impact.y - this->m_position.y; - float dz = impact.z - this->m_position.z; + float dx = impact.x - this->m_launchPos.x; + float dy = impact.y - this->m_launchPos.y; + float dz = impact.z - this->m_launchPos.z; float dySq = dy * dy; float dxSq = dx * dx; float remaining = sqrt(dxSq + dz * dz + dySq); @@ -276,8 +318,8 @@ void CMissile::UpdateProgress(float distance) { this->m_progress = progress; impact = this->TransformPositionByTransport(); - float hx = impact.x - this->m_launchPos.x; - float hy = impact.y - this->m_launchPos.y; + float hx = impact.x - this->m_position.x; + float hy = impact.y - this->m_position.y; float total = sqrt(dxSq + dySq); float horizontalProgress = 1.0f; @@ -292,11 +334,11 @@ void CMissile::UpdateProgress(float distance) { this->m_horizontalProgress = horizontalProgress; } -// VERIFY: 07b406e6 manual +// VERIFY: 240015da manual // OFFSET: 0x00700550 int32_t CMissile::ApplyMotionScriptFunctionTranslation(const SimpleScriptIO& io, C44Matrix& matrix) { C3Vector impact = this->TransformPositionByTransport(); - C3Vector dir(impact.x - this->m_position.x, impact.y - this->m_position.y, 0.0f); + C3Vector dir(impact.x - this->m_launchPos.x, impact.y - this->m_launchPos.y, 0.0f); float lengthSq = dir.y * dir.y + dir.x * dir.x; if (lengthSq > 2.3841858e-7f) { @@ -342,38 +384,38 @@ int32_t CMissile::ApplyMotionScriptFunctionTranslation(const SimpleScriptIO& io, return moved > 0.2f; } -// VERIFY: 88c0c9d0 manual +// VERIFY: 5d1af25b manual // OFFSET: 0x00700350 int32_t CMissile::CallMotionScriptFunction(SimpleScriptIO& io) { io.m_numbers.m_count = 12; io.m_numbers.m_data[0] = this->m_progress; - io.m_numbers.m_data[1] = (double)(int32_t)(OsGetAsyncTimeMs() - this->unk_0180) * 0.001f; + io.m_numbers.m_data[1] = (double)(int32_t)(OsGetAsyncTimeMs() - this->m_fireTime) * 0.001f; io.m_numbers.m_data[2] = this->unk_0110; io.m_numbers.m_data[3] = this->unk_0114; - float dx = this->m_position.x - this->m_launchPos.x; - float dy = this->m_position.y - this->m_launchPos.y; - float dz = this->m_position.z - this->m_launchPos.z; + float dx = this->m_launchPos.x - this->m_position.x; + float dy = this->m_launchPos.y - this->m_position.y; + float dz = this->m_launchPos.z - this->m_position.z; io.m_numbers.m_data[4] = sqrt(dz * dz + dy * dy + dx * dx); C3Vector impact = this->TransformPositionByTransport(); - dx = impact.x - this->m_launchPos.x; - dy = impact.y - this->m_launchPos.y; - dz = impact.z - this->m_launchPos.z; - io.m_numbers.m_data[5] = sqrt(dz * dz + dy * dy + dx * dx); - io.m_numbers.m_data[6] = this->unk_0184; - - impact = this->TransformPositionByTransport(); dx = impact.x - this->m_position.x; dy = impact.y - this->m_position.y; dz = impact.z - this->m_position.z; + io.m_numbers.m_data[5] = sqrt(dz * dz + dy * dy + dx * dx); + io.m_numbers.m_data[6] = this->m_initialDistance; + + impact = this->TransformPositionByTransport(); + dx = impact.x - this->m_launchPos.x; + dy = impact.y - this->m_launchPos.y; + dz = impact.z - this->m_launchPos.z; io.m_numbers.m_data[7] = sqrt(dz * dz + dy * dy + dx * dx); - io.m_numbers.m_data[8] = this->unk_0188; - io.m_numbers.m_data[9] = this->unk_018C; - io.m_numbers.m_data[10] = this->unk_0190; + io.m_numbers.m_data[8] = this->m_random[0]; + io.m_numbers.m_data[9] = this->m_random[1]; + io.m_numbers.m_data[10] = this->m_random[2]; io.m_numbers.m_data[11] = this->m_spellID; - if (!CSimpleScriptManager::s_instance->CallFunction(this->unk_017C, io, io)) { + if (!CSimpleScriptManager::s_instance->CallFunction(this->m_motionScriptFunction, io, io)) { return 0; } @@ -385,20 +427,1779 @@ int32_t CMissile::CallMotionScriptFunction(SimpleScriptIO& io) { if (io.m_numbers.m_data[8] > 0.0) { this->m_flags |= 0x1000000; - this->unk_0024 = io.m_numbers.m_data[8]; + this->m_speed = io.m_numbers.m_data[8]; } if (io.m_numbers.m_data[9] > 0.0) { this->m_flags |= 0x1000000; - this->unk_0024 = io.m_numbers.m_data[9] * this->unk_0028; + this->m_speed = io.m_numbers.m_data[9] * this->m_baseSpeed; } if (0.0 != io.m_numbers.m_data[10]) { - float scale = io.m_numbers.m_data[10] + this->unk_0028; - this->unk_0024 = scale; + float scale = io.m_numbers.m_data[10] + this->m_baseSpeed; + this->m_speed = scale; this->m_flags |= 0x1000000; - this->unk_0024 = 0.0099999998f < scale ? scale : 0.0099999998f; + this->m_speed = 0.0099999998f < scale ? scale : 0.0099999998f; } return 1; } + +// VERIFY: 17e0df9b manual +// OFFSET: 0x006FF4C0 +void ChaserState::ChaserImplementation(const C3Vector& target, float stiffness, float elapsed) { + float x = stiffness * elapsed; + float damping = 1.0f / (x + x * x * x * 0.235f + x * x * 0.47999999f + 1.0f); + float dx = this->m_position.x - target.x; + float dy = this->m_position.y - target.y; + float dz = this->m_position.z - target.z; + float vx = (dx * stiffness + this->m_velocity.x) * elapsed; + float vy = (this->m_velocity.y + dy * stiffness) * elapsed; + float vz = elapsed * (this->m_velocity.z + dz * stiffness); + this->m_position = C3Vector((dx + vx) * damping + target.x, (dy + vy) * damping + target.y, (dz + vz) * damping + target.z); + this->m_velocity = C3Vector((this->m_velocity.x - vx * stiffness) * damping, (this->m_velocity.y - vy * stiffness) * damping, (this->m_velocity.z - stiffness * vz) * damping); +} + +// VERIFY: 1f83aaf4 auto +// OFFSET: 0x006FEAE0 +static float SmoothStep(float t) { + if (t < 0.0f) { + return 0.0f; + } + + if (t <= 1.0f) { + return t * ((3.0f - (t + t)) * t); + } + + return 1.0f; +} + +// VERIFY: cdfd2d24 auto +// OFFSET: 0x006FEC10 +C3Vector* CMissile::ResolveTargetPosition(C3Vector* position, WOWGUID* transport) { + if (!this->m_transportGuid) { + *transport = WOWGUID(); + *position = this->m_impactPos; + } else if (MovementObjIsTransport(this->m_transportGuid)) { + *transport = this->m_transportGuid; + *position = this->m_impactPos; + } else { + *transport = WOWGUID(); + *position = this->m_worldImpactPos; + } + + return position; +} + +// VERIFY: 2f03598a manual +// OFFSET: 0x006FEDA0 +void CMissile::Link(CMissile** link) { + if (this->m_prevLink) { + *this->m_prevLink = this->m_next; + } + + if (this->m_next) { + this->m_next->m_prevLink = this->m_prevLink; + } + + this->m_next = nullptr; + this->m_prevLink = link; + this->m_next = *link; + *link = this; + + if (this->m_next) { + this->m_next->m_prevLink = &this->m_next; + } +} + +// VERIFY: 4caf78ff manual +// OFFSET: 0x006FEE00 +int32_t CMissile::AttachToVictim(CGUnit_C* victim, uint32_t duration) { + if (!this->m_model || !this->m_model->IsLoaded(0, 0) || !(this->m_model->m_fFlags & 0x8000)) { + return 0; + } + + if (!victim) { + return 0; + } + + CM2Model* victimModel = victim->m_worldModel; + + if (!victimModel || !victimModel->IsLoaded(0, 0) || !victimModel->HasAttachment(this->m_attachmentID) || this->m_fizzleTime) { + return 0; + } + + uint32_t destroyTime = OsGetAsyncTimeMs() + duration; + CMissile** link = &victim->m_pendingMissiles; + + while (*link && static_cast((*link)->m_destroyTime - destroyTime) < 0) { + link = &(*link)->m_next; + } + + if (this->m_mapEntity) { + World::ObjectDestroy(this->m_mapEntity); + } + + this->m_mapEntity = nullptr; + this->Link(link); + this->m_destroyTime = destroyTime; + this->m_model->SetBoneSequence(0xFFFFFFFF, 191, 0xFFFFFFFF, 0, 1.0f, 1, 1); + this->m_model->AttachToParent(victim->m_worldModel, this->m_attachmentID, nullptr, 0); + C44Matrix attach = victim->m_worldModel->GetAttachmentWorldTransform(this->m_attachmentID); + C44Matrix world = this->m_model->m_worldTransform; + this->m_model->SetWorldTransform(world * attach.AffineInverse(sqrt(attach.a1 * attach.a1 + attach.a2 * attach.a2 + attach.a0 * attach.a0))); + this->m_flags |= 2; + return 1; +} + +// VERIFY: 2870c504 manual +// OFFSET: 0x006FF410 +void CMissile::ClearTargetingEffects() { + if (!this->m_targetingUnit) { + return; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_targetingUnit, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->ClearEffectKit(this->m_spellID, 7, this->m_targetingEffectTime, 1, 1); + } + + this->m_targetingUnit = WOWGUID(); +} + +// VERIFY: 4f946d0f auto +// OFFSET: 0x006FF6C0 +void CMissile::SetReadyToFire(CMissile** list) { + this->Link(list); +} + +// VERIFY: fead66fc manual +// OFFSET: 0x006FF6D0 +void CMissile::UpdateImpactPos() { + CGObject_C* target = ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!target) { + return; + } + + C3Vector position(0.0f, 0.0f, 0.0f); + CM2Model* model = target->m_worldModel; + + if (this->m_attachmentID != -1 && model && model->HasAttachment(this->m_attachmentID) && (model->m_fFlags & 0x8000)) { + position = this->m_attachOffset * model->GetAttachmentWorldTransform(this->m_attachmentID); + } else { + position = this->m_attachOffset; + position.z = target->m_height * target->m_scale * 0.75f + position.z; + + if ((target->m_obj->m_type & TYPEMASK_UNIT) && static_cast(target)->m_vehiclePassenger && model && (model->m_fFlags & 0x8000)) { + position *= model->GetAnimatedWorldTransform(); + } else { + position *= target->GetMatrix(); + } + } + + if ((this->m_motionFlags & 1) && (this->m_motionFlags & 8)) { + position.z = target->GetPosition().z + this->m_groundOffset; + } + + if (this->m_flags & 8) { + C3Vector delta(position.x - this->m_position.x, position.y - this->m_position.y, position.z - this->m_position.z); + float length = sqrt(delta.z * delta.z + delta.y * delta.y + delta.x * delta.x); + + if (fabs(length) < 2.3841858e-7f) { + return; + } + + float inv = 1.0f / length; + C3Vector dir(inv * delta.x, delta.y * inv, inv * delta.z); + + if (fabs(fabs(dir.z) - 1.0f) < 2.3841858e-7f) { + return; + } + + float extended = length + this->m_speed * 0.5f; + C3Vector offset(extended * dir.x, dir.y * extended, extended * dir.z); + C3Vector axis(-(delta.x * delta.z), delta.z * -delta.y, delta.x * delta.x - delta.y * -delta.y); + float angle = sin(CRandom::sfloat_(g_rndSeed) * 1.5707964f) * 0.052359879f; + C3Vector rotated = offset * C33Matrix::Rotation(angle, axis, false); + this->m_impactPos.x = this->m_position.x + rotated.x; + this->m_impactPos.y = rotated.y + this->m_position.y; + this->m_impactPos.z = rotated.z + this->m_position.z; + this->m_transportGuid = WOWGUID(); + return; + } + + if (target->m_obj->m_type & TYPEMASK_UNIT) { + CMovement_C* movement = static_cast(target)->m_movement; + C3Vector toTarget(position.x - this->m_position.x, position.y - this->m_position.y, position.z - this->m_position.z); + float speed = movement->m_currentSpeed; + C3Vector velocity(movement->m_moveDir.x * speed, movement->m_moveDir.y * speed, speed * movement->m_moveDir.z); + float speedSq = this->m_speed * this->m_speed; + + if (velocity.z * velocity.z + velocity.y * velocity.y + velocity.x * velocity.x > speedSq) { + velocity.NormalizeSafe(); + velocity.x = velocity.x * this->m_speed; + velocity.y = velocity.y * this->m_speed; + velocity.z = this->m_speed * velocity.z; + } + + C3Vector half(velocity.x * 0.5f, velocity.y * 0.5f, velocity.z * 0.5f); + float a = half.z * half.z + half.y * half.y + half.x * half.x - speedSq; + float dot = half.z * toTarget.z + half.y * toTarget.y + half.x * toTarget.x; + float b = dot + dot; + float c = (toTarget.y * toTarget.y + toTarget.z * toTarget.z + toTarget.x * toTarget.x) * a; + float discriminant = b * b - c * 4.0f; + + if (discriminant >= 0.0f && a * a >= 0.0000099999997f) { + float inv2a = 0.5f / a; + float root = sqrt(discriminant); + float t1 = (-b - root) * inv2a; + float t2 = inv2a * (root - b); + float best = FLT_MAX; + + if (t1 > 0.0f && t1 < FLT_MAX) { + best = t1; + } + + if (t2 > 0.0f && t2 < best) { + best = t2; + } + + if (FLT_MAX != best) { + this->m_impactPos.x = half.x * best + position.x; + this->m_transportGuid = WOWGUID(); + this->m_impactPos.y = half.y * best + position.y; + this->m_impactPos.z = best * half.z + position.z; + return; + } + } + } + + this->m_impactPos = position; + this->m_transportGuid = WOWGUID(); +} + +// VERIFY: ca267e5d manual +// OFFSET: 0x006FFCD0 +void CMissile::CalcMissFade() { + C3Vector impact = this->TransformPositionByTransport(); + float fadeDistance = 0.0f; + + if (this->m_flags & 8) { + fadeDistance = this->m_speed * 0.5f; + } + + if (!this->m_model || this->m_fizzleTime) { + return; + } + + float dy = impact.y - this->m_position.y; + float dx = impact.x - this->m_position.x; + float dz = impact.z - this->m_position.z; + float distSq = dx * dx + dy * dy + dz * dz; + + if (fadeDistance * fadeDistance > distSq) { + this->m_model->m_fadeAlpha = SmoothStep(sqrt(distSq) / fadeDistance); + } +} + +// VERIFY: f702a9e0 manual +// OFFSET: 0x006FFD70 +void CMissile::ApplyTargetTransportOffset(CGObject_C* target, C3Vector* position, float elapsed) { + WOWGUID transport; + + if (target) { + transport.m_guid = target->GetTransportGUID(); + } else { + transport = this->m_transportGuid; + } + + if (!transport) { + return; + } + + CGObject_C* object = ClntObjMgrObjectPtr(transport, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + return; + } + + C3Vector transportPos = (object->m_obj->m_type & TYPEMASK_UNIT) ? static_cast(object)->BuildSmoothPosition() : object->GetPosition(); + + if (this->m_flags & 0x4000000) { + C3Vector delta(transportPos.x - this->m_lastTransportPos.x, transportPos.y - this->m_lastTransportPos.y, transportPos.z - this->m_lastTransportPos.z); + this->m_transportOffset.ChaserImplementation(delta, 5.0f, elapsed); + position->x = position->x + this->m_transportOffset.m_position.x; + position->y = this->m_transportOffset.m_position.y + position->y; + position->z = this->m_transportOffset.m_position.z + position->z; + } else { + this->m_transportOffset.m_position = C3Vector(0.0f, 0.0f, 0.0f); + this->m_transportOffset.m_velocity = C3Vector(0.0f, 0.0f, 0.0f); + this->m_flags |= 0x4000000; + } + + this->m_lastTransportPos = transportPos; +} + +// VERIFY: 60128e18 manual +// OFFSET: 0x006FFFC0 +void CMissile::FollowGround(const C3Vector& direction, float distance) { + if (distance < 0.0f) { + distance = 0.0f; + } else if (distance >= 50.0f) { + distance = 50.0f; + } + + C3Vector target(direction.x * distance * 2.0f + this->m_position.x, direction.y * distance * 2.0f + this->m_position.y, direction.z * distance * 2.0f + this->m_position.z); + C3Vector flat; + + if (fabs(direction.z) <= 0.99900001f) { + float inv = 1.0f / sqrt(direction.y * direction.y + direction.x * direction.x); + flat = C3Vector(direction.x * inv, direction.y * inv, inv * 0.0f); + } else { + flat = C3Vector(1.0f, 0.0f, 0.0f); + } + + int32_t steps = 4; + float remaining = distance; + C3Vector end; + + while (true) { + C3Vector step(flat.x * remaining, flat.y * remaining, remaining * flat.z); + C3Vector start = this->m_position; + end = C3Vector(step.x + this->m_position.x, step.y + this->m_position.y, step.z + this->m_position.z); + float t = 1.0f; + C3Vector hit(0.0f, 0.0f, 0.0f); + + if (!World::Intersect(start, end, &hit, &t, 0x111, nullptr)) { + break; + } + + this->m_position.x = step.x * t + this->m_position.x; + this->m_position.y = step.y * t + this->m_position.y; + this->m_position.z = step.z * t + this->m_position.z; + remaining = (1.0f - t) * remaining; + this->m_position.z = this->m_groundOffset + this->m_position.z; + + if (t > 0.99900001f || --steps <= 0) { + break; + } + } + + this->m_position = end; + + if (steps == 4) { + C3Vector start = this->m_position; + C3Vector down(this->m_position.x, this->m_position.y, this->m_position.z - (this->m_groundOffset + 20.0f)); + C3Vector hit(0.0f, 0.0f, 0.0f); + float t = 1.0f; + + if (World::Intersect(start, down, &hit, &t, 0x111, nullptr)) { + float ground = this->m_groundOffset + hit.z; + float z = this->m_position.z - (this->m_position.z - ground) * this->m_followGroundRate * distance; + + if (z > ground) { + ground = z; + } + + this->m_position.z = ground; + } + } + + if (this->m_followGroundStart < this->m_horizontalProgress) { + float blend = 1.0f / (1.0f - this->m_followGroundStart) * (this->m_horizontalProgress - this->m_followGroundStart); + blend = blend * blend; + + if (this->m_motionFlags & 4) { + float keep = 1.0f - blend; + this->m_position.x = target.x * blend + this->m_position.x * keep; + this->m_position.y = this->m_position.y * keep + target.y * blend; + this->m_position.z = target.z * blend + keep * this->m_position.z; + } else { + C3Vector impact = this->TransformPositionByTransport(); + float keep = 1.0f - blend; + this->m_position.x = impact.x * blend + this->m_position.x * keep; + this->m_position.y = impact.y * blend + this->m_position.y * keep; + this->m_position.z = impact.z * blend + keep * this->m_position.z; + } + } +} + +// VERIFY: c18f5cdc auto +// OFFSET: 0x006FF470 +C44Matrix CMissile::GetPositionMatrix() const { + C44Matrix matrix; + matrix.a0 = 1.0f; + matrix.a1 = 0.0f; + matrix.a2 = 0.0f; + matrix.a3 = 0.0f; + matrix.b0 = 0.0f; + matrix.b2 = 0.0f; + matrix.b3 = 0.0f; + matrix.c0 = 0.0f; + matrix.c1 = 0.0f; + matrix.c3 = 0.0f; + matrix.b1 = 1.0f; + matrix.c2 = 1.0f; + matrix.d0 = this->m_position.x; + matrix.d1 = this->m_position.y; + matrix.d2 = this->m_position.z; + matrix.d3 = 1.0f; + return matrix; +} + +// VERIFY: cb224bb9 manual +// OFFSET: 0x00700700 +void CMissile::BeginWaitingForModelFX(int32_t disableEffects) { + this->ClearTargetingEffects(); + + if (disableEffects) { + this->m_flags |= 0x10000000; + } + + this->Link(&CMissile::s_missileDestroyList); + CGObject_C* object = ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + CGUnit_C* target = object && (object->m_obj->m_type & TYPEMASK_UNIT) ? static_cast(object) : nullptr; + + if (this->m_model && this->m_model->IsLoaded(0, 0) && (this->m_model->m_fFlags & 0x8000)) { + if (!this->m_fizzleTime) { + this->m_model->SetBoneSequence(0xFFFFFFFF, 191, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } + + if (target) { + CM2Model* targetModel = target->m_worldModel; + + if (targetModel && targetModel->IsLoaded(0, 0) && targetModel->HasAttachment(this->m_attachmentID)) { + this->m_model->AttachToParent(targetModel, this->m_attachmentID, nullptr, 0); + C44Matrix attach = targetModel->GetAttachmentWorldTransform(this->m_attachmentID); + C44Matrix world = this->m_model->m_worldTransform; + this->m_model->SetWorldTransform(world * attach.AffineInverse(sqrt(attach.a1 * attach.a1 + attach.a2 * attach.a2 + attach.a0 * attach.a0))); + } + } + } + + if (this->m_mapEntity) { + World::ObjectSetUpdateCallback(this->m_mapEntity, nullptr, nullptr); + } +} + +// VERIFY: 55d630e5 manual +// OFFSET: 0x00701F50 +CMissile::CMissile() { + this->m_speed = 0.0f; + this->m_baseSpeed = 0.0f; + this->m_casterGuid = WOWGUID(); + this->m_targetGuid = WOWGUID(); + this->m_transportGuid = WOWGUID(); + this->m_model = nullptr; + this->m_spellID = 0; + this->m_position = C3Vector(0.0f, 0.0f, 0.0f); + this->m_launchPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_impactPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_worldImpactPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_lastModelPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_flags = 0; + this->m_attachmentID = -1; + this->m_attachOffset = C3Vector(0.0f, 0.0f, 0.0f); + this->m_soundKitID = 0; + this->m_hitResult = 0; + this->m_destroyTime = 0; + this->m_victimAnimTime = 0; + this->m_castTime = 0; + this->m_duration = 1000; + this->m_lastUpdateTime = 0; + this->m_currentTarget = 0; + this->m_scale = 1.0f; + this->m_progress = 0.0f; + this->m_horizontalProgress = 0.0f; + this->m_groundOffset = 0.0f; + this->m_followGroundRate = 0.0f; + this->m_followGroundStart = 0.0f; + this->m_motionFlags = 0; + this->unk_0110 = 0; + this->unk_0114 = 1; + this->m_velocity = C3Vector(0.0f, 0.0f, 0.0f); + this->m_fizzleTime = 0; + this->m_missileCollision = nullptr; + this->m_timeScale = 1.0f; + this->m_remoteCollisionPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_mapEntity = nullptr; + this->m_initialDistance = 0.0f; + this->m_mapEntity2 = nullptr; + this->m_random[0] = 0.0f; + this->m_prevLink = nullptr; + this->m_random[1] = 0.0f; + this->m_next = nullptr; + this->m_random[2] = 0.0f; + this->m_targetingUnit = WOWGUID(); + this->m_targetingEffectTime = 0; + this->m_motionScriptFunction = -1; + this->m_smoothDirection = C3Vector(0.0f, 0.0f, 0.0f); + this->m_lastTransportPos = C3Vector(0.0f, 0.0f, 0.0f); + this->m_transportOffset.m_position = C3Vector(0.0f, 0.0f, 0.0f); + this->m_transportOffset.m_velocity = C3Vector(0.0f, 0.0f, 0.0f); + this->m_targets.SetCount(0); + this->m_targetHitResults.SetCount(0); + this->m_targetMissReasons.SetCount(0); + this->m_targetPoints.SetCount(0); +} + +// VERIFY: fd33567b manual +// OFFSET: 0x00702190 +CMissile::~CMissile() { + this->ClearTargetingEffects(); + + if (this->m_model) { + if (this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + this->m_model->Release(); + this->m_model = nullptr; + } + + if (this->m_mapEntity) { + World::ObjectDestroy(this->m_mapEntity); + this->m_mapEntity = nullptr; + } + + if (this->m_mapEntity2) { + World::ObjectDestroy(this->m_mapEntity2); + this->m_mapEntity2 = nullptr; + } + + if (this->m_prevLink) { + *this->m_prevLink = this->m_next; + } + + if (this->m_next) { + this->m_next->m_prevLink = this->m_prevLink; + } + + this->m_next = nullptr; + this->m_prevLink = nullptr; + SI2::StopSound(&this->m_missileSound, 0, 0.15000001f, 1); + this->m_targets.SetCount(0); + this->m_targetHitResults.SetCount(0); + this->m_targetMissReasons.SetCount(0); + this->m_targetPoints.SetCount(0); +} + +// VERIFY: 28f4590a auto +// OFFSET: 0x00702B10 +CMissile* CMissile::NewMissile() { + uint32_t memHandle; + CMissile* missile = nullptr; + + if (!ObjectAlloc(*CMissile::s_missileHeap, &memHandle, reinterpret_cast(&missile), false)) { + return nullptr; + } + + if (missile) { + new (missile) CMissile(); + } + + missile->m_memHandle = memHandle; + return missile; +} + +// VERIFY: 02259a6e auto +// OFFSET: 0x00702B60 +CMissile* CMissile::CopyMissile(const CMissile* source) { + uint32_t memHandle; + CMissile* missile = nullptr; + + if (ObjectAlloc(*CMissile::s_missileHeap, &memHandle, reinterpret_cast(&missile), false)) { + if (missile) { + new (missile) CMissile(); + } + + missile->m_memHandle = memHandle; + } else { + missile = nullptr; + } + + missile->m_casterGuid = source->m_casterGuid; + missile->m_targetGuid = source->m_targetGuid; + missile->m_spellID = source->m_spellID; + missile->m_speed = source->m_speed; + missile->m_baseSpeed = source->m_baseSpeed; + missile->m_position = source->m_position; + missile->m_transportGuid = source->m_transportGuid; + missile->m_impactPos = source->m_impactPos; + missile->m_flags = source->m_flags; + missile->m_attachmentID = source->m_attachmentID; + missile->m_attachOffset = source->m_attachOffset; + missile->m_soundKitID = source->m_soundKitID; + missile->m_hitResult = source->m_hitResult; + missile->m_missReason = source->m_missReason; + missile->m_destroyTime = source->m_destroyTime; + missile->m_victimAnimTime = source->m_victimAnimTime; + missile->m_castTime = source->m_castTime; + missile->m_duration = source->m_duration; + missile->m_currentTarget = source->m_currentTarget; + missile->m_scale = source->m_scale; + missile->m_progress = source->m_progress; + missile->m_horizontalProgress = source->m_horizontalProgress; + missile->m_groundOffset = source->m_groundOffset; + missile->m_followGroundRate = source->m_followGroundRate; + missile->m_followGroundStart = source->m_followGroundStart; + missile->m_motionFlags = source->m_motionFlags; + missile->unk_0110 = source->unk_0110; + missile->unk_0114 = source->unk_0114; + missile->m_motionScriptFunction = source->m_motionScriptFunction; + missile->m_initialDistance = source->m_initialDistance; + missile->m_random[0] = source->m_random[0]; + missile->m_random[1] = source->m_random[1]; + missile->m_random[2] = source->m_random[2]; + missile->m_fizzleTime = source->m_fizzleTime; + missile->m_model = World::s_m2Scene->DuplicateModel(source->m_model, 0); + missile->m_targets.Set(source->m_targets.m_count, source->m_targets.m_data); + missile->m_targetHitResults.Set(source->m_targetHitResults.m_count, source->m_targetHitResults.m_data); + missile->m_targetMissReasons.Set(source->m_targetMissReasons.m_count, source->m_targetMissReasons.m_data); + missile->m_targetPoints.Set(source->m_targetPoints.m_count, source->m_targetPoints.m_data); + return missile; +} + +// VERIFY: f9a1bf6f auto +// OFFSET: 0x00703730 +void CMissile::DeleteSelf() { + if (this->m_missileCollision) { + this->m_missileCollision->Free(); + } + + uint32_t* heap = CMissile::s_missileHeap; + this->~CMissile(); + ObjectFree(*heap, this->m_memHandle); +} + +// VERIFY: 878d0027 auto +// OFFSET: 0x00703770 +void CMissile::RemoveMissiles() { + while (CMissile::s_inFlightMissileList) { + CMissile::s_inFlightMissileList->DeleteSelf(); + } + + while (CMissile::s_missileDestroyList) { + CMissile::s_missileDestroyList->DeleteSelf(); + } +} + +// VERIFY: a8c4a938 manual +// OFFSET: 0x00703810 +int32_t CMissile::WaitForModelFX() { + if (this->m_model && this->m_model->IsLoaded(0, 0) && (this->m_model->m_fFlags & 0x8000)) { + CM2Model* model = this->m_model; + + if (this->m_flags & 0x800000) { + if (this->m_flags & 0x10000000) { + model->unk_017C = 0.0f; + this->m_model->SetEmittersEnabled(0); + this->m_model->SetRibbonsEnabled(0); + this->m_flags &= ~0x10000000; + } + } else { + if (!(this->m_flags & 0x10000000)) { + model->unk_017C = 0.0f; + this->m_model->SetEmittersEnabled(0); + this->m_model->SetRibbonsEnabled(0); + } + + this->m_flags |= 0x800000; + } + + CM2Model* current = this->m_model; + + if (current->m_scene->m_frameStamp - current->m_frameStamp < 2 && (current->HasLiveParticles() || this->m_model->HasLiveRibbons())) { + return 1; + } + } + + this->DeleteSelf(); + return 0; +} + +// VERIFY: ae6a2e34 manual +// OFFSET: 0x00703900 +void CMissile::UpdateAttachments(WOWGUID guid) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + CM2Model* unitModel = unit->m_worldModel; + + for (CMissile* missile = CMissile::s_missileDestroyList; missile; ) { + CMissile* next = missile->m_next; + + if (missile->m_targetGuid == guid && missile->m_model && missile->m_model->m_attachParent) { + if (unitModel && unitModel->IsLoaded(0, 0) && unitModel->HasAttachment(missile->m_attachmentID)) { + missile->m_model->DetachFromParent(); + missile->m_model->AttachToParent(unitModel, missile->m_attachmentID, nullptr, 0); + C44Matrix attach = unitModel->GetAttachmentWorldTransform(missile->m_attachmentID); + C44Matrix world = missile->m_model->m_worldTransform; + missile->m_model->SetWorldTransform(world * attach.AffineInverse(sqrt(attach.a1 * attach.a1 + attach.a2 * attach.a2 + attach.a0 * attach.a0))); + } else { + missile->DeleteSelf(); + } + } + + missile = next; + } +} + +// VERIFY: 22ec6d31 auto +// OFFSET: 0x00703A80 +void CMissile::ClearInFlightMissilesWithTarget(WOWGUID target) { + for (CMissile* missile = CMissile::s_inFlightMissileList; missile; ) { + CMissile* next = missile->m_next; + + if (missile->m_targetGuid == target) { + missile->DeleteSelf(); + } + + missile = next; + } +} + +// VERIFY: d6890537 auto +// OFFSET: 0x00703AE0 +void CMissile::ScriptManagerCallback(uint32_t event) { + if (event == 1) { + CMissile::RemoveMissiles(); + } +} + +// VERIFY: 9611b505 manual +// OFFSET: 0x00700880 +void CMissile::InitializeTrajectory() { + C3Vector impact = this->TransformPositionByTransport(); + C3Vector delta(impact.x - this->m_launchPos.x, impact.y - this->m_launchPos.y, impact.z - this->m_launchPos.z); + float pitch = this->m_pitch; + C3Vector velocity(0.0f, 0.0f, 0.0f); + + if (pitch > 1.5707964f) { + pitch = pitch - (pitch - 1.5707964f) * 2.0f; + } else if (pitch < -1.5707964f) { + pitch = 2.0f * (-1.5707964f - pitch) + pitch; + } + + SpellRec spell; + int32_t hasSpell = g_spellDB.GetRecord(this->m_spellID, &spell); + SpellMissileRec* missile = hasSpell ? g_spellMissileDB.GetRecord(spell.m_spellMissileID) : nullptr; + this->m_gravity = missile ? missile->m_gravity : 19.291105f; + float speed; + int32_t result = SpellUtils_ComputeMissileTrajectory(pitch, &delta, this->m_gravity, &speed, &this->m_travelTime, &velocity); + + if (!result) { + pitch = (this->m_gravity < 0.0f ? -0.0099999998f : 0.0099999998f) + this->m_pitch; + + if (pitch > 1.5707964f) { + pitch = pitch - (pitch - 1.5707964f) * 2.0f; + } else if (pitch < -1.5707964f) { + pitch = 2.0f * (-1.5707964f - pitch) + pitch; + } + + result = SpellUtils_ComputeMissileTrajectory(pitch, &delta, this->m_gravity, &speed, &this->m_travelTime, &velocity); + + if (!result) { + this->m_flags &= ~0x10000; + } + } + + if (result == 1) { + if (hasSpell && missile) { + speed = this->m_trajectorySpeed; + this->m_travelTime = SpellUtils_ComputeMissileTrajectoryTravelTime(pitch, speed, &delta, this->m_gravity); + + if (this->m_travelTime < 0.000099999997f) { + speed = missile->m_defaultSpeedMin; + this->m_travelTime = SpellUtils_ComputeMissileTrajectoryTravelTime(pitch, speed, &delta, this->m_gravity); + + if (this->m_travelTime < 0.000099999997f) { + speed = missile->m_defaultSpeedMax; + this->m_travelTime = SpellUtils_ComputeMissileTrajectoryTravelTime(pitch, speed, &delta, this->m_gravity); + + if (this->m_travelTime < 0.000099999997f) { + this->m_flags &= ~0x10000; + } + } + } + + if (this->m_flags & 0x10000) { + float inv = 1.0f / this->m_travelTime; + velocity = C3Vector(delta.x * inv, delta.y * inv, inv * delta.z); + } + } else { + this->m_flags &= ~0x10000; + } + } + + float remaining = static_cast(this->m_arrivalTime - OsGetAsyncTimeMs()) * 0.001f; + + if (remaining < 0.000099999997f) { + remaining = 0.000099999997f; + } + + if (this->m_flags & 0x10000) { + this->m_velocity = velocity; + this->m_timeScale = this->m_travelTime / remaining; + + if (this->m_timeScale < 0.0f) { + this->m_timeScale = 0.0f; + } else if (this->m_timeScale >= 2.0f) { + this->m_timeScale = 2.0f; + } + } else { + float newSpeed = sqrt(delta.z * delta.z + delta.y * delta.y + delta.x * delta.x) / remaining; + this->m_speed = newSpeed; + this->m_baseSpeed = newSpeed; + } + + if ((this->m_flags & 0x200000) && (missile->m_flags & 0x3C)) { + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(this->m_casterGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + this->m_missileCollision = CMissileCollision::Alloc(); + CGUnit_C* root = caster && caster->m_vehiclePassenger && caster->m_vehiclePassenger->m_transitionVehicleGuid ? caster->m_vehiclePassenger->GetStoredRootVehicleUnit() : caster; + C3Vector end = this->TransformPositionByTransport(); + this->m_missileCollision->Init(&this->m_launchPos, &end, pitch, speed, missile, root); + } +} + +// VERIFY: 859a92cc manual +// OFFSET: 0x00700E20 +void CMissile::HitTargetAreaEffect(const SpellRec* spell, const SpellVisualRec* visual) { + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(this->m_casterGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + SpellVisualKitRec* areaKit = g_spellVisualKitDB.GetRecord(visual->m_impactAreaKit); + + if (areaKit && !this->m_fizzleTime) { + C3Vector position; + WOWGUID transport; + this->ResolveTargetPosition(&position, &transport); + + if (caster) { + PlaySpellVisuaKitData data(spell, areaKit, 3); + data.m_position = &position; + data.m_transportGUID = transport; + data.m_someGUID = this->m_casterGuid; + caster->PlaySpellVisualKit(data); + } else { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + PlaySpellVisuaKitData data(spell, areaKit, 3); + data.m_transportGUID = transport; + data.m_position = &position; + data.m_someGUID = this->m_casterGuid; + data.unk_0018 = 0; + player->PlaySpellVisualKit(data); + } + } + } + + const SpellVisualKitRec* casterKit = Spell_C_GetAppropriateImpactKit(visual, 1); + const SpellVisualKitRec* targetKit = Spell_C_GetAppropriateImpactKit(visual, 0); + SpellVisualKitRec* stateKit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + uint32_t hitResultCount = this->m_targetHitResults.m_count; + + for (uint32_t i = 0; i < this->m_targets.m_count; i++) { + WOWGUID targetGuid; + targetGuid.m_guid = this->m_targets.m_data[i]; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(targetGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + continue; + } + + if (hitResultCount) { + uint32_t result = this->m_targetHitResults.m_data[i]; + + if (result && !(this->m_flags & 0x100) && !this->unk_0110) { + if (spell && !(spell->m_attributes & 0x100)) { + unit->AddWorldText(this->m_casterGuid, result, spell, 0); + CGGameUI::ShowSpellMissFeedback(unit->m_obj->m_guid, result); + } + + UnitCombatLogSpellMissed(this->m_casterGuid, unit->m_obj->m_guid, this->m_spellID, result, 0, 0, 0); + } + } else if (!this->m_fizzleTime) { + const SpellVisualKitRec* kit = unit != caster ? targetKit : casterKit; + + if (kit) { + PlaySpellVisuaKitData data(spell, kit, 1); + data.m_someGUID = this->m_casterGuid; + unit->PlaySpellVisualKit(data); + } + + if (stateKit && unit->m_unit->m_unitFieldHealth > 0 && unit->HasAuraBySpellId(spell->m_id) && (static_cast(stateKit->m_flags) >= 0 || unit->HasAuraActive(spell->m_id))) { + PlaySpellVisuaKitData data(spell, stateKit, 2); + data.m_someGUID = this->m_casterGuid; + unit->PlaySpellVisualKit(data); + } + } + } + + for (uint32_t i = 0; i < this->m_targetPoints.m_count; i++) { + if (!targetKit || !caster) { + continue; + } + + PlaySpellVisuaKitData data(spell, targetKit, 1); + SpellCastTargetPoint* point = &this->m_targetPoints.m_data[i]; + + if (point->m_transport && MovementObjIsTransport(point->m_transport)) { + data.m_transportGUID = point->m_transport; + data.m_position = &point->m_position; + } else { + data.m_transportGUID = WOWGUID(); + data.m_position = &point->m_worldPosition; + } + + caster->PlaySpellVisualKit(data); + } + + if (hitResultCount) { + this->m_flags |= 0x100; + } + + this->BeginWaitingForModelFX(0); +} + +// VERIFY: 72a88afd manual +// OFFSET: 0x00701230 +void CMissile::ComputeModelMatrix(C44Matrix* matrix, const C3Vector* position, const C3Vector* direction) { + matrix->d0 = position->x; + matrix->d1 = position->y; + matrix->d2 = position->z; + + if (this->m_motionScriptFunction != -1) { + if (this->CallMotionScriptFunction(s_msfIO)) { + this->ApplyMotionScriptFunctionTranslation(s_msfIO, *matrix); + } else { + this->m_motionScriptFunction = -1; + } + } + + int32_t animated = 0; + + if (this->m_flags & 0x2000000) { + CM2Model* model = this->m_model; + C3Vector translation(matrix->d0, matrix->d1, matrix->d2); + model->Animate(); + *matrix = model->m_matrixF4 * model->m_scene->m_viewInv; + matrix->d0 = translation.x; + matrix->d1 = translation.y; + matrix->d2 = translation.z; + this->m_flags &= ~0x2000000; + animated = 1; + } else { + bool haveForward = false; + + if (this->m_model && (this->m_flags & 0x800)) { + C3Vector delta(matrix->d0 - this->m_lastModelPos.x, matrix->d1 - this->m_lastModelPos.y, matrix->d2 - this->m_lastModelPos.z); + float length = sqrt(delta.y * delta.y + delta.z * delta.z + delta.x * delta.x); + + if (length > 2.3841858e-7f) { + if (length < 0.0099999998f && (this->m_flags & 0x100000)) { + float weight = length * 100.0f; + + if (weight < 0.050000001f) { + weight = 0.050000001f; + } + + delta *= weight; + delta += this->m_smoothDirection * (1.0f - weight); + length = sqrt(delta.y * delta.y + delta.z * delta.z + delta.x * delta.x); + } + + this->m_smoothDirection = delta; + this->m_flags |= 0x100000; + float inv = 1.0f / length; + matrix->a0 = delta.x * inv; + matrix->a1 = delta.y * inv; + matrix->a2 = inv * delta.z; + haveForward = true; + } + } + + if (!haveForward) { + matrix->a0 = direction->x; + matrix->a1 = direction->y; + matrix->a2 = direction->z; + } + + float forwardX = matrix->a0; + matrix->b0 = -matrix->a1; + matrix->b1 = forwardX; + matrix->b2 = 0.0f; + + if (matrix->b1 * matrix->b1 + matrix->b0 * matrix->b0 > 0.0000099999997f) { + float inv = 1.0f / sqrt(matrix->b0 * matrix->b0 + matrix->b1 * matrix->b1); + matrix->b0 = inv * matrix->b0; + matrix->b1 = inv * matrix->b1; + C2Vector side(matrix->b0, matrix->b1); + matrix->c0 = -(side.y * matrix->a2); + matrix->c1 = side.x * matrix->a2; + matrix->c2 = matrix->a0 * side.y - matrix->a1 * side.x; + } else if (this->m_model && (this->m_flags & 0x800) && (matrix->a0 = direction->x, matrix->a1 = direction->y, matrix->a2 = direction->z, matrix->b0 = -direction->y, matrix->b1 = direction->x, matrix->b2 = 0.0f, matrix->b1 * matrix->b1 + matrix->b0 * matrix->b0 > 0.0000099999997f)) { + C2Vector side(matrix->b0, matrix->b1); + side.Normalize(); + matrix->b0 = side.x; + matrix->b1 = side.y; + C3Vector up = C3Vector(matrix->a0, matrix->a1, matrix->a2) % C2Vector(matrix->b0, matrix->b1); + matrix->c0 = up.x; + matrix->c1 = up.y; + matrix->c2 = up.z; + } else { + matrix->a0 = 0.0f; + matrix->a1 = 0.0f; + matrix->a2 = 1.0f; + matrix->b0 = 1.0f; + matrix->b1 = 0.0f; + matrix->b2 = 0.0f; + matrix->c0 = 0.0f; + matrix->c2 = 0.0f; + matrix->c1 = 1.0f; + } + } + + if (this->m_motionScriptFunction != -1) { + this->ApplyMotionScriptFunctionRotationAndScale(s_msfIO, *matrix); + } + + if (!animated) { + matrix->Scale(this->m_scale); + } +} + +// VERIFY: 4d97ff64 manual +// OFFSET: 0x00702A60 +int32_t CMissile::PossiblyHandleBounce() { + if (!(this->m_flags & 0x200)) { + return 0; + } + + int32_t fired = 0; + uint32_t index = ++this->m_currentTarget; + + if (index < this->m_targets.m_count) { + this->m_targetGuid.m_guid = this->m_targets.m_data[index]; + this->m_flags &= 0xF7FFFA04; + this->FireMissiles(&this->m_position); + fired = 1; + } + + if (this->m_currentTarget >= this->m_targetPoints.m_count) { + return fired; + } + + SpellCastTargetPoint* point = &this->m_targetPoints.m_data[this->m_currentTarget]; + this->m_impactPos = point->m_position; + this->m_transportGuid = point->m_transport; + this->m_flags &= 0xF7FFFA04; + this->FireMissiles(&this->m_position); + return 1; +} + +// VERIFY: 87fb757a manual +// OFFSET: 0x00702DB0 +void CMissile::HitTarget(CGUnit_C* target, const SpellRec* spell, const SpellVisualRec* visual) { + if (target->m_unit->m_unitFieldHealth > 0) { + if (!visual || !(visual->m_flags & 0x40)) { + target->PlayWoundAnimKit(0); + } + } else { + target->PlayDeathAnimation(0); + } + + if (spell && visual && !this->m_fizzleTime) { + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(this->m_casterGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + const SpellVisualKitRec* kit = Spell_C_GetAppropriateImpactKit(visual, target == caster); + C3Vector position(0.0f, 0.0f, 0.0f); + C3Vector* positionPtr = nullptr; + WOWGUID transport = WOWGUID(); + + if (this->m_model && (this->m_flags & 0x8000)) { + position = (this->m_model->m_fFlags & 0x8000) ? this->m_model->GetWorldPosition() : target->GetPosition(); + positionPtr = &position; + } else if ((this->m_motionFlags & 1) && (this->m_motionFlags & 8)) { + C3Vector resolved; + position = *this->ResolveTargetPosition(&resolved, &transport); + positionPtr = &position; + } + + if (kit) { + PlaySpellVisuaKitData data(spell, kit, 1); + data.m_transportGUID = transport; + data.m_someGUID = this->m_casterGuid; + data.m_position = positionPtr; + target->PlaySpellVisualKit(data); + } + + SpellVisualKitRec* stateKit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + + if (stateKit && target->m_unit->m_unitFieldHealth > 0 && target->HasAuraBySpellId(spell->m_id) && (static_cast(stateKit->m_flags) >= 0 || target->HasAuraActive(spell->m_id))) { + PlaySpellVisuaKitData data(spell, stateKit, 2); + data.m_someGUID = this->m_casterGuid; + target->PlaySpellVisualKit(data); + } + } + + if ((this->m_attachmentID == -1 || !target->GetObjectModel() || !(this->m_flags & 4) || !this->AttachToVictim(target, 5000)) && !this->PossiblyHandleBounce()) { + this->BeginWaitingForModelFX(0); + } +} + +// VERIFY: f4431d3e manual +// OFFSET: 0x00703410 +void CMissile::ReachedTarget(CGUnit_C* target, const C3Vector* direction) { + this->m_progress = 1.0f; + this->m_horizontalProgress = 1.0f; + this->m_position = this->TransformPositionByTransport(); + C3Vector dir = *direction; + float length = sqrt(dir.z * dir.z + dir.y * dir.y + dir.x * dir.x); + + if (fabs(length) < 2.3841858e-7f) { + dir = C3Vector(0.0f, 0.0f, 1.0f); + } else { + float inv = 1.0f / length; + dir.x = inv * dir.x; + dir.y = dir.y * inv; + dir.z = inv * dir.z; + } + + if (this->m_model && (this->m_model->m_fFlags & 0x8000)) { + C44Matrix matrix; + this->ComputeModelMatrix(&matrix, &this->m_position, &dir); + CM2Model* model = this->m_model; + model->m_fFlags |= 0x8000; + model->m_worldTransform = matrix; + this->m_lastModelPos = C3Vector(matrix.d0, matrix.d1, matrix.d2); + } + + SI2::StopSound(&this->m_missileSound, 0, 0.15000001f, 1); + this->m_flags &= ~0x10000; + SpellRec spell; + + if (g_spellDB.GetRecord(this->m_spellID, &spell)) { + const SpellVisualRec* visual = GetSpellVisual(&spell); + + if (target) { + if (this->IsHit()) { + this->HitTarget(target, &spell, visual); + return; + } + } else if (visual) { + this->HitTargetAreaEffect(&spell, visual); + return; + } + } else if (target && this->IsHit()) { + this->HitTarget(target, nullptr, nullptr); + return; + } + + this->MissedTarget(target, direction); +} + +// VERIFY: ad9ee4a8 manual +// OFFSET: 0x00703640 +void CMissile::HandleMissileTrajectoryCollision(const C3Vector* direction) { + CDataStore msg; + msg.Put(static_cast(CMSG_UPDATE_PROJECTILE_POSITION)); + msg.Put(this->m_casterGuid.m_guid); + msg.Put(this->m_spellID); + msg.Put(this->m_castID); + msg.Put(this->m_position.x); + msg.Put(this->m_position.y); + msg.Put(this->m_position.z); + msg.Finalize(); + ClientServices::Send2(&msg); + this->m_impactPos = this->m_position; + this->m_transportGuid = WOWGUID(); + this->ReachedTarget(nullptr, direction); +} + +// VERIFY: 95c5a21d manual +// OFFSET: 0x007015D0 +void CMissile::CalcPosition(int32_t advance) { + uint32_t now = OsGetAsyncTimeMs(); + float elapsed = advance ? (now - this->m_lastUpdateTime) * 0.001f : 0.0f; + this->m_lastUpdateTime = now; + + if (0.0f == this->m_speed) { + return; + } + + CGObject_C* object = ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_OBJECT, __FILE__, __LINE__); + CGUnit_C* target = static_cast(object); + int32_t targetIsUnit; + + if (object && (object->m_obj->m_type & TYPEMASK_UNIT)) { + targetIsUnit = 1; + + if (!(this->m_flags & 8)) { + this->UpdateImpactPos(); + } + } else { + targetIsUnit = 0; + } + + if (this->m_victimAnimTime && static_cast(now - this->m_victimAnimTime) >= 0) { + this->m_victimAnimTime = 0; + + if (targetIsUnit) { + uint32_t animId = (this->m_flags & 0x10) ? 24 : 30; + M2SequenceInfo info; + info.Clear(); + target->m_worldModel->GetSequenceInfo(animId, 0, info); + + if (info.m_animId) { + target->PlayBaseAnimation(animId, 0); + } + } + } + + if (this->m_flags & 0x2000) { + this->ApplyTargetTransportOffset(object, &this->m_launchPos, elapsed); + } + + this->ApplyTargetTransportOffset(object, &this->m_position, elapsed); + float step = elapsed * this->m_speed; + C3Vector impact = this->TransformPositionByTransport(); + uint32_t flags = this->m_flags; + C3Vector delta(impact.x - this->m_position.x, impact.y - this->m_position.y, impact.z - this->m_position.z); + uint32_t arrival = this->m_arrivalTime; + float distance = sqrt(delta.y * delta.y + delta.x * delta.x + delta.z * delta.z); + float timeScale = this->m_timeScale; + int32_t timed = (flags & 0x1024000) == 0x20000 && elapsed > 0.0f && this->m_duration > 0.0f; + uint32_t trajectory = flags & 0x10000; + + if (trajectory) { + if (flags & 0x40000) { + float t = this->m_adjustedDuration ? (now - this->m_adjustTime) / static_cast(this->m_adjustedDuration) : 1.0f; + arrival += (this->m_adjustedDuration - (arrival - this->m_adjustTime)) * t; + float targetScale = arrival == this->m_fireTime ? 1.0f : this->m_travelTime / ((arrival - this->m_fireTime) * 0.001f); + timeScale = t * (targetScale - this->m_timeScale) + this->m_timeScale; + } + + if (static_cast(now - arrival) >= 0) { + this->ReachedTarget(targetIsUnit ? target : nullptr, &delta); + return; + } + } else if (timed) { + if (static_cast(now - this->m_fireTime - this->m_duration) >= 0) { + this->ReachedTarget(targetIsUnit ? target : nullptr, &delta); + return; + } + } else if (step >= distance && !(flags & 2)) { + this->ReachedTarget(targetIsUnit ? target : nullptr, &delta); + return; + } + + if (step <= 0.0f && this->m_mapEntity) { + return; + } + + C3Vector dir = delta; + + if (fabs(distance) < 2.3841858e-7f) { + dir = C3Vector(0.0f, 0.0f, 1.0f); + } else { + float inv = 1.0f / distance; + dir.x = delta.x * inv; + dir.y = dir.y * inv; + dir.z = inv * dir.z; + } + + C3Vector previous = this->m_position; + + if (trajectory) { + float total = (arrival - this->m_fireTime) * 0.001f; + float left = 0.001f * (arrival - now); + float t = timeScale * (total - left); + this->m_position.x = this->m_velocity.x * t + this->m_launchPos.x; + this->m_position.y = this->m_velocity.y * t + this->m_launchPos.y; + this->m_position.z = this->m_velocity.z * t + this->m_launchPos.z; + this->m_position.z = this->m_position.z - t * (this->m_gravity * t) * 0.5f; + + if (this->m_flags & 0x1000) { + float progress = 1.0f - left / total; + this->m_progress = progress; + this->m_horizontalProgress = progress; + } + } else if (timed) { + float t = (now - this->m_fireTime) / static_cast(this->m_duration); + this->m_progress = t; + this->m_horizontalProgress = t; + C3Vector target = this->TransformPositionByTransport(); + float keep = 1.0f - this->m_progress; + this->m_position.x = target.x * t + this->m_launchPos.x * keep; + this->m_position.y = target.y * t + this->m_launchPos.y * keep; + this->m_position.z = keep * this->m_launchPos.z + target.z * t; + } else { + if (step > 0.0f) { + if (this->m_flags & 0x4000) { + this->FollowGround(dir, step); + } else { + this->m_position += C3Vector(dir.x * step, dir.y * step, step * dir.z); + } + } + + if (this->m_flags & 0x1000) { + this->UpdateProgress(distance - step); + } + } + + if (this->m_flags & 0x400000) { + float dz = this->m_position.z - this->m_remoteCollisionPos.z; + float dy = this->m_position.y - this->m_remoteCollisionPos.y; + float dx = this->m_position.x - this->m_remoteCollisionPos.x; + float current = dx * dx + dy * dy + dz * dz; + float pz = previous.z - this->m_remoteCollisionPos.z; + float py = previous.y - this->m_remoteCollisionPos.y; + float px = previous.x - this->m_remoteCollisionPos.x; + + if (py * py + pz * pz + px * px < current) { + this->m_impactPos = previous; + this->m_transportGuid = WOWGUID(); + this->ReachedTarget(nullptr, &delta); + return; + } + } + + if (this->m_missileCollision) { + float t = this->m_missileCollision->ComputeSegmentImpactTime(&previous, &this->m_position); + + if (t >= 0.0f) { + this->m_position.x = (this->m_position.x - previous.x) * t + previous.x; + this->m_position.y = (this->m_position.y - previous.y) * t + previous.y; + this->m_position.z = t * (this->m_position.z - previous.z) + previous.z; + this->HandleMissileTrajectoryCollision(&delta); + return; + } + } + + if (this->m_model) { + C44Matrix matrix; + this->ComputeModelMatrix(&matrix, &this->m_position, &dir); + CM2Model* model = this->m_model; + model->m_fFlags |= 0x8000; + model->m_worldTransform = matrix; + this->m_lastModelPos = C3Vector(matrix.d0, matrix.d1, matrix.d2); + + if (this->m_fizzleTime) { + float fade = (this->m_fizzleTime - now) * 0.0020000001f; + this->m_model->m_fadeAlpha = fclamp(fade, 0.0f, 1.0f); + + if (fade <= 0.0f) { + this->BeginWaitingForModelFX(0); + return; + } + } + + if (!this->m_mapEntity && (this->m_model->m_fFlags & 0x8000)) { + this->m_mapEntity = CMap::ObjectCreate(this->m_model, &CGWorldFrame::MissileEnumProc, nullptr, 0, reinterpret_cast(this), 6); + } + + CAaBox box; + CAaSphere sphere; + + if (this->m_model->IsLoaded(0, 0)) { + box = this->m_model->GetBoundingBox(); + sphere = this->m_model->GetBoundingSphere(); + + if ((this->m_flags & 0x90000) == 0x10000) { + for (uint32_t i = 0; ; i++) { + CM2Model* emitterModel = this->m_model; + + if (!(emitterModel->m_fFlags & 1)) { + emitterModel->WaitForLoad(nullptr); + } + + if (i >= emitterModel->m_shared->m_data->m_particles.m_count) { + break; + } + + emitterModel = this->m_model; + + if (!(emitterModel->m_fFlags & 1)) { + emitterModel->WaitForLoad(nullptr); + } + + emitterModel->m_particleEmitters[i]->m_flags |= 0x400000; + } + + this->m_flags |= 0x80000; + } + } + + C3Vector zero(0.0f, 0.0f, 0.0f); + CMap::ObjectUpdate(this->m_mapEntity, matrix, box, sphere, zero, false, 0xFFFFFFFF); + this->m_model->SetAnimating(1); + } + + if (SI2::IsPlaying(&this->m_missileSound)) { + C3Vector position = this->m_model ? this->m_model->GetWorldPosition() : this->m_position; + SI2::Set3DPosition(&this->m_missileSound, &position); + } +} + +// VERIFY: fa72d815 manual +// OFFSET: 0x00702FC0 +void CMissile::MissedTarget(CGUnit_C* target, const C3Vector* direction) { + if (target) { + if (!(this->m_flags & 0x100)) { + SpellRec spell; + + if (g_spellDB.GetRecord(this->m_spellID, &spell) && !(spell.m_attributes & 0x100) && !this->unk_0110) { + target->AddWorldText(this->m_casterGuid, this->GetHitResult(), &spell, 0); + CGGameUI::ShowSpellMissFeedback(target->m_obj->m_guid, this->GetHitResult()); + UnitCombatLogSpellMissed(this->m_casterGuid, target->m_obj->m_guid, this->m_spellID, this->GetHitResult(), 0, 0, 0); + } + + this->m_flags |= 0x100; + } + + if (!(this->m_flags & 0x58)) { + M2SequenceInfo info; + info.Clear(); + target->m_worldModel->GetSequenceInfo(30, 0, info); + + if (info.m_animId) { + target->PlayBaseAnimation(30, 0); + } + } + + uint32_t flags = this->m_flags; + + if (flags & 0x10) { + if (this->AttachToVictim(target, 5000)) { + this->PossiblyHandleBounce(); + return; + } + + if (!this->PossiblyHandleBounce()) { + this->BeginWaitingForModelFX(0); + } + + return; + } + + if (flags & 0x20) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->AddSpecialByPosition(10, this->m_position, &target->m_obj->m_guid, 32, &CGObject_C::EffectOnceHandler); + effect->m_flags |= 0x8000; + C44Matrix matrix = this->m_model ? this->m_model->m_worldTransform : this->GetPositionMatrix(); + effect->m_facing = atan2(matrix.b1, matrix.b0) - 1.5707964f; + effect->Release(); + + if (!this->PossiblyHandleBounce()) { + this->BeginWaitingForModelFX(0); + } + + return; + } + } + + uint32_t flags = this->m_flags; + + if (!(flags & 8)) { + if (flags & 0x40) { + C3Vector dir(-direction->x, -direction->y, -direction->z); + float length = sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z); + + if (fnotequal(length, 0.0f) && fnotequal(length, fabs(dir.z))) { + dir /= length; + C33Matrix first = C33Matrix::Rotation(CRandom::sfloat_(g_rndSeed) * 1.5707964f, dir, true); + C3Vector side(dir.y, -dir.x, 0.0f); + side *= first; + C33Matrix second = C33Matrix::Rotation(CRandom::sfloat_(g_rndSeed) * 1.5707964f, side, false); + dir *= second; + float speed = this->m_speed * 0.5f; + this->m_speed = speed; + this->m_impactPos.x = dir.x * (0.5f * speed) + this->m_position.x; + this->m_impactPos.y = 0.5f * speed * dir.y + this->m_position.y; + this->m_impactPos.z = 0.5f * speed * dir.z + this->m_position.z; + this->m_transportGuid = WOWGUID(); + + if (this->m_model) { + this->m_model->SetBoneSequence(0xFFFFFFFF, 198, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } + + this->m_flags = (this->m_flags & ~0x48) | 8; + this->PossiblyHandleBounce(); + return; + } + } else if (flags & 0x80) { + this->m_targetGuid = this->m_casterGuid; + this->m_flags = (flags & 0xFFFFFA7F) | 0x400; + uint32_t reason = this->GetMissReason(); + this->SetHitResult(reason); + + if (!reason) { + this->m_flags |= 1; + } + + this->FireMissiles(&this->m_position); + return; + } + } + + if (!this->PossiblyHandleBounce()) { + this->BeginWaitingForModelFX(0); + } +} + +// VERIFY: d0f1a70e manual +// OFFSET: 0x007022D0 +void CMissile::FireMissiles(const C3Vector* position) { + if (!this->m_currentTarget) { + this->m_lastUpdateTime = OsGetAsyncTimeMs(); + } + + this->DetermineMissType(); + this->m_launchPos = *position; + this->m_position = *position; + this->Link(&CMissile::s_inFlightMissileList); + + if (this->m_flags & 0x10000) { + this->InitializeTrajectory(); + } + + if (this->m_flags & 0x10) { + this->m_attachmentID = 0; + } + + CGUnit_C* target = static_cast(ClntObjMgrObjectPtr(this->m_targetGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (target && target->m_worldModel && target->m_worldModel->IsLoaded(0, 0)) { + if (!target->m_worldModel->HasAttachment(this->m_attachmentID)) { + if (target->m_worldModel->HasAttachment(15)) { + this->m_attachmentID = 15; + } else { + this->m_attachmentID = target->m_worldModel->HasAttachment(19) ? 19 : -1; + } + } + } else if (!this->m_targetGuid || target) { + this->m_attachmentID = -1; + } else { + if (!this->PossiblyHandleBounce()) { + C3Vector up(1.0f, 0.0f, 0.0f); + this->ReachedTarget(nullptr, &up); + } + + return; + } + + if (!this->m_targetGuid) { + this->m_flags |= 0x20000; + } + + this->m_progress = 0.0f; + this->m_horizontalProgress = 0.0f; + C3Vector impact = this->TransformPositionByTransport(); + C3Vector delta(impact.x - this->m_position.x, impact.y - this->m_position.y, impact.z - this->m_position.z); + this->m_fireTime = OsGetAsyncTimeMs(); + this->m_initialDistance = sqrt(delta.x * delta.x + delta.z * delta.z + delta.y * delta.y); + + uint32_t bits = (CRandom::uint32_(g_rndSeed) & 0x7FFFFF) | 0x3F800000; + this->m_random[0] = *reinterpret_cast(&bits) - 1.0f; + bits = (CRandom::uint32_(g_rndSeed) & 0x7FFFFF) | 0x3F800000; + this->m_random[1] = *reinterpret_cast(&bits) - 1.0f; + bits = (CRandom::uint32_(g_rndSeed) & 0x7FFFFF) | 0x3F800000; + this->m_random[2] = *reinterpret_cast(&bits) - 1.0f; + + this->m_lastModelPos = C3Vector(this->m_position.x - delta.x, this->m_position.y - delta.y, this->m_position.z - delta.z); + this->m_smoothDirection = C3Vector(0.0f, 0.0f, 0.0f); + this->m_flags &= ~0x100000; + this->UpdateImpactPos(); + this->CalcPosition(0); + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_spellID, &spell)) { + return; + } + + SpellVisualRec* visual = g_spellVisualDB.GetRecord(spell.m_spellVisualID[0]); + + if (this->m_model) { + if (this->m_model->m_attachParent) { + this->m_model->DetachFromParent(); + } + + if (spell.m_attributesExE & 0x40000000) { + this->m_model->m_fFlags |= 4; + } + + float distance; + + if (this->m_speed <= 0.0f || this->m_currentTarget) { + distance = this->m_initialDistance; + } else { + float maxSpeed = this->m_speed + this->m_speed; + CGUnit_C* caster = static_cast(ClntObjMgrObjectPtr(this->m_casterGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (visual && visual->m_flags < 0) { + if (caster) { + C3Vector offset = this->TransformPositionByTransport() - this->m_launchPos; + distance = sqrt(offset.z * offset.z + offset.y * offset.y + offset.x * offset.x); + } else { + distance = this->m_initialDistance; + } + } else if (caster) { + C3Vector casterPos = caster->GetPosition(); + C3Vector offset = this->TransformPositionByTransport() - casterPos; + distance = sqrt(offset.z * offset.z + offset.y * offset.y + offset.x * offset.x); + } else { + distance = this->m_initialDistance; + } + + float remainingTime = distance / this->m_speed - static_cast(this->m_fireTime - this->m_castTime) * 0.001f; + float speed; + + if (remainingTime > 0.0f) { + speed = distance / remainingTime; + + if (maxSpeed < speed) { + speed = maxSpeed; + } + } else { + remainingTime = 0.0f; + speed = maxSpeed; + } + + this->m_speed = speed; + this->m_duration = static_cast(static_cast(distance / this->m_speed * 1000.0f)); + + if (target && (this->m_flags & 0x50)) { + uint32_t animId = (this->m_flags & 0x10) ? 24 : 30; + M2SequenceInfo info; + info.Clear(); + target->m_worldModel->GetSequenceInfo(animId, 0, info); + int32_t delay = FloatToInt64(remainingTime * 1000.0f) - (info.m_duration >> 1); + + if (delay <= 0) { + if (info.m_animId) { + target->PlayBaseAnimation(animId, 0); + } + } else { + this->m_victimAnimTime = delay + OsGetAsyncTimeMs(); + } + } + } + + if (!this->m_currentTarget) { + if (this->m_initialDistance <= 0.0f) { + this->m_model->SetBoneSequence(0xFFFFFFFF, 0, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } else { + float speedScale; + M2SequenceInfo info; + + if (this->m_model->IsLoaded(0, 0) && this->m_model->HasSequence(144) && (info.Clear(), this->m_model->GetSequenceInfo(144, 0, info), info.m_flags & 1)) { + speedScale = info.m_duration * this->m_speed * 0.001f / distance; + } else { + speedScale = 1.0f; + } + + this->m_model->SetBoneSequence(0xFFFFFFFF, 144, 0, 0, speedScale, 1, 1); + } + } + } + + this->ClearTargetingEffects(); + + if (visual && visual->m_missileTargetingKit > 0) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_missileTargetingKit); + + if (kit) { + CGUnit_C* unit = target; + + if (unit || (this->m_casterGuid && !this->unk_0110 && (unit = static_cast(ClntObjMgrObjectPtr(this->m_casterGuid, TYPEMASK_UNIT, __FILE__, __LINE__))))) { + this->m_targetingEffectTime = OsGetAsyncTimeMs(); + + if (!target) { + C3Vector targetPos; + WOWGUID transport; + this->ResolveTargetPosition(&targetPos, &transport); + PlaySpellVisuaKitData data(&spell, kit, 7); + data.m_position = &targetPos; + data.m_transportGUID = transport; + data.m_someGUID = this->m_casterGuid; + data.unk_0018 = 0; + data.unk_0030 = this->m_targetingEffectTime; + unit->PlaySpellVisualKit(data); + } else { + PlaySpellVisuaKitData data(&spell, kit, 2); + data.m_someGUID = this->m_casterGuid; + data.unk_0030 = this->m_targetingEffectTime; + unit->PlaySpellVisualKit(data); + } + + this->m_targetingUnit = unit->m_obj->m_guid; + } + } + } + + if (!SI2::IsPlaying(&this->m_missileSound) && this->m_soundKitID) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_fadeInTime = 0.5f; + properties.m_loopMode = 1; + properties.m_noRandomStart = 1; + properties.m_maxAudibleBehavior = 0; + properties.m_streaming = true; + + if (this->m_casterGuid == CGUnit_C::s_activeMover || this->m_targetGuid == CGUnit_C::s_activeMover) { + properties.m_priority = 110; + } + + SI2::PlaySoundKit(this->m_soundKitID, &this->m_position, &this->m_missileSound, &properties, 0, nullptr, 1, 0); + } +} + +// VERIFY: fbab6522 auto +// OFFSET: 0x00703B00 +void CMissile::UpdateStaticLists() { + for (CMissile* missile = CMissile::s_inFlightMissileList; missile; ) { + CMissile* next = missile->m_next; + missile->CalcPosition(CGWorldFrame::s_currentWorldFrame->m_elapsedSec > 0.0f); + + if (missile->m_flags & 8) { + missile->CalcMissFade(); + } + + missile = next; + } + + for (CMissile* missile = CMissile::s_missileDestroyList; missile; ) { + CMissile* next = missile->m_next; + missile->WaitForModelFX(); + missile = next; + } +} + +// VERIFY: 589857c0 auto +// OFFSET: 0x006FF0A0 +void CMissile::InstallMotionScriptFunction(int32_t motionId) { + this->m_motionScriptFunction = CSimpleScriptManager::s_instance->FindFunction(motionId); + + if (this->m_motionScriptFunction != -1) { + return; + } + + SpellMissileMotionRec* motion = g_spellMissileMotionDB.GetRecord(motionId); + + if (!motion) { + return; + } + + SimpleScriptFunctionDesc desc; + desc.m_name = motion->m_name; + desc.m_args = s_msfArgs; + desc.m_stringArgs = nullptr; + desc.m_body = motion->m_scriptBody; + desc.m_returns = s_msfReturns; + desc.m_stringReturns = nullptr; + this->m_motionScriptFunction = CSimpleScriptManager::s_instance->CreateFunction(motionId, desc); +} diff --git a/WoW/Source/Object/ObjectClient/Missile_C.h b/WoW/Source/Object/ObjectClient/Missile_C.h index a5e3afb..5ad3c6c 100644 --- a/WoW/Source/Object/ObjectClient/Missile_C.h +++ b/WoW/Source/Object/ObjectClient/Missile_C.h @@ -7,8 +7,14 @@ #include "Engine/Source/Storm/Source/SLock.h" #include "Engine/Source/Tempest/C3Vector.h" #include "WoW/Source/Object/ObjectClient/Object_C.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" class C44Matrix; +class CGObject_C; +class CGUnit_C; +class CMapEntity; +class CMissileCollision; class CM2Model; struct SimpleScriptIO; @@ -19,11 +25,22 @@ struct MissileCollisionData { /* 000C */ C3Vector m_position; }; +struct ChaserState { + /* 0000 */ C3Vector m_position; + /* 000C */ C3Vector m_velocity; + + void ChaserImplementation(const C3Vector& target, float stiffness, float elapsed); +}; + class CMissile { public: static void UpdateStaticLists(); static void RemoveMissiles(); static CMissile* s_inFlightMissileList; + static CMissile* s_missileDestroyList; + static CMissile* NewMissile(); + static CMissile* CopyMissile(const CMissile* source); + static void ClearInFlightMissilesWithTarget(WOWGUID target); static uint32_t* s_missileHeap; static void AdjustAllMissileTrajectoryDurations(uint8_t castID, uint32_t duration); @@ -41,87 +58,66 @@ class CMissile { /* 001C */ uint32_t m_spellID; /* 0020 */ uint8_t m_castID; /* 0021 */ uint8_t unk_0021[3]; - /* 0024 */ float unk_0024; - /* 0028 */ float unk_0028; - /* 002C */ C3Vector m_launchPos; - /* 0038 */ C3Vector m_position; + /* 0024 */ float m_speed; + /* 0028 */ float m_baseSpeed; + /* 002C */ C3Vector m_position; + /* 0038 */ C3Vector m_launchPos; /* 0044 */ C3Vector m_impactPos; /* 0050 */ C3Vector m_worldImpactPos; - /* 005C */ float unk_005C; - /* 0060 */ float unk_0060; - /* 0064 */ float unk_0064; + /* 005C */ C3Vector m_lastModelPos; /* 0068 */ uint32_t m_flags; /* 006C */ int32_t m_attachmentID; /* 0070 */ C3Vector m_attachOffset; - /* 007C */ uint32_t unk_007C; - /* 0080 */ uint32_t m_missileSound; - /* 0084 */ uint32_t unk_0084; - /* 0088 */ SSyncObject m_syncObject; - /* 008C */ uint32_t unk_008C; - /* 0090 */ float unk_0090; + /* 007C */ int32_t m_soundKitID; + /* 0080 */ SE2SoundKitObject m_missileSound; /* 0094 */ uint32_t m_hitResult; /* 0098 */ uint32_t m_missReason; - /* 009C */ uint32_t unk_009C; - /* 00A0 */ uint32_t unk_00A0; - /* 00A4 */ uint32_t unk_00A4; - /* 00A8 */ uint32_t unk_00A8; - /* 00AC */ uint32_t unk_00AC; - /* 00B0 */ TSGrowableArray m_targetPoints; + /* 009C */ uint32_t m_destroyTime; + /* 00A0 */ TSGrowableArray m_targets; + /* 00B0 */ TSGrowableArray m_targetPoints; /* 00C0 */ TSGrowableArray m_targetHitResults; /* 00D0 */ TSGrowableArray m_targetMissReasons; - /* 00E0 */ uint32_t unk_00E0; - /* 00E4 */ uint32_t unk_00E4; - /* 00E8 */ uint32_t unk_00E8; - /* 00EC */ uint32_t unk_00EC; + /* 00E0 */ uint32_t m_victimAnimTime; + /* 00E4 */ uint32_t m_castTime; + /* 00E8 */ uint32_t m_duration; + /* 00EC */ uint32_t m_lastUpdateTime; /* 00F0 */ uint32_t m_currentTarget; - /* 00F4 */ float unk_00F4; + /* 00F4 */ float m_scale; /* 00F8 */ float m_progress; /* 00FC */ float m_horizontalProgress; - /* 0100 */ float unk_0100; - /* 0104 */ float unk_0104; - /* 0108 */ float unk_0108; - /* 010C */ uint32_t unk_010C; + /* 0100 */ float m_groundOffset; + /* 0104 */ float m_followGroundRate; + /* 0108 */ float m_followGroundStart; + /* 010C */ uint32_t m_motionFlags; /* 0110 */ int32_t unk_0110; /* 0114 */ int32_t unk_0114; - /* 0118 */ uint32_t unk_0118; - /* 011C */ uint32_t m_speed; - /* 0120 */ C3Vector unk_0120; - /* 012C */ uint32_t m_travelTime; - /* 0130 */ float unk_0130; + /* 0118 */ float m_pitch; + /* 011C */ float m_trajectorySpeed; + /* 0120 */ C3Vector m_velocity; + /* 012C */ float m_travelTime; + /* 0130 */ float m_timeScale; /* 0134 */ uint32_t m_arrivalTime; /* 0138 */ uint32_t m_adjustTime; /* 013C */ uint32_t m_adjustedDuration; - /* 0140 */ uint32_t m_gravity; + /* 0140 */ float m_gravity; /* 0144 */ uint32_t m_fizzleTime; - /* 0148 */ uint32_t m_missileCollision; + /* 0148 */ CMissileCollision* m_missileCollision; /* 014C */ C3Vector m_remoteCollisionPos; - /* 0158 */ uint32_t unk_0158; - /* 015C */ uint32_t unk_015C; - /* 0160 */ CMissile* m_prev; + /* 0158 */ CMapEntity* m_mapEntity; + /* 015C */ CMapEntity* m_mapEntity2; + /* 0160 */ CMissile** m_prevLink; /* 0164 */ CMissile* m_next; - /* 0168 */ uint32_t unk_0168; + /* 0168 */ uint32_t m_memHandle; /* 016C */ uint32_t unk_016C; - /* 0170 */ uint32_t unk_0170; - /* 0174 */ uint32_t unk_0174; - /* 0178 */ uint32_t unk_0178; - /* 017C */ int32_t unk_017C; - /* 0180 */ uint32_t unk_0180; - /* 0184 */ float unk_0184; - /* 0188 */ float unk_0188; - /* 018C */ float unk_018C; - /* 0190 */ float unk_0190; - /* 0194 */ float unk_0194; - /* 0198 */ float unk_0198; - /* 019C */ float unk_019C; - /* 01A0 */ float unk_01A0; - /* 01A4 */ float unk_01A4; - /* 01A8 */ float unk_01A8; - /* 01AC */ float unk_01AC; - /* 01B0 */ float unk_01B0; - /* 01B4 */ float unk_01B4; - /* 01B8 */ float unk_01B8; - /* 01BC */ float unk_01BC; - /* 01C0 */ float unk_01C0; + /* 0170 */ WOWGUID m_targetingUnit; + /* 0178 */ uint32_t m_targetingEffectTime; + /* 017C */ int32_t m_motionScriptFunction; + /* 0180 */ uint32_t m_fireTime; + /* 0184 */ float m_initialDistance; + /* 0188 */ float m_random[3]; + /* 0194 */ C3Vector m_smoothDirection; + /* 01A0 */ C3Vector m_lastTransportPos; + /* 01AC */ ChaserState m_transportOffset; /* 01C4 */ uint32_t unk_01C4; void AdjustTrajectoryDuration(uint32_t duration); @@ -136,6 +132,31 @@ class CMissile { void SetRemoteCollisionPos(const C3Vector& position); C3Vector TransformPositionByTransport(); void UpdateProgress(float distance); + CMissile(); + ~CMissile(); + C44Matrix GetPositionMatrix() const; + void BeginWaitingForModelFX(int32_t disableEffects); + int32_t WaitForModelFX(); + C3Vector* ResolveTargetPosition(C3Vector* position, WOWGUID* transport); + void Link(CMissile** link); + int32_t AttachToVictim(CGUnit_C* victim, uint32_t duration); + void ClearTargetingEffects(); + void SetReadyToFire(CMissile** list); + void UpdateImpactPos(); + void CalcMissFade(); + void ApplyTargetTransportOffset(CGObject_C* target, C3Vector* position, float elapsed); + void FollowGround(const C3Vector& direction, float distance); + void FireMissiles(const C3Vector* position); + int32_t PossiblyHandleBounce(); + void HitTarget(CGUnit_C* target, const SpellRec* spell, const SpellVisualRec* visual); + void HitTargetAreaEffect(const SpellRec* spell, const SpellVisualRec* visual); + void MissedTarget(CGUnit_C* target, const C3Vector* direction); + void ReachedTarget(CGUnit_C* target, const C3Vector* direction); + void HandleMissileTrajectoryCollision(const C3Vector* direction); + void ComputeModelMatrix(C44Matrix* matrix, const C3Vector* position, const C3Vector* direction); + void InitializeTrajectory(); + void InstallMotionScriptFunction(int32_t motionId); + void CalcPosition(int32_t advance); void DeleteSelf(); }; diff --git a/WoW/Source/Object/ObjectClient/Object_C.cpp b/WoW/Source/Object/ObjectClient/Object_C.cpp index 47b26c9..34bba0f 100644 --- a/WoW/Source/Object/ObjectClient/Object_C.cpp +++ b/WoW/Source/Object/ObjectClient/Object_C.cpp @@ -35,6 +35,16 @@ #include "WoW/Source/Magic/MagicClient/Spell_C.h" #include #include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/DB/Rec/SpellVisualKitRec.h" +#include "Engine/Source/Os/TimeManager.h" +#include "WoW/Source/Magic/MagicClient/SpellVisuals.h" +#include "WoW/Source/Object/ObjectClient/Movement_C.h" +#include "WoW/Source/Object/MovementShared.h" +#include "WoW/Source/DB/Rec/SpellVisualRec.h" +#include "WoW/Source/DB/Rec/SpellVisualEffectNameRec.h" +#include "WoW/Source/DB/Rec/SpellVisualKitModelAttachRec.h" +#include "WoW/Source/DB/Rec/SpellRec.h" // STATIC: 0x00ADAC98 CGObject_C::InteractIcon CGObject_C::s_interactIcons[12] = { @@ -113,21 +123,6 @@ static int32_t ScaleUpdateHandler(WOWGUID guid, uint32_t fieldOffset, uint32_t f return 1; } -// INLINED -CHashKeyGUID::CHashKeyGUID() { - this->m_guid.m_guid = 0; -} - -// INLINED -CHashKeyGUID::CHashKeyGUID(uint64_t guid) { - this->m_guid.m_guid = guid; -} - -// INLINED -bool CHashKeyGUID::operator==(const CHashKeyGUID& key) { - return this->m_guid == key.m_guid; -} - // VERIFY: 76f8c467 auto // OFFSET: 0x007442E0 void CGObject_C::ModelLoaded(CM2Model* model) { @@ -872,9 +867,9 @@ float CGObject_C::GetSpeed() const { void CGObject_C::PlaySpellVisualKit_PlayAnims(const SpellRec* spell, const SpellVisualKitRec* kit, SPELL_VISUAL_KIT_TYPE type, const C3Vector* position, int32_t a5, int32_t a6, WOWGUID guid, uint32_t a8, const SpellVisualRec* visual, uint32_t a10, int32_t a11) { } -// VERIFY: f1546aca auto +// VERIFY: 6ea82269 auto // OFFSET: 0x00743560 -void CGObject_C::PlaySpellVisualKit_HandleWeapons(const SpellRec* spell, const SpellVisualKitRec* kit, const C3Vector* position, WOWGUID guid, uint32_t a5, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), uint32_t a7, int32_t* a8) { +void CGObject_C::PlaySpellVisualKit_HandleWeapons(const SpellRec* spell, const SpellVisualKitRec* kit, const C3Vector* position, WOWGUID guid, uint32_t a5, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), int32_t* hasEffect) { } // VERIFY: acfa0e6e auto @@ -1427,3 +1422,505 @@ CGObject_C* CGObject_C::GetFocusObject() { CGObject_C* target = ClntObjMgrObjectPtr(WOWGUID{ farSight }, TYPEMASK_OBJECT, __FILE__, __LINE__); return target ? target : object; } + +// VERIFY: bdeb4d6c auto +// OFFSET: 0x00743230 +void CGObject_C::AuraDecayHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param) { + if (!interrupted) { + reinterpret_cast(static_cast(param))->MoveToDestroyList(); + } +} + +// VERIFY: 8bec8c39 auto +// OFFSET: 0x00743250 +void CGObject_C::OnSpellEffectClear(CEffect* effect) { + if (effect->m_model && effect->m_model->IsLoaded(0, 0) && effect->m_model->HasSequence(159)) { + effect->m_flags &= ~0x1000; + effect->m_model->SetBoneSequence(0xFFFFFFFF, 159, 0xFFFFFFFF, 0, 1.0f, 1, 1); + effect->m_model->SetSequenceCallback(reinterpret_cast(&CGObject_C::AuraDecayHandler), reinterpret_cast(effect)); + return; + } + + if (effect->m_flags & 0x40) { + SI2::StopSound(&effect->m_soundKitObject, 0, 0.3f, 1); + } + + effect->MoveToDestroyList(); +} + +// VERIFY: 5c5abd1d auto +// OFFSET: 0x00743580 +void CGObject_C::EffectDecayHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param) { + CEffect* effect = reinterpret_cast(static_cast(param)); + + if (!interrupted && effect) { + effect->MoveToDestroyList(); + } +} + +// VERIFY: 509f8bf8 auto +// OFFSET: 0x00744920 +void CGObject_C::AuraEffectHoldHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param) { + CEffect* effect = reinterpret_cast(static_cast(param)); + + if (interrupted || !effect || !effect->m_model) { + return; + } + + uint32_t endTime = effect->unk_00CC; + + if (endTime && static_cast(OsGetAsyncTimeMs() - endTime) > 0) { + if (effect->m_model->HasSequence(159)) { + effect->m_model->SetSequenceCallback(reinterpret_cast(&CGObject_C::EffectDecayHandler), reinterpret_cast(effect)); + effect->m_model->SetBoneSequence(0xFFFFFFFF, 159, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } else { + effect->MoveToDestroyList(); + } + } else { + effect->m_model->SetBoneSequence(0xFFFFFFFF, sequenceId, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } +} + +// VERIFY: 4c989a64 auto +// OFFSET: 0x007449C0 +void CGObject_C::AuraEffectHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param) { + CEffect* effect = reinterpret_cast(static_cast(param)); + + if (interrupted || !effect || !effect->m_model) { + return; + } + + if (effect->m_kitRec && (effect->m_kitRec->m_flags & 0x20)) { + effect->m_model->SetSequenceCallback(reinterpret_cast(&CGObject_C::AuraEffectHoldHandler), reinterpret_cast(effect)); + effect->m_model->SetBoneSequence(0xFFFFFFFF, 0, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } else if (effect->m_model->HasSequence(158)) { + effect->m_model->SetSequenceCallback(reinterpret_cast(&CGObject_C::AuraEffectHoldHandler), reinterpret_cast(effect)); + effect->m_model->SetBoneSequence(0xFFFFFFFF, 158, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } +} + +// VERIFY: 241a7a4c manual +// OFFSET: 0x00744790 +void CGObject_C::PlayEffectName(int32_t attachType, uint32_t a3, int32_t spellId, const SpellVisualKitRec* kit, const SpellVisualEffectNameRec* effectName, uint32_t* flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), const C3Vector* position, WOWGUID target, uint32_t a11, const SpellVisualKitModelAttachRec* attach) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->unk_00CC = a3; + + WOWGUID source = this->m_obj->m_guid; + + if (!target.m_guid) { + target = this->m_obj->m_guid; + } + + effect->AddEffect(attachType, spellId, kit, effectName, &target, &source, *flags, callback, position, a11, attach); + + if (*flags & 0x40000) { + effect->SetEnabled(0); + } + + if (kit->m_flags & 0x200) { + effect->m_flags |= 0x2000000; + } + + effect->Release(); + *flags = (*flags & ~0x411) | 0x400; +} + +// VERIFY: 82722487 manual +// OFFSET: 0x00745230 +void CGObject_C::PlaySpellVisualKit(const PlaySpellVisuaKitData& data) { + uint32_t flags = 0; + int32_t spellId = 0; + int32_t hasEffect = 0; + + if (data.m_spellRec) { + spellId = data.m_spellRec->m_id; + } + + if (!data.m_impactVisualKit) { + return; + } + + C3Vector transformed = { 0.0f, 0.0f, 0.0f }; + const C3Vector* position = nullptr; + + if (data.m_position) { + if (data.m_transportGUID.m_guid) { + position = &transformed; + C44Matrix transport; + MovementGetTransportMtxX(data.m_transportGUID, &transport, WOWGUID{ 0 }, __FILE__, __LINE__); + transformed = *data.m_position * transport; + } else { + position = data.m_position; + } + } + + void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t) = nullptr; + + if (data.m_impactVisualKit->m_shakeID) { + flags = 0x10; + } + + if (SI2::IsSoundKitLooping(data.m_impactVisualKit->m_soundID)) { + flags |= 0x1; + } + + const SpellRec* spell = data.m_spellRec; + + if (spell && spell->m_spellMissileID > 0) { + flags |= 0x400000; + } + + const SpellVisualRec* visual = spell ? g_spellVisualDB.GetRecord(spell->m_spellVisualID[0]) : nullptr; + + if (this->PlaySpellVisualKit_DelayLightningEffects(spell, data.m_impactVisualKit, static_cast(data.unk_0008), data.m_position, data.m_transportGUID, data.unk_0018, data.unk_001C, data.unk_0020, data.unk_0024, flags, visual)) { + return; + } + + if (visual && (visual->m_flags & 0x10)) { + flags |= 0x200000; + } + + const SpellVisualKitRec* kit = data.m_impactVisualKit; + + if (kit->m_flags & 0xC) { + flags |= 0x1000000; + } + + int32_t animParam = data.unk_0018; + + switch (data.unk_0008) { + case 0: + flags |= 0x80; + callback = &CGObject_C::EffectOnceHandler; + flags = (flags & ~0x21) | 0x20; + break; + + case 1: + case 5: + case 6: + case 8: + callback = &CGObject_C::EffectOnceHandler; + flags = (flags & ~0x21) | 0x20; + break; + + case 2: + flags |= 0x21000; + callback = &CGObject_C::AuraEffectHandler; + + if (spell) { + if (spell->m_effectAura[0] == 78) { + flags |= 0x800000; + } + + if (spell->m_effectAura[1] == 78) { + flags |= 0x800000; + } + + if (spell->m_effectAura[2] == 78) { + flags |= 0x800000; + } + } + + break; + + case 3: + if (spell) { + callback = &CGObject_C::EffectOnceHandler; + flags = (flags & ~0x21) | 0x20; + } + + animParam = 0; + flags |= 0x22000; + break; + + case 4: + callback = &CGObject_C::LoopEffectHandler; + flags |= 0x40; + break; + + case 7: + if (spell) { + callback = &CGObject_C::LoopEffectHandler; + } + + flags |= 0x22000; + break; + + default: + break; + } + + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(kit->m_headEffect); + + if (effectName) { + this->PlayEffectName(20, 0, spellId, kit, effectName, &flags, callback, position, data.m_someGUID, 0, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_worldEffect); + + if (effectName) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->unk_00CC = 0; + + if (data.m_spellRec && !data.m_position) { + for (uint32_t i = 0; i < 3; i++) { + if (data.m_spellRec->m_effectAura[i] == 26) { + flags |= 0x4000; + break; + } + } + } + + WOWGUID transport = data.m_transportGUID; + C3Vector objectPosition = { 0.0f, 0.0f, 0.0f }; + + if (!data.m_position) { + flags |= 0x200; + objectPosition = this->GetRawPosition(); + transport.m_guid = this->GetTransportGUID(); + + if ((this->m_obj->m_type & 0x8) && (static_cast(this)->m_movement->m_flags & 0x40000000)) { + objectPosition.z -= static_cast(this)->m_unit->m_unitFieldHoverheight; + } + } + + WOWGUID guid = this->m_obj->m_guid; + const C3Vector* effectPosition = data.m_position ? data.m_position : &objectPosition; + effect->InitFromUnit(*effectPosition, OsGetAsyncTimeMs(), spellId, data.m_impactVisualKit, effectName, &guid, flags, callback, data.unk_0030, nullptr, transport); + effect->Release(); + flags = (flags & ~0x411) | 0x400; + hasEffect = 1; + } + + if (flags & 0x2000) { + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_baseEffect); + + if (!effectName || !data.m_position) { + goto attachments; + } + + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->unk_00CC = 0; + WOWGUID guid = this->m_obj->m_guid; + effect->InitFromUnit(*data.m_position, OsGetAsyncTimeMs(), spellId, data.m_impactVisualKit, effectName, &guid, flags, callback, data.unk_0030, nullptr, data.m_transportGUID); + effect->Release(); + flags = (flags & ~0x411) | 0x400; + } else { + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_baseEffect); + + if (effectName) { + this->PlayEffectName(19, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_leftHandEffect); + + if (effectName) { + this->PlayEffectName(21, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_rightHandEffect); + + if (effectName) { + this->PlayEffectName(22, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_breathEffect); + + if (effectName) { + this->PlayEffectName(17, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_chestEffect); + + if (effectName) { + this->PlayEffectName(34, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + this->PlaySpellVisualKit_HandleWeapons(data.m_spellRec, data.m_impactVisualKit, position, data.m_someGUID, data.unk_0030, flags, callback, &hasEffect); + + const SpellVisualKitRec* special = data.m_impactVisualKit; + effectName = g_spellVisualEffectNameDB.GetRecord(special->m_specialEffect[0]); + + if (effectName) { + this->PlayEffectName(23, 0, spellId, special, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_specialEffect[1]); + + if (effectName) { + this->PlayEffectName(24, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, position, data.m_someGUID, data.unk_0030, nullptr); + hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(data.m_impactVisualKit->m_specialEffect[2]); + + if (!effectName) { + goto attachments; + } + + this->PlayEffectName(25, 0, spellId, data.m_impactVisualKit, effectName, &flags, callback, data.m_position, data.m_someGUID, data.unk_0030, nullptr); + } + + hasEffect = 1; + +attachments: + int32_t attachCount = SpellVisualsGetModelAttachRecCount(data.m_impactVisualKit->m_id); + + for (int32_t i = 0; i < attachCount; i++) { + const SpellVisualKitModelAttachRec* attach = SpellVisualsGetModelAttachRec(data.m_impactVisualKit->m_id, i); + SpellVisualEffectNameRec* attachEffect = attach ? g_spellVisualEffectNameDB.GetRecord(attach->m_spellVisualEffectNameID) : nullptr; + + if (!attachEffect) { + continue; + } + + if (flags & 0x2000) { + if (!data.m_position) { + continue; + } + + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->unk_00CC = 0; + WOWGUID guid = this->m_obj->m_guid; + effect->InitFromUnit(*data.m_position, OsGetAsyncTimeMs(), spellId, data.m_impactVisualKit, attachEffect, &guid, flags, callback, data.unk_0030, attach, data.m_transportGUID); + effect->Release(); + flags = (flags & ~0x411) | 0x400; + } else if (attach->m_attachmentID == -1) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->unk_00CC = 0; + + if (data.m_spellRec && !data.m_position) { + for (uint32_t j = 0; j < 3; j++) { + if (data.m_spellRec->m_effectAura[j] == 26) { + flags |= 0x4000; + break; + } + } + } + + WOWGUID transport = data.m_transportGUID; + C3Vector objectPosition = { 0.0f, 0.0f, 0.0f }; + + if (!data.m_position) { + flags |= 0x200; + objectPosition = this->GetRawPosition(); + transport.m_guid = this->GetTransportGUID(); + + if ((this->m_obj->m_type & 0x8) && (static_cast(this)->m_movement->m_flags & 0x40000000)) { + objectPosition.z -= static_cast(this)->m_unit->m_unitFieldHoverheight; + } + } + + WOWGUID guid = this->m_obj->m_guid; + const C3Vector* effectPosition = data.m_position ? data.m_position : &objectPosition; + effect->InitFromUnit(*effectPosition, OsGetAsyncTimeMs(), spellId, data.m_impactVisualKit, attachEffect, &guid, flags, callback, data.unk_0030, attach, transport); + effect->Release(); + flags = (flags & ~0x411) | 0x400; + } else { + this->PlayEffectName(attach->m_attachmentID, 0, spellId, data.m_impactVisualKit, attachEffect, &flags, callback, position, data.m_someGUID, data.unk_0030, attach); + } + + hasEffect = 1; + } + + this->PlaySpellVisualKit_PlayAnims(data.m_spellRec, data.m_impactVisualKit, static_cast(data.unk_0008), position, animParam, data.unk_001C, data.m_someGUID, data.unk_0030, visual, flags, hasEffect); +} + +// VERIFY: 1d3e05cf auto +// OFFSET: 0x00744870 +void CGObject_C::EffectOnceHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param) { + CEffect* effect = reinterpret_cast(static_cast(param)); + + if (interrupted || !effect) { + return; + } + + if (effect->m_model && effect->m_model->HasSequence(159)) { + effect->m_model->SetSequenceCallback(reinterpret_cast(&CGObject_C::EffectDecayHandler), reinterpret_cast(effect)); + effect->m_model->SetBoneSequence(0xFFFFFFFF, 159, 0xFFFFFFFF, 0, 1.0f, 1, 1); + return; + } + + M2BoneSequenceInfo info; + effect->m_model->GetBoneSequenceInfo(boneId, info); + effect->m_model->SetBoneSequenceTime(boneId, info.m_endTime - info.m_startTime - 1); + uint32_t sceneTime = effect->m_model->m_scene->m_time; + + if (!sceneTime) { + sceneTime = 1; + } + + effect->m_model->m_lastAnimTime = sceneTime; + effect->MoveToDestroyList(); +} + +// VERIFY: 211f8e2d auto +// OFFSET: 0x00744BD0 +void CGObject_C::ClearEffectKit(int32_t spellId, int32_t kitType, int32_t a4, int32_t a5, int32_t a6) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + SpellVisualRec visualRec; + const SpellVisualRec* visual = this->GetAppropriateSpellVisual(&spell, visualRec, 0, 0); + + if (!visual) { + return; + } + + SpellVisualKitRec* kit; + + switch (kitType) { + case 0: + kit = g_spellVisualKitDB.GetRecord(visual->m_castKit); + break; + case 1: + kit = g_spellVisualKitDB.GetRecord(visual->m_impactKit); + break; + case 2: + kit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + break; + case 4: + kit = g_spellVisualKitDB.GetRecord(visual->m_precastKit); + break; + case 5: + kit = g_spellVisualKitDB.GetRecord(visual->m_casterImpactKit); + break; + case 6: + kit = g_spellVisualKitDB.GetRecord(visual->m_targetImpactKit); + break; + case 7: + kit = g_spellVisualKitDB.GetRecord(visual->m_missileTargetingKit); + break; + case 8: + kit = g_spellVisualKitDB.GetRecord(visual->m_stateDoneKit); + break; + default: + return; + } + + if (!kit) { + return; + } + + CEffect* effect = this->m_effectList; + + while (effect) { + CEffect* next = effect->m_next; + + if (effect->m_kitRec && effect->m_kitRec->m_id == kit->m_id && (!a5 || effect->m_spellId == static_cast(spellId)) && (!a6 || effect->unk_00A0 == static_cast(a4))) { + effect->MoveToDestroyList(); + } + + effect = next; + } +} diff --git a/WoW/Source/Object/ObjectClient/Object_C.h b/WoW/Source/Object/ObjectClient/Object_C.h index 459a42f..0877abc 100644 --- a/WoW/Source/Object/ObjectClient/Object_C.h +++ b/WoW/Source/Object/ObjectClient/Object_C.h @@ -29,6 +29,8 @@ class CPassenger; class PLAYERNAMEDESC; class SpellRec; class SpellVisualKitRec; +class SpellVisualEffectNameRec; +class SpellVisualKitModelAttachRec; class SpellVisualRec; enum OUT_OF_RANGE_TYPE : int32_t; enum SPELL_VISUAL_KIT_TYPE : int32_t; @@ -42,6 +44,21 @@ class CHashKeyGUID { bool operator==(const CHashKeyGUID& key); }; +// INLINED +inline CHashKeyGUID::CHashKeyGUID() { + this->m_guid.m_guid = 0; +} + +// INLINED +inline CHashKeyGUID::CHashKeyGUID(uint64_t guid) { + this->m_guid.m_guid = guid; +} + +// INLINED +inline bool CHashKeyGUID::operator==(const CHashKeyGUID& key) { + return this->m_guid == key.m_guid; +} + class CGObject_C : public CGObject, public TSHashObject { public: struct InteractIcon { @@ -65,6 +82,10 @@ class CGObject_C : public CGObject, public TSHashObject m_link; /* 0040 */ uint32_t m_disableTime; @@ -154,7 +175,7 @@ class CGObject_C : public CGObject, public TSHashObject(s_giftWrapItem); } -// VERIFY: 4cbc468b auto +// VERIFY: 58af1e18 auto // OFFSET: 0x006CF240 -PlaySpellVisuaKitData::PlaySpellVisuaKitData(SpellRec* spellRec, SpellVisualKitRec* impactVisualKit, uint32_t a4) { +PlaySpellVisuaKitData::PlaySpellVisuaKitData(const SpellRec* spellRec, const SpellVisualKitRec* impactVisualKit, uint32_t a4) { this->m_spellRec = spellRec; this->unk_0008 = a4; this->m_impactVisualKit = impactVisualKit; @@ -6232,3 +6250,1862 @@ int32_t __stdcall CGPlayer_C::OnQuestGiverQuestComplete(CDataStore* msg) { return 1; } + +// VERIFY: 6f6228c3 manual +// OFFSET: 0x00518B30 +uint32_t CGItem::GetEnchantmentId(int32_t slot) { + if (this->GetItemStaticFlags(0) & 0x2000) { + return 0; + } + + return this->m_item->m_itemFieldEnchantment[slot].m_id; +} + +// VERIFY: 970a6a97 manual +// OFFSET: 0x005E8290 +uint32_t CGItem::GetEnchantmentDuration(int32_t slot) { + if (this->GetItemStaticFlags(0) & 0x2000) { + return 0; + } + + return this->m_item->m_itemFieldEnchantment[slot].m_duration; +} + +// VERIFY: 1b68385f auto +// OFFSET: 0x006D7B30 +void CGPlayer_C::CastRandomCritter() { + uint32_t count = this->m_companionSpells.m_count; + + if (count) { + Spell_C::CastSpell(this->m_companionSpells.m_data[rand() % count], nullptr, WOWGUID{ 0 }, false); + } +} + +// VERIFY: f9b626f7 manual +// OFFSET: 0x006D7320 +int32_t ClientPlaySpellVisualHandler(WOWGUID guid, void* param) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && unit->IsHostileCritter()) { + const SpellRec* spell = static_cast(param); + + if (!spell) { + SErrDisplayAppFatalMessage("", "", 0); + } + + const SpellVisualRec* visual = GetSpellVisual(spell); + + if (visual) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_targetImpactKit); + + if (kit) { + PlaySpellVisuaKitData data(spell, kit, 6); + unit->PlaySpellVisualKit(data); + } + } + } + + return 1; +} + +// VERIFY: 27cd2fc0 auto +// OFFSET: 0x006D73B0 +void EnumVisibleForAuraEffect(const SpellRec* spell, int32_t a2, int32_t a3) { + s_unk_C9EAB0 = a2; + s_unk_C9EAB4 = a2 ? a3 : 0; + ClntObjMgrEnumVisibleObjects(ClientPlaySpellVisualHandler, const_cast(spell)); +} + +// VERIFY: 8d94fa79 auto +// OFFSET: 0x006D7490 +void CGPlayer_C::UpdateXRayVision(const SpellRec* spell) { + ClntObjMgrEnumVisibleObjects(CGPlayer_C::XRayVisionEffectProc, const_cast(spell)); +} + +// VERIFY: 371bd036 manual +// OFFSET: 0x006D1C30 +int32_t OnUpdatePlayerOverrideSpellsID(WOWGUID guid, uint32_t offset, uint32_t count, const void* value, void* param) { + if (ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)) { + CGSpellBook::UpdateUsable(); + CGSpellBook::UpdateSelection(); + CGActionBar::UpdateOverrideSpellBar(); + CGActionBar::UpdateBonusBar(); + } + + return 1; +} + +// VERIFY: ad8b210c manual +// OFFSET: 0x006DA770 +int32_t OnUpdatePlayerAuraVision(WOWGUID guid, uint32_t offset, uint32_t count, const void* value, void* param) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + uint8_t changed = *static_cast(value) ^ reinterpret_cast(&player->m_player->m_playerFieldBytes2)[3]; + + if (changed & 0x40) { + CGWorldFrame::UpdateScreenEffect(); + } + + ClntObjMgrEnumVisibleObjects(AuraVisionUpdateHandler, &changed); + } + + return 1; +} + +// VERIFY: 5071e977 manual +// OFFSET: 0x006E71D0 +void CGPlayer_C::DelKnownSpell(int32_t spellId, int32_t a3) { + if (spellId > g_spellDB.m_maxID) { + SysMsgPrintf(STATUS_ERROR, 2, "NOSPELLIDFOUND|%d", spellId); + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + bool notify = a3 == 0; + + if (spell.m_attributes & 0x20) { + SkillLineAbilityRec* ability = SpellTableLookupAbility(this->m_unit->m_unitFieldBytes0[0], this->m_unit->m_unitFieldBytes0[1], spellId); + SkillLineRec* skillLine = ability ? g_skillLineDB.GetRecord(ability->m_skillLine) : nullptr; + + if (skillLine) { + HASHKEY_NONE key; + TRADESKILLLINE* line = this->m_tradeSkillLines.Ptr(skillLine->m_id, key); + + if (line) { + for (uint32_t i = line->m_spells.m_count; i; ) { + i--; + + if (line->m_spells.m_data[i] == spellId) { + uint32_t last = line->m_spells.m_count - 1; + + if (i < last) { + memcpy(&line->m_spells.m_data[i], &line->m_spells.m_data[i + 1], sizeof(int32_t) * (last - i)); + } + + line->m_spells.SetCount(last); + CGTradeSkillInfo::RefreshList(1); + break; + } + } + } + } + } else { + if (spell.m_effect[0] == 155) { + this->RemoveEquipBypassSkill(spellId); + } + + if (notify && !(spell.m_attributes & 0x80)) { + if (*spell.m_nameSubtext) { + char text[512]; + SStrPrintf(text, sizeof(text), "%s (%s)", spell.m_name, spell.m_nameSubtext); + CGGameUI::DisplayError(ERR_SPELL_UNLEARNED_S, text); + } else { + CGGameUI::DisplayError(ERR_SPELL_UNLEARNED_S, spell.m_name); + } + } + } + + CGSpellBook::DelKnownSpell(spellId, 0); + CGActionBar::RemoveMacro(spellId); + + if (!a3) { + CGClassTrainer::RefreshList(); + } + + if (spellId == s_dualWieldSpell) { + s_dualWieldSpell = 0; + } + + if (spellId == CGGameUI::GetCursorSpell()) { + CGGameUI::DropCursorSpell(); + } +} + +// VERIFY: 332a79d2 manual +// OFFSET: 0x006E22C0 +void CGPlayer_C::RemoveEquipBypassSkill(int32_t spellId) { + bool found = false; + + for (uint32_t i = 0; i < this->m_equipBypassSkills.m_count; i++) { + if (this->m_equipBypassSkills.m_data[i] == spellId) { + found = true; + } else if (!found) { + continue; + } + + uint32_t count = this->m_equipBypassSkills.m_count; + + if (i) { + if (i < count - 1) { + this->m_equipBypassSkills.m_data[i - 1] = this->m_equipBypassSkills.m_data[i]; + } + + if (i == this->m_equipBypassSkills.m_count - 1) { + this->m_equipBypassSkills.SetCount(i); + } + } else if (count == 1) { + this->m_equipBypassSkills.m_count = 0; + } + } +} + +// VERIFY: 0cc2c313 manual +// OFFSET: 0x006CDF30 +static void ReadInspectItems(CDataStore* msg) { + if (!s_inspectData) { + return; + } + + memset(s_inspectData->m_items, 0, sizeof(s_inspectData->m_items)); + uint32_t mask = 0; + msg->Get(mask); + + for (uint32_t i = 0; i < 19; i++, mask >>= 1) { + if (!(mask & 1)) { + continue; + } + + InspectItem* item = &s_inspectData->m_items[i]; + int32_t itemId = 0; + msg->Get(reinterpret_cast(itemId)); + + if (itemId < 0) { + item->m_flags |= 1; + itemId = -itemId; + } + + item->m_itemId = itemId; + uint16_t enchantMask = 0; + msg->Get(enchantMask); + int32_t* enchant = item->m_enchants; + + for (uint32_t bits = enchantMask; bits; bits >>= 1, enchant++) { + if (bits & 1) { + uint16_t enchantId = 0; + msg->Get(enchantId); + *enchant = enchantId; + } + } + + uint16_t randomPropertiesId = 0; + msg->Get(randomPropertiesId); + item->m_randomPropertiesId = randomPropertiesId; + SmartGUID creator; + *msg >> creator; + item->m_creator = creator; + uint32_t seed = 0; + msg->Get(seed); + item->m_propertySeed = seed; + } +} + +// VERIFY: 70ae18be auto +// OFFSET: 0x006CE070 +int32_t Packet_SMSG_INSPECT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + + if (guid == CGCharacterInfo::m_inspectTarget) { + ReadInspectItems(msg); + } else { + msg->m_read = msg->m_size; + } + + return 1; +} + +// VERIFY: 9cb6b1b5 manual +// OFFSET: 0x006CE0C0 +int32_t Packet_SMSG_INSPECT_TALENT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + + if (guid == CGCharacterInfo::m_inspectTarget) { + CGTalentInfo_Inspect::UpdateTalentData(msg); + FrameScript_SignalEvent(SCRIPT_EVENT_INSPECT_TALENT_READY, nullptr); + + if (!s_inspectData) { + s_inspectData = static_cast(SMemAlloc(sizeof(InspectData), __FILE__, __LINE__, 0)); + } + + s_inspectData->m_guid = guid; + ReadInspectItems(msg); + } + + return 1; +} + +// VERIFY: 7c69ee68 auto +// OFFSET: 0x006CF2A0 +void CGPlayer_C::ExitAutoCombatMode() { + Spell_C_SetAutoRangedCombatSpell(0); + EventUnregister(EVENT_ID_IDLE, CGPlayer_C::AutoCombatModeEventHandler); + this->m_combatModeFlags &= ~0xEu; + CGGameUI::UpdateCombatMode(); +} + +// VERIFY: 3148365b manual +// OFFSET: 0x006D5F70 +void CGPlayer_C::MeleeModeLeave() { + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer() && (this->CGUnit_C::IsInMelee() || this->m_combat.m_attackSent)) { + this->StopAttack(); + Spell_C_CancelMeleeSpells(); + } +} + +// VERIFY: 46257142 manual +// OFFSET: 0x006E2610 +void CGPlayer_C::MeleeModeEnter(const WOWGUID& target) { + if (!CGGameUI::CanPerformAction(1)) { + return; + } + + if (this->m_obj->m_guid != ClntObjMgrGetActivePlayer() || (this->m_unit->m_unitFieldFlags & 0x20000)) { + return; + } + + if (!CGGameUI::m_hasControl || (this->m_player->m_playerFlags & 0x1000000)) { + return; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + if (!this->CanAttackNow(unit)) { + if (this->CGUnit_C::IsInMelee()) { + this->SetCombatMode(); + } + + return; + } + + int16_t overrideId = static_cast(this->m_player->m_playerFieldBytes2); + OverrideSpellDataRec* overrideRec; + + if (overrideId && (overrideRec = g_overrideSpellDataDB.GetRecord(overrideId)) && !(overrideRec->m_flags & 2)) { + return; + } + + if (this->IsVehiclePassengerSeated()) { + WOWGUID transport; + transport.m_guid = this->GetTransportGUID(); + CGUnit_C* vehicle = static_cast(ClntObjMgrObjectPtr(transport, TYPEMASK_UNIT, __FILE__, __LINE__)); + VehicleSeatRec* seat; + + if (!vehicle || !(seat = vehicle->GetVehicleSeatRec(this->m_movementData.m_transportSeat)) || !(seat->m_flags & 0x4000)) { + return; + } + } + + Spell_C_CancelRangedSpells(); + + if (this->m_unit->m_unitFieldBytes1[0]) { + this->ChangeStandState(0); + } + + CGGameUI::Target(unit->m_obj->m_guid); + WOWGUID self = this->m_obj->m_guid; + + if (Spell_C_IsCastingInterruptedByCombat(self) && !this->m_combat.m_attacking) { + return; + } + + if (this->m_stopAttackSent || (!this->m_combat.m_attacking && !this->m_combat.m_attackSent)) { + CDataStore msg; + msg.Put(static_cast(CMSG_ATTACK_SWING)); + msg.Put(unit->m_obj->m_guid.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + this->m_combat.SetAttackSent(unit->m_obj->m_guid); + } + + this->SetSheatheState(1, 1, 0); + Spell_C_SetAutoRangedCombatSpell(0); + this->SpellInterrupted(this->m_castCount, this->m_castSpellId); + Spell_C_CancelAutoRepeat(true); + Spell_C_ClearLastAutoRangedCombatError(); +} + +// VERIFY: d5f87a32 manual +// OFFSET: 0x006E2BE0 +int32_t CGPlayer_C::AutoCombatModeEventHandler(const void* data, void* param) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return 1; + } + + CGUnit_C* target = static_cast(ClntObjMgrObjectPtr(CGGameUI::m_lockedTarget, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!target) { + return 1; + } + + if (!s_cvAutoRangedCombat->m_intValue || !CGSpellBook::m_autoRangedSpell) { + Spell_C_SetAutoRangedCombatSpell(0); + return 1; + } + + if (player->IsInMeleeRange(target)) { + if (!player->CGUnit_C::IsInMelee()) { + WOWGUID guid = target->m_obj->m_guid; + player->MeleeModeEnter(guid); + } + + player->m_combatModeFlags &= ~4u; + return 1; + } + + if (Spell_C_GetAutoRepeatingSpell()) { + return 1; + } + + if (!player->CanAttackNow(target)) { + player->SetCombatMode(); + return 1; + } + + if (player->m_combatModeFlags & 8) { + player->ExitAutoCombatMode(); + return 1; + } + + C3Vector toTarget = target->GetPosition() - player->GetPosition(); + float minRange; + float maxRange; + Spell_C::GetSpellRange(player, CGSpellBook::m_autoRangedSpell, &minRange, &maxRange, target); + float distanceSq = toTarget.y * toTarget.y + toTarget.z * toTarget.z + toTarget.x * toTarget.x; + + if (minRange * minRange < distanceSq || !player->CGUnit_C::IsInMelee()) { + if (player->CGUnit_C::IsInMelee()) { + player->MeleeModeLeave(); + } + + if (!Spell_C_GetAutoRangedCombatSpell()) { + Spell_C_SetAutoRangedCombatSpell(CGSpellBook::m_autoRangedSpell); + player->m_combatModeFlags |= 4; + } + + C3Vector direction = player->m_movementData.GetDirection(); + + if (direction.y * toTarget.y + direction.z * toTarget.z + direction.x * toTarget.x > 0.0f && !(player->m_movement->m_flags & 0x33) && maxRange * maxRange > distanceSq && Spell_C::CastSpell(CGSpellBook::m_autoRangedSpell, nullptr, target->m_obj->m_guid, false)) { + Spell_C_ClearLastAutoRangedCombatError(); + } + } + + return 1; +} + +// VERIFY: b36390c6 auto +// OFFSET: 0x006D66E0 +void CGPlayer_C::OnLevelChange() { + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGSpellBook::UpdateSpells(0, 0, 0); + CGClassTrainer::RefreshList(); + CGUnit_C::NamePlateUpdateLevels(true); + FrameScript_SignalEvent(SCRIPT_EVENT_PVPQUEUE_ANYWHERE_UPDATE_AVAILABLE, nullptr); + } +} + +// VERIFY: a8506f00 auto +// OFFSET: 0x006CDDB0 +int32_t SkillMaxRankChangeHandler(WOWGUID guid, uint32_t offset, uint32_t count, const void* value, void* param) { + CGClassTrainer::RefreshList(); + CGTradeSkillInfo::RefreshList(0); + PlayerSignalSkillStatChanges(); + return 1; +} + +// STATIC: 0x00C9D340 +static PlayerLootItem s_lootItems[18]; + +// VERIFY: 9e4784c1 auto +// OFFSET: 0x006CEB80 +int32_t CGPlayer_C::GetLootItem(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_itemId; +} + +// VERIFY: b65d7e62 auto +// OFFSET: 0x006CEBB0 +int32_t CGPlayer_C::GetLootItemDisplayId(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_displayId; +} + +// VERIFY: dcfad75c auto +// OFFSET: 0x006CEBE0 +int32_t CGPlayer_C::GetLootItemCount(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_count; +} + +// VERIFY: 5618845f auto +// OFFSET: 0x006CEC10 +int32_t CGPlayer_C::GetLootItemRandomSuffix(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_randomSuffix; +} + +// VERIFY: 44db345a auto +// OFFSET: 0x006CEC40 +int32_t CGPlayer_C::GetLootItemRandomPropertyId(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_randomPropertyId; +} + +// VERIFY: ad884501 auto +// OFFSET: 0x006CEC70 +int32_t CGPlayer_C::GetLootItemSlotType(uint32_t slot) { + if (slot >= 18) { + SErrDisplayAppFatalMessage("", "", 0); + } + + return s_lootItems[slot].m_slotType; +} + +// VERIFY: 6d310e19 auto +// OFFSET: 0x006CECA0 +int32_t __stdcall CGPlayer_C::OnLootMoneyNotify(CDataStore* msg) { + uint32_t amount; + uint8_t alone; + msg->Get(amount); + msg->Get(alone); + + if (amount) { + char money[1024]; + GetCurrencyText(amount, money, sizeof(money), ", "); + char text[3000]; + SStrPrintf(text, sizeof(text), FrameScript_GetText(alone ? "YOU_LOOT_MONEY" : "LOOT_MONEY_SPLIT", -1, GENDER_NOT_APPLICABLE), money); + CGChat::AddChatMessage(text, 28, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + } + + return 1; +} + +// VERIFY: aaf305cc auto +// OFFSET: 0x006CEDD0 +void CGPlayer_C::ClearLootingObject() { + this->m_lootTarget = WOWGUID(); + this->UpdateBaseAnimation(0, -1); +} + +// VERIFY: 5787f2d9 manual +// OFFSET: 0x006D53B0 +int32_t CGPlayer_C::OnLootResponse(uint32_t time, CDataStore* msg) { + WOWGUID guid; + uint8_t lootType; + msg->Get(guid.m_guid); + msg->Get(lootType); + + if (!this->m_lootTarget || this->m_lootTarget != guid) { + if (this->m_lootTarget || (lootType != 2 && lootType != 3 && lootType != 4 && lootType != 6 && lootType != 7 && lootType != 8)) { + if (lootType) { + CDataStore release; + release.Put(static_cast(CMSG_LOOT_RELEASE)); + release.Put(guid.m_guid); + release.Finalize(); + ClientServices::Send2(&release); + } else if (msg->m_size != msg->m_read) { + uint8_t error; + msg->Get(error); + + if (error == 15) { + CGGameUI::DisplayError(ERR_ALREADY_PICKPOCKETED); + } + } + + this->m_lootTarget = WOWGUID(); + this->UpdateBaseAnimation(0, -1); + CGGameUI::UnlockItem(guid); + return 1; + } + } + + if (lootType) { + uint32_t coins; + uint8_t count; + msg->Get(coins); + msg->Get(count); + + if (count > 18) { + count = 18; + } + + CGObject_C* object = ClntObjMgrObjectPtr(guid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + CGGameUI::DisplayError(ERR_LOOT_DIDNT_KILL); + CDataStore release; + release.Put(static_cast(CMSG_LOOT_RELEASE)); + release.Put(guid.m_guid); + release.Finalize(); + ClientServices::Send2(&release); + return 1; + } + + if (object->m_obj->m_type & TYPEMASK_ITEM) { + CGGameUI::LockItem(guid); + } + + this->m_lootTarget = guid; + memset(s_lootItems, 0, sizeof(s_lootItems)); + + for (uint32_t i = 0; i < count; i++) { + uint8_t slot; + msg->Get(slot); + PlayerLootItem& item = s_lootItems[slot]; + msg->Get(reinterpret_cast(item.m_itemId)); + msg->Get(reinterpret_cast(item.m_count)); + msg->Get(reinterpret_cast(item.m_displayId)); + msg->Get(reinterpret_cast(item.m_randomSuffix)); + msg->Get(reinterpret_cast(item.m_randomPropertyId)); + uint8_t slotType; + msg->Get(slotType); + s_lootItems[slot].m_slotType = slotType; + } + + CGGameUI::OpenLoot(object, coins, lootType); + + if (this->m_movement->m_flags & 0xC000FF) { + CGGameUI::CloseLoot(true, true, false); + } + + return 1; + } + + uint8_t error; + msg->Get(error); + + switch (error) { + case 4: + CGGameUI::DisplayError(ERR_LOOT_TOO_FAR); + break; + case 5: + CGGameUI::DisplayError(ERR_LOOT_BAD_FACING); + break; + case 6: + CGGameUI::DisplayError(ERR_LOOT_LOCKED); + break; + case 8: + CGGameUI::DisplayError(ERR_LOOT_NOTSTANDING); + break; + case 9: + CGGameUI::DisplayError(ERR_LOOT_STUNNED); + break; + case 10: + CGGameUI::DisplayError(ERR_LOOT_PLAYER_NOT_FOUND); + return 1; + case 11: + CGGameUI::DisplayError(ERR_PLAY_TIME_EXCEEDED); + break; + case 12: + CGGameUI::DisplayError(ERR_LOOT_MASTER_INV_FULL); + return 1; + case 13: + CGGameUI::DisplayError(ERR_LOOT_MASTER_UNIQUE_ITEM); + return 1; + case 14: + CGGameUI::DisplayError(ERR_LOOT_MASTER_OTHER); + return 1; + case 16: + CGGameUI::DisplayError(ERR_NOT_WHILE_SHAPESHIFTED); + return 1; + default: + CGGameUI::DisplayError(ERR_LOOT_DIDNT_KILL); + break; + } + + this->m_lootTarget = WOWGUID(); + this->UpdateBaseAnimation(0, -1); + CGGameUI::UnlockItem(guid); + this->UpdateBaseAnimation(0, -1); + return 1; +} + +// VERIFY: 6a9eb816 manual +// OFFSET: 0x006D5860 +int32_t CGPlayer_C::OnLootRemoved(CDataStore* msg) { + uint8_t slot; + msg->Get(slot); + + if (ClntObjMgrObjectPtr(this->m_lootTarget, TYPEMASK_OBJECT, __FILE__, __LINE__)) { + memset(&s_lootItems[slot], 0, sizeof(s_lootItems[slot])); + CGGameUI::ClearLootSlot(slot); + } + + return 1; +} + +// VERIFY: fc79bef2 manual +// OFFSET: 0x006D58D0 +int32_t CGPlayer_C::OnLootSlotChanged(CDataStore* msg) { + WOWGUID guid; + uint8_t slot; + msg->Get(guid.m_guid); + msg->Get(slot); + + if (!ClntObjMgrObjectPtr(this->m_lootTarget, TYPEMASK_OBJECT, __FILE__, __LINE__) || this->m_lootTarget != guid) { + msg->m_read = msg->m_size; + return 1; + } + + PlayerLootItem& item = s_lootItems[slot]; + msg->Get(reinterpret_cast(item.m_itemId)); + msg->Get(reinterpret_cast(item.m_displayId)); + msg->Get(reinterpret_cast(item.m_randomSuffix)); + msg->Get(reinterpret_cast(item.m_randomPropertyId)); + msg->Get(reinterpret_cast(item.m_count)); + CGGameUI::LootSlotChanged(slot); + return 1; +} + +// VERIFY: 27a68345 auto +// OFFSET: 0x006D59E0 +int32_t CGPlayer_C::OnLootReleaseResponse(CDataStore* msg) { + WOWGUID guid; + uint8_t released; + msg->Get(guid.m_guid); + msg->Get(released); + + if (released && guid == this->m_lootTarget) { + this->m_lootTarget = WOWGUID(); + this->UpdateBaseAnimation(0, -1); + CGGameUI::CloseLoot(false, false, false); + } + + return 1; +} + +// VERIFY: 346301d0 manual +// OFFSET: 0x006DAC40 +void CGPlayer_C::LootCorpse(CGCorpse_C* corpse, bool autoInteract) { + if (!this->CanLoot(corpse) || !corpse->CanBeLooted() || (this->m_movement->m_flags & 0xC010FF)) { + return; + } + + if (autoInteract) { + C3Vector corpsePosition = corpse->GetPosition(); + C3Vector position = this->GetPosition(); + float dz = position.z - corpsePosition.z; + float dy = position.y - corpsePosition.y; + float dx = position.x - corpsePosition.x; + + if (dx * dx + (dy * dy + dz * dz) > 25.0f) { + WOWGUID guid = corpse->m_obj->m_guid; + + if (this->SetTrackingTarget(guid, 6)) { + return; + } + } + } + + CGGameUI::CloseLoot(true, false, false); + CDataStore msg; + msg.Put(static_cast(CMSG_LOOT_UNIT)); + msg.Put(corpse->m_obj->m_guid.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + this->m_lootTarget = corpse->m_obj->m_guid; + this->PlayBaseAnimation(ANIM_LOOT, 0); +} + +// VERIFY: 4c4a93c3 manual +// OFFSET: 0x006DAD90 +void CGPlayer_C::LootUnit(CGUnit_C* unit, bool autoInteract) { + if (!this->CanLoot(unit) || !unit->CanBeLooted(FrameTime::s_curTimeMs)) { + return; + } + + if (autoInteract) { + float range = this->GetMeleeRange(unit); + C3Vector unitPosition = unit->GetPosition(); + C3Vector position = this->GetPosition(); + float dz = position.z - unitPosition.z; + float dy = position.y - unitPosition.y; + float dx = position.x - unitPosition.x; + + if (range * range < dx * dx + (dy * dy + dz * dz)) { + WOWGUID guid = unit->m_obj->m_guid; + + if (this->SetTrackingTarget(guid, 6)) { + return; + } + } + } + + if (this->m_movement->m_flags & 0xC010FF) { + return; + } + + if (this->m_mountDisplayId > 0 && !(this->m_clientFlags & 0x10000000) && !this->MountedCombatAllowed()) { + if (!this->CanAutoDismount()) { + CGGameUI::DisplayError(ERR_NOT_WHILE_MOUNTED); + return; + } + + this->Dismount(); + } + + if (this->HasVehicleTransport()) { + this->CheckVehicleExitOnCast(); + } + + CGGameUI::CloseLoot(true, false, false); + CDataStore msg; + msg.Put(static_cast(CMSG_LOOT_UNIT)); + msg.Put(unit->m_obj->m_guid.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + this->m_lootTarget = unit->m_obj->m_guid; + this->PlayBaseAnimation(ANIM_LOOT, 0); +} + +// VERIFY: 84a4b9ef manual +// OFFSET: 0x006D51F0 +static int32_t InteractUpdateProc(WOWGUID guid, void* param) { + CGPlayer_C* player = static_cast(param); + CGObject_C* object = ClntObjMgrObjectPtr(guid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (!object) { + return 1; + } + + uint32_t type = object->m_obj->m_type; + + if (type != (TYPEMASK_UNIT | TYPEMASK_OBJECT) && type != (TYPEMASK_GAMEOBJECT | TYPEMASK_OBJECT)) { + return 1; + } + + if (type & TYPEMASK_GAMEOBJECT) { + if (player->CGUnit_C::CanInteract(static_cast(object))) { + return 1; + } + } else { + if (player->CanInteract(static_cast(object))) { + if (static_cast(object)->m_unit->m_unitNpcFlags & 0x2000) { + player->UpdateTaxiStatus(static_cast(object)); + } + + return 1; + } + } + + object->m_questStatus = 0; + object->m_interactIconType = 0; + object->RemoveInteractIcon(); + return 1; +} + +// VERIFY: c1f1a966 manual +// OFFSET: 0x006DC5A0 +void SendQuestGiverStatusMultipleQuery() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + ClntObjMgrEnumVisibleObjects(InteractUpdateProc, player); + } + + CDataStore msg; + msg.Put(static_cast(CMSG_QUEST_GIVER_STATUS_MULTIPLE_QUERY)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: d34ef321 manual +// OFFSET: 0x005946C0 +uint16_t CGPlayer_C::GetSkillLineID(int32_t index) const { + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + return this->m_player->m_playerSkillInfo[index].m_skillId; + } + + return 0; +} + +// VERIFY: b7e4b9ce manual +// OFFSET: 0x006DA4A0 +int32_t SkillRankChangeHandler(WOWGUID guid, uint32_t offset, uint32_t count, const void* value, void* param) { + uint32_t newRank = *static_cast(value); + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + uint32_t index = (offset - offsetof(CGPlayerLocalData, m_playerSkillInfo[0].m_rank)) / sizeof(PlayerSkillInfo); + + if (index >= 128) { + SErrDisplayAppFatalMessage("", "", 0); + } + + if (player && player->GetSkillValue(index) != newRank) { + SignalPlayerSkillStatEvents(); + uint32_t oldRank = player->GetSkillValue(index); + ConsolePrintf("Skill %d increased from %d to %d", player->GetSkillLineID(index), newRank, oldRank); + PlayerSignalSkillStatChanges(); + SkillLineRec* skillLine = g_skillLineDB.GetRecord(player->GetSkillLineID(index)); + const SkillRaceClassInfoRec* info = SpellTableLookupInfo(player->m_unit->m_unitFieldBytes0[0], player->m_unit->m_unitFieldBytes0[1], player->GetSkillLineID(index)); + + if (skillLine) { + if (info && !(info->m_flags & 0x402)) { + if (!newRank) { + CGGameUI::DisplayError(ERR_SKILL_GAINED_S, skillLine->m_displayName); + } else if (static_cast(player->GetSkillValue(index)) > 0) { + CGGameUI::DisplayError(ERR_SKILL_UP_SI, skillLine->m_displayName, player->GetSkillValue(index)); + } + } + + if (skillLine->m_categoryID == 9 || skillLine->m_categoryID == 11) { + CGPlayer_C::QueryQuestGiverStatusMultiple(); + } + } + } + + CGClassTrainer::RefreshList(); + CGTradeSkillInfo::RefreshList(0); + CGMerchantInfo::RefreshList(); + return 1; +} + +// VERIFY: 2ea51292 manual +// OFFSET: 0x006DCCC0 +bool CGPlayer_C::GetPackAndSlot(const CGItem_C* item, uint8_t* bag, uint8_t* slot) { + WOWGUID container = item->m_item->m_itemFieldContained; + + if (container == this->m_obj->m_guid) { + *bag = 0xFF; + *slot = this->FindSlotIndex(item->m_obj->m_guid); + return *slot != 0xFF; + } + + *bag = this->FindSlotIndex(container); + + if (*bag == 0xFF) { + return false; + } + + CGContainer_C* object = static_cast(ClntObjMgrObjectPtr(container, TYPEMASK_CONTAINER, __FILE__, __LINE__)); + + if (!object) { + return false; + } + + int32_t index = object->GetBag()->FindItemSlot(item->m_obj->m_guid); + + if (index < 0) { + return false; + } + + *slot = static_cast(index); + return true; +} + +// VERIFY: f458e054 manual +// OFFSET: 0x006DCD70 +void CGPlayer_C::OpenLootItem(CGItem_C* item) { + uint8_t bag; + uint8_t slot; + + if (!this->GetPackAndSlot(item, &bag, &slot)) { + return; + } + + CGGameUI::CloseLoot(true, false, false); + this->m_autoLoot = CGGameUI::IsAutoLooting() != 0; + + if (this->m_autoLoot && this->m_lootTarget) { + CGLootInfo::DoAutoLoot(0); + } + + this->m_lootTarget = item->m_obj->m_guid; + CGGameUI::LockItem(item->m_obj->m_guid); + CDataStore msg; + msg.Put(static_cast(CMSG_OPEN_ITEM)); + msg.Put(bag); + msg.Put(slot); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// STATIC: 0x00ADA1AC +static const UIErrors s_mountResultErrors[] = { ERR_MOUNT_INVALIDMOUNTEE, ERR_MOUNT_TOOFARAWAY, ERR_MOUNT_ALREADYMOUNTED, ERR_MOUNT_NOTMOUNTABLE, ERR_MOUNT_NOTYOURPET, ERR_MOUNT_OTHER, ERR_MOUNT_LOOTING, ERR_MOUNT_RACECANTMOUNT, ERR_MOUNT_SHAPESHIFTED, ERR_MOUNT_FORCEDDISMOUNT, ERR_MAX_VALUE }; + +// STATIC: 0x00ADA1D8 +static const UIErrors s_dismountResultErrors[] = { ERR_DISMOUNT_NOPET, ERR_DISMOUNT_NOTMOUNTED, ERR_DISMOUNT_NOTYOURPET, ERR_MAX_VALUE }; + +// STATIC: 0x00A32618 +static const UIErrors s_buyBankSlotErrors[] = { ERR_BANKSLOT_FAILED_TOO_MANY, ERR_BANKSLOT_INSUFFICIENT_FUNDS, ERR_BANKSLOT_NOTBANKER }; + +// VERIFY: eb850af4 auto +// OFFSET: 0x006CEDF0 +static void __stdcall DisplayMountResult(uint32_t result) { + if (result < 11) { + CGGameUI::DisplayError(s_mountResultErrors[result]); + } +} + +// VERIFY: 6eebaa29 auto +// OFFSET: 0x006CEE10 +static void __stdcall DisplayDismountResult(uint32_t result) { + if (result < 4) { + CGGameUI::DisplayError(s_dismountResultErrors[result]); + } +} + +// VERIFY: 3e53c616 auto +// OFFSET: 0x006CB990 +static void RandomRollNameQueryCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + uint32_t* roll = static_cast(param); + + if (!roll) { + SErrDisplayAppFatalMessage("", "", 0); + } + + if (success) { + WOWGUID requester = WOWGUID(); + NameCache* name = g_nameDBCache.GetRecord(guid.m_guid, requester, nullptr, nullptr, false); + + if (name) { + char text[3000]; + SStrPrintf(text, sizeof(text), FrameScript_GetText("RANDOM_ROLL_RESULT", -1, GENDER_NOT_APPLICABLE), name->m_name, roll[2], roll[0], roll[1]); + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + } + } + + operator delete(roll); +} + +// VERIFY: 9cd907bd manual +// OFFSET: 0x006E2E90 +int32_t Packet_Group_9(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + if (!msg) { + SErrDisplayAppFatalMessage("", "", 0); + } + + switch (msgId) { + case SMSG_FORCEACTIONSHOW: { + uint32_t a1; + uint32_t a2; + msg->Get(a1); + msg->Get(a2); + return 1; + } + + case SMSG_PETGODMODE: { + uint8_t enabled = 0; + msg->Get(enabled); + ConsoleWrite(enabled ? "Pet Godmode enabled" : "Pet Godmode disabled", DEFAULT_COLOR); + return 1; + } + + case SMSG_GOD_MODE: { + uint8_t enabled = 0; + msg->Get(enabled); + ConsoleWrite(enabled ? "Godmode enabled" : "Godmode disabled", DEFAULT_COLOR); + return 1; + } + + case SMSG_TRIGGER_CINEMATIC: { + uint32_t cinematic; + msg->Get(cinematic); + + if (ClientServices::Connection()->m_inGame) { + CGGameUI::StartCinematic(cinematic); + } else { + s_pendingMovie = cinematic; + } + + return 1; + } + + case SMSG_INVENTORY_CHANGE_FAILURE: { + uint8_t result = 0; + msg->Get(result); + + if (!result) { + return 1; + } + + UIErrors error = static_cast(GetDisplayErrorByInventoryError(result)); + WOWGUID item; + WOWGUID item2; + uint8_t bag; + msg->Get(item.m_guid); + msg->Get(item2.m_guid); + msg->Get(bag); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + switch (result) { + case 1: + case 87: { + uint32_t requiredLevel = 0; + msg->Get(requiredLevel); + CGGameUI::DisplayError(error, requiredLevel); + break; + } + + case 16: { + CGPlayer_C* activePlayer = ClntObjMgrGetActivePlayerObj(); + + if (!activePlayer || !activePlayer->ReportBagItemSubtypeMismatch(bag)) { + CGGameUI::DisplayError(error); + } + + break; + } + + case 81: { + uint64_t a2 = 0; + uint32_t a3 = 0; + uint64_t a4 = 0; + msg->Get(a2); + msg->Get(a3); + msg->Get(a4); + + if (player) { + CGPlayer_C::ServerBindConfirm(item, a2, a3, a4, bag); + } + + break; + } + + case 84: + case 85: + case 89: { + uint32_t category = 0; + msg->Get(category); + ItemLimitCategoryRec* rec = nullptr; + + if (!category || !(rec = g_itemLimitCategoryDB.GetRecord(category))) { + SErrDisplayAppFatalMessage("", "", 0); + } + + CGGameUI::DisplayError(error, rec->m_quantity, rec->m_name); + break; + } + + default: + CGGameUI::DisplayError(error); + break; + } + + if (item) { + if (player) { + if (item == player->m_lootTarget) { + CGGameUI::CloseLoot(true, false, false); + player->UpdateBaseAnimation(0, -1); + } + + Spell_C_CancelSpellByCaster(item); + } + + CGGameUI::UnlockItem(item); + } + + if (item2) { + CGGameUI::UnlockItem(item2); + } + + if (CGLootInfo::m_lootObj && player && player->m_autoLoot) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_OPENED, "%d", 1); + } + + return 1; + } + + case SMSG_OPEN_CONTAINER: { + WOWGUID guid; + msg->Get(guid.m_guid); + CGContainerInfo::OpenContainer(guid); + return 1; + } + + case SMSG_INSTANCE_LOCK_WARNING_QUERY: { + uint32_t lockTime = 0; + msg->Get(lockTime); + uint32_t a2 = 0; + msg->Get(a2); + uint8_t a3 = 0; + msg->Get(a3); + CGGameUI::SetInstanceLockTime(lockTime, a2, a3); + return 1; + } + + case SMSG_BIND_POINT_UPDATE: + CGPlayer_C::SaveBindPoint(msg); + return 1; + + case SMSG_BINDZONEREPLY: { + uint32_t a1; + uint32_t a2; + msg->Get(a1); + msg->Get(a2); + return 1; + } + + case SMSG_PLAYER_BOUND: { + WOWGUID binder; + uint32_t areaId; + msg->Get(binder.m_guid); + msg->Get(areaId); + s_unk_C9EAA0 = binder; + SI2::PlaySoundKit(0x475, nullptr, nullptr, nullptr, 0, nullptr, 1, 0); + AreaTableRec* area = g_areaTableDB.GetRecord(areaId); + + if (area) { + CGGameUI::DisplayError(ERR_DEATHBIND_SUCCESS_S, area->m_areaName); + } + + return 1; + } + + case SMSG_ITEM_PUSH_RESULT: { + WOWGUID guid; + uint32_t received; + uint32_t created; + uint32_t showInChat; + uint8_t bag; + uint32_t slot; + uint32_t itemId; + uint32_t suffixFactor; + uint32_t randomPropertyId; + uint32_t count; + uint32_t totalCount; + msg->Get(guid.m_guid); + msg->Get(received); + msg->Get(created); + msg->Get(showInChat); + msg->Get(bag); + msg->Get(slot); + msg->Get(itemId); + msg->Get(suffixFactor); + msg->Get(randomPropertyId); + msg->Get(count); + msg->Get(totalCount); + OnItemPushResult(guid, bag, slot, itemId, suffixFactor, randomPropertyId, received, created, showInChat, count); + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + player->CheckForQuestItemLoot(itemId, count, totalCount); + } + + return 1; + } + + case SMSG_MOUNT_RESULT: + if (ClntObjMgrGetActivePlayerObj()) { + uint32_t result = 0; + msg->Get(result); + DisplayMountResult(result); + } + + return 1; + + case SMSG_DISMOUNT_RESULT: + if (ClntObjMgrGetActivePlayerObj()) { + uint32_t result = 0; + msg->Get(result); + DisplayDismountResult(result); + } + + return 1; + + case SMSG_PET_NAME_INVALID: { + uint32_t error; + msg->Get(error); + CGGameUI::DisplayNameError(error); + char name[80]; + msg->GetString(name, sizeof(name)); + uint8_t declined; + msg->Get(declined); + + if (declined) { + char declensions[5][96]; + + for (uint32_t i = 0; i < 5; i++) { + msg->GetString(declensions[i], sizeof(declensions[i])); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_PET_FORCE_NAME_DECLENSION, "%s%s%s%s%s%s", name, declensions[0], declensions[1], declensions[2], declensions[3], declensions[4]); + } + + return 1; + } + + case SMSG_SHOW_TAXI_NODES: + if (ClntObjMgrGetActivePlayerObj()) { + CGPlayer_C::ShowTaxiNodes(msg); + } + + return 1; + + case SMSG_TAXI_NODE_STATUS: + if (ClntObjMgrGetActivePlayerObj()) { + CGPlayer_C::OnTaxiNodeStatus(msg); + } + + return 1; + + case SMSG_ACTIVATE_TAXI_REPLY: + if (ClntObjMgrGetActivePlayerObj()) { + uint32_t reply = 0; + msg->Get(reply); + CGPlayer_C::HandleActivateTaxiReply(reply); + } + + return 1; + + case SMSG_NEW_TAXI_PATH: + CGGameUI::DisplayError(ERR_NEWTAXIPATH); + CGGossipInfo::SetGossip(WOWGUID()); + return 1; + + case SMSG_PLAYERBINDERROR: + CGGameUI::DisplayError(ERR_DEATHBINDALREADYBOUND); + return 1; + + case SMSG_SHOW_BANK: { + WOWGUID banker; + msg->Get(banker.m_guid); + CGBankInfo::SetBanker(banker); + return 1; + } + + case SMSG_BUY_BANK_SLOT_RESULT: { + uint32_t result; + msg->Get(result); + + if (result < 3) { + CGGameUI::DisplayError(s_buyBankSlotErrors[result]); + } + + return 1; + } + + case SMSG_FISH_NOT_HOOKED: + CGGameUI::DisplayError(ERR_FISH_NOT_HOOKED); + return 1; + + case SMSG_FISH_ESCAPED: + CGGameUI::DisplayError(ERR_FISH_ESCAPED); + return 1; + + case SMSG_LEVEL_UP_INFO: { + uint32_t level; + uint32_t health; + uint32_t power[7]; + uint32_t stats[5]; + msg->Get(level); + msg->Get(health); + + for (uint32_t i = 0; i < 7; i++) { + msg->Get(power[i]); + } + + for (uint32_t i = 0; i < 5; i++) { + msg->Get(stats[i]); + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return 1; + } + + int32_t talentPoints = level >= 10; + + if (level >= 2) { + CGTutorial::TriggerTutorial(0x36); + } + + if (level >= 4) { + CGTutorial::TriggerTutorial(0xD); + } + + if (level >= 6) { + CGTutorial::TriggerTutorial(0x16); + } + + if (level >= 7) { + CGTutorial::TriggerTutorial(0x15); + CGTutorial::TriggerTutorial(0x25); + } + + if (level >= 8) { + CGTutorial::TriggerTutorial(0x20); + } + + if (level >= 10) { + CGTutorial::TriggerTutorial(0xC); + } + + if (level >= 12) { + CGTutorial::TriggerTutorial(0x26); + } + + if (level >= 15) { + CGTutorial::TriggerTutorial(0x32); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_PLAYER_LEVEL_UP, "%d%d%d%d%d%d%d%d%d", level, health, power[0], talentPoints, stats[0], stats[1], stats[2], stats[3], stats[4]); + return 1; + } + + case MSG_MINIMAP_PING: { + WOWGUID guid; + C2Vector position(0.0f, 0.0f); + msg->Get(guid.m_guid); + msg->Get(position.x); + msg->Get(position.y); + CGMinimapFrame::SetPingPosition(guid, position); + return 1; + } + + case SMSG_EXPLORATION_EXPERIENCE: { + uint32_t areaId; + int32_t experience; + msg->Get(areaId); + msg->Get(reinterpret_cast(experience)); + AreaTableRec* area = g_areaTableDB.GetRecord(areaId); + + if (!area) { + return 1; + } + + CGGameUI::DisplayError(ERR_ZONE_EXPLORED, area->m_areaName); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (experience > 0) { + if (!player) { + return 1; + } + + if (!(player->m_player->m_playerFlags & 0x2000000)) { + CGGameUI::DisplayError(ERR_ZONE_EXPLORED_XP, area->m_areaName, experience); + } + } + + if (!player) { + return 1; + } + + ChrRacesRec* race = g_chrRacesDB.GetRecord(player->m_unit->m_unitFieldBytes0[0]); + + if (race && race->m_explorationSoundID) { + SI2::PlaySoundKit(race->m_explorationSoundID, nullptr, nullptr, nullptr, 0, nullptr, 1, 0); + } + + return 1; + } + + case MSG_RANDOM_ROLL: { + uint32_t* roll = static_cast(SMemAlloc(3 * sizeof(uint32_t), __FILE__, __LINE__, 0)); + msg->Get(roll[0]); + msg->Get(roll[1]); + msg->Get(roll[2]); + WOWGUID guid; + msg->Get(guid.m_guid); + + if (!FriendList::s_friendList || !FriendList::s_friendList->IsIgnored(guid, true)) { + NameCache* name = g_nameDBCache.GetRecord(guid.m_guid, guid, RandomRollNameQueryCallback, roll, false); + + if (!name) { + return 1; + } + + char text[3000]; + SStrPrintf(text, sizeof(text), FrameScript_GetText("RANDOM_ROLL_RESULT", -1, GENDER_NOT_APPLICABLE), name->m_name, roll[2], roll[0], roll[1]); + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + } + + operator delete(roll); + return 1; + } + + case SMSG_CLEAR_FAR_SIGHT_IMMEDIATE: { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->ClearFarSight(); + } + + return 1; + } + + case SMSG_CHAT_WRONG_FACTION: + CGGameUI::DisplayError(ERR_CHAT_WRONG_FACTION); + return 1; + + case SMSG_GM_TICKET_GET_SYSTEM_STATUS: { + uint32_t status; + msg->Get(status); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_GM_STATUS, "%d", status); + return 1; + } + + case SMSG_SPIRIT_HEALER_CONFIRM: { + WOWGUID guid; + msg->Get(guid.m_guid); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->TalkToSpiritHealer(guid); + } + + return 1; + } + + case MSG_QUEST_PUSH_RESULT: { + WOWGUID guid; + uint8_t result; + msg->Get(guid.m_guid); + msg->Get(result); + WOWGUID requester = WOWGUID(); + NameCache* name = g_nameDBCache.GetRecord(guid.m_guid, requester, nullptr, nullptr, false); + + if (!name) { + return 1; + } + + switch (result) { + case 0: + CGGameUI::DisplayError(ERR_QUEST_PUSH_SUCCESS_S, name->m_name); + break; + + case 1: + CGGameUI::DisplayError(ERR_QUEST_PUSH_INVALID_S, name->m_name); + break; + + case 2: + CGGameUI::DisplayError(ERR_QUEST_PUSH_ACCEPTED_S, name->m_name); + break; + + case 3: + CGGameUI::DisplayError(ERR_QUEST_PUSH_DECLINED_S, name->m_name); + break; + + case 4: + CGGameUI::DisplayError(ERR_QUEST_PUSH_BUSY_S, name->m_name); + break; + + case 5: + CGGameUI::DisplayError(ERR_QUEST_PUSH_LOG_FULL_S, name->m_name); + break; + + case 6: + CGGameUI::DisplayError(ERR_QUEST_PUSH_ONQUEST_S, name->m_name); + break; + + case 7: + CGGameUI::DisplayError(ERR_QUEST_PUSH_ALREADY_DONE_S, name->m_name); + break; + + case 8: + CGGameUI::DisplayError(ERR_QUEST_PUSH_NOT_DAILY_S, name->m_name); + break; + + case 9: + CGGameUI::DisplayError(ERR_QUEST_PUSH_TIMER_EXPIRED_S, name->m_name); + break; + + case 10: + CGGameUI::DisplayError(ERR_QUEST_PUSH_NOT_IN_PARTY_S, name->m_name); + break; + + case 11: + CGGameUI::DisplayError(ERR_QUEST_PUSH_DIFFERENT_SERVER_DAILY_S, name->m_name); + break; + } + + return 1; + } + + case SMSG_RAID_GROUP_ONLY: { + uint32_t bootTime; + uint32_t reason = 0; + msg->Get(bootTime); + msg->Get(reason); + + if (!bootTime) { + switch (reason) { + case 1: + CGGameUI::DisplayError(ERR_RAID_GROUP_LOWLEVEL); + break; + + case 2: + CGGameUI::DisplayError(ERR_RAID_GROUP_ONLY); + break; + + case 3: + CGGameUI::DisplayError(ERR_RAID_GROUP_FULL); + break; + + case 4: + CGGameUI::DisplayError(ERR_RAID_GROUP_REQUIREMENTS_UNMATCH); + break; + } + } + + CGGameUI::SetInstanceBootTime(bootTime); + return 1; + } + + case SMSG_CHAT_NOT_IN_PARTY: { + uint32_t type; + msg->Get(type); + + if (type == 2 || type == 51) { + CGGameUI::DisplayError(ERR_NOT_IN_GROUP); + } else if (type == 3 || type == 39 || type == 40) { + CGGameUI::DisplayError(ERR_NOT_IN_RAID); + } + + return 1; + } + + case SMSG_CHAT_PLAYER_NOTFOUND: { + char name[305]; + msg->GetString(name, sizeof(name)); + CGGameUI::DisplayError(ERR_CHAT_PLAYER_NOT_FOUND_S, name); + CGAutoCompleteName::RemoveFlagsByName(name, 32, 1, 0); + return 1; + } + + case MSG_TALENT_WIPE_CONFIRM: { + WOWGUID guid; + uint32_t cost; + msg->Get(guid.m_guid); + msg->Get(cost); + + if (guid) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->TalkToTalentMaster(guid, cost); + } + } else { + CGGameUI::DisplayError(ERR_TALENT_WIPE_ERROR); + } + + return 1; + } + + case SMSG_BINDER_CONFIRM: { + WOWGUID guid; + msg->Get(guid.m_guid); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->TalkToBinder(guid); + } + + return 1; + } + + case SMSG_CHAT_RESTRICTED: { + uint8_t type; + msg->Get(type); + + switch (type) { + case 0: + CGGameUI::DisplayError(ERR_CHAT_RESTRICTED); + break; + + case 1: + CGGameUI::DisplayError(ERR_CHAT_THROTTLED); + break; + + case 2: + CGGameUI::DisplayError(ERR_USER_SQUELCHED); + break; + + case 3: + CGGameUI::DisplayError(ERR_YELL_RESTRICTED); + break; + } + + return 1; + } + + case SMSG_CHAT_PLAYER_AMBIGUOUS: { + char name[305]; + msg->GetString(name, sizeof(name)); + CGGameUI::DisplayError(ERR_CHAT_PLAYER_AMBIGUOUS_S, name); + return 1; + } + + case SMSG_DEATH_RELEASE_LOC: { + int32_t mapId; + C3Vector position(0.0f, 0.0f, 0.0f); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + msg->Get(reinterpret_cast(mapId)); + msg->Get(position.x); + msg->Get(position.y); + msg->Get(position.z); + + if (!player || (player->m_player->m_playerFlags & 0x10)) { + position = C3Vector(0.0f, 0.0f, 0.0f); + CGGameUI::SetDeathReleaseLocation(-1, position); + } else { + CGGameUI::SetDeathReleaseLocation(mapId, position); + } + + return 1; + } + + case SMSG_FORCED_DEATH_UPDATE: { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + SErrDisplayAppFatalMessage("", "", 0); + return 0; + } + + player->UpdateRepopTimer(); + CGGameUI::UpdateActivePlayer(); + return 1; + } + + case SMSG_COMPLAINT_RESULT: { + uint8_t result; + uint8_t reason; + msg->Get(result); + msg->Get(reason); + + if (result == 1) { + CGChat::m_complaintsSystemStatus = 0; + } + + if (reason == 12) { + CGCalendar::CalendarError("COMPLAINT_ADDED", 0); + return 1; + } + + CGChat::AddChatMessage(FrameScript_GetText("COMPLAINT_ADDED", -1, GENDER_NOT_APPLICABLE), CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + return 1; + } + + case SMSG_FEATURE_SYSTEM_STATUS: { + uint8_t status; + msg->Get(status); + CGChat::m_complaintsSystemStatus = status; + msg->Get(status); + CGChat::m_voiceChatSystemStatus = status; + return 1; + } + + case SMSG_REPORT_PVP_AFK_RESULT: { + uint8_t result; + uint8_t a2; + uint8_t a3; + WOWGUID guid; + msg->Get(result); + msg->Get(a2); + msg->Get(a3); + msg->Get(guid.m_guid); + const char* text; + + if (result == 5) { + if (g_enablePVPNotifyAFKCVar->m_intValue) { + return 1; + } + + g_enablePVPNotifyAFKCVar->Set(1, true, false, false, true); + text = FrameScript_GetText("PVP_REPORT_AFK_SYSTEM_ENABLED", -1, GENDER_NOT_APPLICABLE); + } else { + if (result != 6 || !g_enablePVPNotifyAFKCVar->m_intValue) { + return 1; + } + + g_enablePVPNotifyAFKCVar->Set(0, true, false, false, true); + text = FrameScript_GetText("PVP_REPORT_AFK_SYSTEM_DISABLED", -1, GENDER_NOT_APPLICABLE); + } + + CGChat::AddChatMessage(text, CHAT_MSG_SYSTEM, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + return 1; + } + + case SMSG_CONVERT_RUNE: { + uint8_t rune; + uint8_t type; + msg->Get(rune); + msg->Get(type); + CGRuneInfo::ConvertRune(rune, type); + return 1; + } + + case SMSG_RESYNC_RUNES: + CGRuneInfo::ResyncRunes(msg); + return 1; + + case SMSG_ADD_RUNE_POWER: + CGRuneInfo::AddRunePower(msg); + return 1; + + case SMSG_ARENA_TEAM_CHANGE_FAILED_QUEUED: { + uint32_t failed = 0; + msg->Get(failed); + + if (failed) { + CGGameUI::DisplayError(ERR_ARENA_TEAM_CHANGE_FAILED_QUEUED); + } + + return 1; + } + + case SMSG_TOGGLE_XP_GAIN: { + uint8_t enabled = 0; + msg->Get(enabled); + ConsoleWrite(enabled ? "XP Gain Enabled" : "XP Gain Disabled", DEFAULT_COLOR); + return 1; + } + + case SMSG_CAMERA_SHAKE: { + uint32_t shakeId; + uint32_t soundId; + msg->Get(shakeId); + msg->Get(soundId); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + SErrDisplayAppFatalMessage("", "", 0); + return 0; + } + + C3Vector position = player->GetPosition(); + SpellEffectCameraShakesRec* rec = g_spellEffectCameraShakesDB.GetRecord(shakeId); + + if (rec) { + for (uint32_t i = 0; i < 3; i++) { + CGWorldFrame::GetActiveCamera()->AddShakeById(rec->m_cameraShake[i], &position); + } + } + + if (soundId) { + SI2::PlaySoundKit(soundId, &position, nullptr, nullptr, 0, nullptr, 1, 0); + } + + return 1; + } + + default: + return 0; + } +} diff --git a/WoW/Source/Object/ObjectClient/Player_C.h b/WoW/Source/Object/ObjectClient/Player_C.h index a06be18..2ef4492 100644 --- a/WoW/Source/Object/ObjectClient/Player_C.h +++ b/WoW/Source/Object/ObjectClient/Player_C.h @@ -61,6 +61,15 @@ struct PlayerPendingItemExpiration : public TSLinkedNodem_envRef); this->m_hashMask = -1; } + +// VERIFY: e64eaffe manual +// OFFSET: 0x00758390 +SimpleScriptFunction* CSimpleScriptManager::GetFunction(uint32_t handle) { + if (handle == 0xFFFFFFFF) { + return nullptr; + } + + TSGrowableArray* list = &this->m_buckets[handle >> 16]; + + if (handle >= list->m_count) { + return nullptr; + } + + return &list->m_data[handle]; +} + +// VERIFY: 2600d97c auto +// OFFSET: 0x007587D0 +uint32_t CSimpleScriptManager::CreateFunction(int32_t id, const SimpleScriptFunctionDesc& desc) { + CDynamicString script; + script.SetCapacity(512); + script += "return function("; + int32_t separator = 0; + int32_t numArgs = 0; + int32_t numStringArgs = 0; + + if (desc.m_args && *desc.m_args) { + do { + if (separator) { + script += ", "; + } + + script += desc.m_args[numArgs]; + separator = 1; + numArgs++; + } while (desc.m_args[numArgs]); + } + + if (desc.m_stringArgs && *desc.m_stringArgs) { + do { + if (separator) { + script += ", "; + } + + script += desc.m_stringArgs[numStringArgs]; + separator = 1; + numStringArgs++; + } while (desc.m_stringArgs[numStringArgs]); + } + + script += ")\n"; + int32_t numReturns = 0; + int32_t numStringReturns = 0; + + if (desc.m_returns && *desc.m_returns) { + do { + script += "local "; + script += desc.m_returns[numReturns]; + script += " = 0.0\n"; + numReturns++; + } while (desc.m_returns[numReturns]); + } + + if (desc.m_stringReturns && *desc.m_stringReturns) { + do { + script += "local "; + script += desc.m_stringReturns[numStringReturns]; + script += " = \"\"\n"; + numStringReturns++; + } while (desc.m_stringReturns[numStringReturns]); + } + + script += desc.m_body; + script += "\nreturn "; + separator = 0; + + if (desc.m_returns) { + for (int32_t i = 0; desc.m_returns[i]; i++) { + if (separator) { + script += ", "; + } + + script += desc.m_returns[i]; + separator = 1; + } + } + + if (desc.m_stringReturns) { + for (int32_t i = 0; desc.m_stringReturns[i]; i++) { + if (separator) { + script += ", "; + } + + script += desc.m_stringReturns[i]; + separator = 1; + } + } + + script += "\nend\n"; + lua_State* L = FrameScript_GetContext(); + lua_rawgeti(L, LUA_REGISTRYINDEX, FrameScript_GetErrorHandlerReference()); + + if (luaL_loadbuffer(L, script.m_buffer, script.m_length, desc.m_name)) { + if (lua_pcall(L, 1, 0, 0)) { + lua_settop(L, -2); + } + + return 0xFFFFFFFF; + } + + if (lua_pcall(L, 0, 1, 1)) { + lua_settop(L, -3); + return 0xFFFFFFFF; + } + + lua_rawgeti(L, LUA_REGISTRYINDEX, this->m_envRef); + lua_setfenv(L, -2); + uint32_t handle = this->FindFunction(id); + SimpleScriptFunction local; + SimpleScriptFunction* function; + + if (handle == 0xFFFFFFFF) { + function = &local; + } else { + function = this->GetFunction(handle); + luaL_unref(L, LUA_REGISTRYINDEX, function->m_luaRef); + } + + function->m_id = id; + function->m_luaRef = luaL_ref(L, LUA_REGISTRYINDEX); + lua_settop(L, -2); + function->m_numArgs = numArgs; + function->m_numStringArgs = numStringArgs; + function->m_numReturns = numReturns; + function->m_numStringReturns = numStringReturns; + + if (handle != 0xFFFFFFFF) { + return handle; + } + + uint32_t bucket = id & this->m_hashMask; + TSGrowableArray* list = &this->m_buckets[bucket]; + list->Add(1, function); + return (bucket << 16) | (list->m_count - 1); +} diff --git a/WoW/Source/Object/ObjectClient/SimpleScript.h b/WoW/Source/Object/ObjectClient/SimpleScript.h index 3cf2fb3..8616a4d 100644 --- a/WoW/Source/Object/ObjectClient/SimpleScript.h +++ b/WoW/Source/Object/ObjectClient/SimpleScript.h @@ -14,6 +14,15 @@ struct SimpleScriptFunction { /* 0014 */ int32_t m_numStringReturns; }; +struct SimpleScriptFunctionDesc { + /* 0000 */ const char* m_name; + /* 0004 */ const char** m_args; + /* 0008 */ const char** m_stringArgs; + /* 000C */ const char* m_body; + /* 0010 */ const char** m_returns; + /* 0014 */ const char** m_stringReturns; +}; + struct SimpleScriptIO { /* 0000 */ TSGrowableArray m_numbers; /* 0010 */ uint32_t m_stringSize; @@ -41,6 +50,8 @@ class CSimpleScriptManager { void CopyGlobal(const char* name); int32_t Execute(const char* script, const char* name); uint32_t FindFunction(int32_t id); + SimpleScriptFunction* GetFunction(uint32_t handle); + uint32_t CreateFunction(int32_t id, const SimpleScriptFunctionDesc& desc); int32_t Init(uint32_t bits); void Uninit(); }; diff --git a/WoW/Source/Object/ObjectClient/UnitCombatLog_C.cpp b/WoW/Source/Object/ObjectClient/UnitCombatLog_C.cpp index f41c5a2..d8b9467 100644 --- a/WoW/Source/Object/ObjectClient/UnitCombatLog_C.cpp +++ b/WoW/Source/Object/ObjectClient/UnitCombatLog_C.cpp @@ -27,6 +27,16 @@ #include "WoW/Source/Ui/ScriptEvents.h" #include "WoW/Source/Object/ObjectClient/AuraData.h" #include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentRec.h" +#include "WoW/Source/DB/Rec/SpellMechanicRec.h" +#include "Engine/Source/Tempest/CMath.h" +#include "WoW/Source/DB/Rec/SpellDurationRec.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/Game/GameClient/PlayerName.h" +#include "WoW/Source/Game/ValidateName.h" +#include "Engine/Source/Base/ConvertUTF.h" +#include "WoW/Source/Object/CreatureStats.h" +#include "WoW/Source/DB/Rec/SummonPropertiesRec.h" // STATIC: 0x00ADB758 static const char* s_combatLogEventNames[50] = { @@ -134,6 +144,9 @@ static const char* s_combatTextTypes[48] = { "ARENA_POINTS_GAINED" }; +// STATIC: 0x00ADB93C +static const uint32_t s_mechanicTextColor = 0xFFFFDE00; + // STATIC: 0x00ADB944 static TSList > s_invalidatedNames; @@ -1442,3 +1455,1330 @@ int32_t CombatLogEntry::PushEvent(lua_State* L) { return count; } + +// VERIFY: c56cea32 auto +// OFFSET: 0x00750210 +void CombatLogEntry::SetExecuteItem(int32_t itemId) { + this->m_infoFlags |= 0x200; + this->m_info.m_values[0] = itemId; + PendingCombatLogData* data = GetPendingCombatLogData(this, WOWGUID{ 0 }, 4); + data->m_id = itemId; + data->m_type = 5; + this->m_info.m_names[1] = this->ResolveName(data, nullptr, true); +} + +// VERIFY: ed94944b manual +// OFFSET: 0x00750500 +void CombatLog::QueueMissedSpellText(const WOWGUID& source, const WOWGUID& dest, int32_t event, const SpellRec* spell, int32_t missType, int32_t amount, uint32_t timeOffset) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, spell); + entry->SetMissInfo(missType, amount); + + if (s_combatTextActiveUnit == dest) { + switch (missType) { + case 1: + SendToCombatText(event == 8 ? 15 : 3); + break; + + case 2: + SendToCombatText(event == 8 ? 22 : 10); + break; + + case 3: + SendToCombatText(event == 8 ? 16 : 4); + break; + + case 4: + SendToCombatText(event == 8 ? 17 : 5); + break; + + case 5: + SendToCombatText(event == 8 ? 23 : 11); + break; + + case 6: + SendToCombatText(event == 8 ? 18 : 6); + break; + + case 7: + case 8: + SendToCombatText(event == 8 ? 19 : 7); + break; + + case 9: + SendToCombatText(event == 8 ? 20 : 8); + break; + + case 10: + SendToCombatText(event == 8 ? 24 : 12); + break; + + case 11: + SendToCombatText(event == 8 ? 21 : 9); + break; + + default: + break; + } + } + + QueueCombatLogEntry(entry, timeOffset); +} + +// VERIFY: 66f75cea auto +// OFFSET: 0x00751050 +int32_t Packet_SMSG_ENCHANTMENTLOG(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + uint32_t itemId; + msg->Get(itemId); + uint32_t enchantId; + msg->Get(enchantId); + + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(enchantId); + + if (enchant && !(enchant->m_flags & 0x2)) { + CombatLogEntry* entry = GetCombatLogEntry(caster, target, caster.m_guid ? 31 : 32, nullptr); + entry->m_infoFlags |= 0x1000; + entry->m_info.m_names[2] = enchant->m_name; + entry->SetExecuteItem(itemId); + QueueCombatLogEntry(entry, 0); + } + + return 1; +} + +// VERIFY: c50eda39 auto +// OFFSET: 0x00751AD0 +void UnitCombatLogSpellFail(const WOWGUID& caster, int32_t spellId, const char* reason) { + if (!reason || !*reason) { + return; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + WOWGUID dest = { 0 }; + CombatLogEntry* entry = GetCombatLogEntry(caster, dest, 7, &spell); + entry->SetFailReason(reason); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 94b0219d auto +// OFFSET: 0x00751B80 +void UnitCombatLogSpellMissed(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t missType, bool a5, bool a6, int32_t a7) { + if (!missType) { + return; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + int32_t event; + + if (a6) { + event = 33; + } else if (a5) { + event = 41; + } else { + event = (spell.m_attributesExC & 0x8000) ? 4 : 8; + } + + CombatLog::QueueMissedSpellText(casterGuid, targetGuid, event, &spell, missType, 0, a7); + } +} + +// VERIFY: d5382c97 manual +// OFFSET: 0x007522A0 +void CombatLog::AddSpellCastEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + int32_t event = (static_cast(dest.m_guid >> 32) & 0xF0F00000) == 0xF0100000 ? 16 : 15; + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, &spell); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 5431f565 auto +// OFFSET: 0x00752340 +void CombatLog::AddSpellResurrectEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, 46, &spell); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 397ad275 auto +// OFFSET: 0x007523D0 +void UnitCombatLogInterrupt(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t interruptedSpellId) { + SpellRec spell; + SpellRec interrupted; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name && g_spellDB.GetRecord(interruptedSpellId, &interrupted) && !(interrupted.m_attributes & 0x180) && *interrupted.m_name) { + CombatLogEntry* entry = GetCombatLogEntry(casterGuid, targetGuid, 17, &spell); + entry->m_infoFlags |= 0x100; + entry->m_info.m_values[0] = interruptedSpellId; + QueueCombatLogEntry(entry, 0); + + if (IsCombatTextActiveUnit(targetGuid)) { + SendToCombatText(0, interrupted.m_name); + } + + SpellMechanicRec* mechanic = g_spellMechanicDB.GetRecord(26); + + if (mechanic) { + DisplayMechanicEffect(&targetGuid, &casterGuid, &spell, mechanic); + } + } +} + +// VERIFY: 130013bd auto +// OFFSET: 0x00752520 +void CombatLog::AddSpellDamageEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, uint32_t timeOffset) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name && damage) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, 18, &spell); + entry->m_infoFlags |= 0x1; + entry->m_info.m_values[0] = damage; + QueueCombatLogEntry(entry, timeOffset); + + if (s_combatTextActiveUnit == dest) { + SendToCombatText(41, damage); + } + } +} + +// VERIFY: 5dd1e7d2 auto +// OFFSET: 0x007525E0 +void CombatLog::AddSpellExecuteEntry(const WOWGUID& source, const WOWGUID& dest, int32_t itemId, int32_t spellId) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, 19, &spell); + entry->SetExecuteItem(itemId); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 52db4556 auto +// OFFSET: 0x00752680 +void CombatLog::AddSpellEnergizeEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, 20, &spell); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 8c0f6497 manual +// OFFSET: 0x006D3220 +int32_t CombatLog::HandleSpellLogExecute(CDataStore* msg, int32_t timeOffset) { + SmartGUID caster; + *msg >> caster; + uint32_t spellId = 0; + msg->Get(spellId); + uint32_t effectCount = 0; + msg->Get(effectCount); + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + msg->m_read = msg->m_size; + return 1; + } + + for (int32_t i = effectCount; i > 0; i--) { + uint32_t effect = 0; + msg->Get(effect); + uint32_t targetCount = 0; + msg->Get(targetCount); + + for (int32_t j = targetCount; j > 0; j--) { + SmartGUID target; + + switch (effect) { + case 8: + case 62: { + *msg >> target; + uint32_t amount = 0; + msg->Get(amount); + uint32_t powerType = 0; + msg->Get(powerType); + float multiplier = 0.0f; + msg->Get(multiplier); + UnitCombatLogPowerDrain(caster, target, spellId, powerType, amount, multiplier, (spell.m_attributesExC & 0x2000000) != 0, timeOffset); + break; + } + + case 18: + case 113: + *msg >> target; + CombatLog::AddSpellResurrectEntry(caster, target, spellId); + break; + + case 19: { + *msg >> target; + uint32_t damage = 0; + msg->Get(damage); + CombatLog::AddSpellDamageEntry(caster, target, spellId, damage, timeOffset); + break; + } + + case 24: + case 59: + case 157: { + uint32_t itemId = 0; + msg->Get(itemId); + CGChat::LogTradeSkillCreate(caster, itemId); + break; + } + + case 28: + case 50: + case 56: + case 76: + case 81: + case 83: + case 104: + case 105: + case 106: + case 107: + *msg >> target; + CombatLog::AddSpellCastEntry(caster, target, spellId); + break; + + case 33: + *msg >> target; + CombatLog::GetSpellLogLinkInfo(caster, target, spellId); + break; + + case 68: { + *msg >> target; + uint32_t interrupted = 0; + msg->Get(interrupted); + UnitCombatLogInterrupt(caster, target, spellId, interrupted); + break; + } + + case 101: { + uint32_t itemId = 0; + msg->Get(itemId); + CGChat::LogFeedPet(caster, itemId); + break; + } + + case 102: + *msg >> target; + CGChat::LogDismissPet(caster, target); + break; + + case 111: { + *msg >> target; + uint32_t itemId = 0; + msg->Get(itemId); + uint32_t extra = 0; + msg->Get(extra); + + if (itemId == 0xFFFFFFFF && extra == 0xFFFFFFFF) { + CombatLog::AddSpellEnergizeEntry(caster, target, spellId); + } else { + CombatLog::AddSpellExecuteEntry(caster, target, itemId, spellId); + } + + break; + } + + default: + break; + } + } + } + + return 1; +} + +// VERIFY: ae480a8e manual +// OFFSET: 0x00751F70 +void UnitCombatLogHeal(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t amount, int32_t overheal, int32_t absorbed, bool crit, bool periodic, uint32_t timeOffset) { + if (!amount && !overheal && !absorbed) { + return; + } + + CGUnit_C* target = static_cast(ClntObjMgrObjectPtr(targetGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (target) { + target->ModifyPredictedHealth(amount); + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + SendHealEvent(periodic ? 35 : 10, casterGuid, targetGuid, &spell, amount, overheal, absorbed, crit, timeOffset); + } +} + +// VERIFY: 9de2c0e0 manual +// OFFSET: 0x00752040 +void UnitCombatLogEnergize(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t powerType, int32_t amount, bool periodic, uint32_t timeOffset) { + if (!amount) { + return; + } + + CGUnit_C* target = static_cast(ClntObjMgrObjectPtr(targetGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (target) { + target->ModifyPredictedPower(powerType, amount); + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + SendEnergizeEvent(periodic ? 36 : 11, casterGuid, targetGuid, &spell, powerType, amount, timeOffset); + } +} + +// VERIFY: 013ab8d4 manual +// OFFSET: 0x00752710 +void UnitCombatLogAuraAddedOrRemoved(CGUnit_C* unit, AuraData* aura, const SpellRec* spell, uint8_t harmful, int32_t added) { + if (unit->m_unit->m_unitFieldHealth <= 0 && !added) { + return; + } + + if (!spell || !spell->m_id || (spell->m_attributes & 0x180) || !*spell->m_name || (spell->m_attributes & 0x40) || (spell->m_attributesExF & 0x400)) { + return; + } + + WOWGUID guid = unit->m_obj->m_guid; + CombatLogEntry* entry = GetCombatLogEntry(aura->m_creator, guid, added ? 21 : 24, spell); + entry->m_infoFlags |= 0x400; + reinterpret_cast(entry->m_info.m_values[1]) = harmful; + QueueCombatLogEntry(entry, 0); + + if (added) { + WOWGUID unitGuid = unit->m_obj->m_guid; + UnitCombatLogSpellMechanic(unitGuid, aura, spell); + } + + if (!IsCombatTextActiveUnit(unit->m_obj->m_guid)) { + return; + } + + if (added) { + if (harmful) { + SendToCombatText(34, spell->m_name); + } else if (!(spell->m_attributesExF & 0x40)) { + SendToCombatText(33, spell->m_name); + } + } else { + SendToCombatText(harmful ? 32 : 31, spell->m_name); + } +} + +// VERIFY: db86f760 manual +// OFFSET: 0x006D3090 +int32_t CombatLog::HandleSpellLogMiss(CDataStore* msg, int32_t timeOffset) { + uint32_t spellId = 0; + msg->Get(spellId); + uint64_t value = 0; + msg->Get(value); + WOWGUID caster = WOWGUID{ value }; + uint8_t debug = 0; + msg->Get(debug); + bool hasDebug = debug != 0; + uint32_t count = 0; + msg->Get(count); + + SpellRec spell; + int32_t found = g_spellDB.GetRecord(spellId, &spell); + + for (; count; count--) { + uint64_t targetValue = 0; + msg->Get(targetValue); + WOWGUID target = WOWGUID{ targetValue }; + uint8_t missType = 0; + msg->Get(missType); + + if (hasDebug) { + float a = 0.0f; + msg->Get(a); + float b = 0.0f; + msg->Get(b); + } else if (found && !(spell.m_attributes & 0x100)) { + CGGameUI::ShowSpellMissFeedback(target, missType); + UnitCombatLogSpellMissed(caster, target, spellId, missType, true, false, timeOffset); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->AddWorldText(caster, missType, &spell, false); + } + } + } + + return 1; +} + +// VERIFY: b28f2a2e manual +// OFFSET: 0x006D3C30 +int32_t CombatLog::HandleSpellHealLog(CDataStore* msg, int32_t timeOffset) { + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + uint32_t spellId = 0; + msg->Get(spellId); + uint32_t amount = 0; + msg->Get(amount); + uint32_t overheal = 0; + msg->Get(overheal); + uint32_t absorbed = 0; + msg->Get(absorbed); + uint8_t critByte = 0; + msg->Get(critByte); + bool crit = critByte != 0; + uint8_t unused = 0; + msg->Get(unused); + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return 1; + } + + if (!(spell.m_attributes & 0x100)) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && !amount && absorbed) { + WOWGUID source = caster; + unit->AddWorldText(source, 10, &spell, true); + } + + WOWGUID dest = target; + CGGameUI::ShowHealingFeedback(dest, amount, crit); + } + + UnitCombatLogHeal(caster, target, spellId, amount, overheal, absorbed, crit, (spell.m_attributesExC & 0x2000000) != 0, timeOffset); + return 1; +} + +// VERIFY: c6dd3152 manual +// OFFSET: 0x006D3DF0 +int32_t CombatLog::HandleSpellLogEnergizeLog(CDataStore* msg, int32_t timeOffset) { + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + uint32_t spellId = 0; + msg->Get(spellId); + uint32_t powerType = 0; + msg->Get(powerType); + uint32_t amount = 0; + msg->Get(amount); + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + if (!(spell.m_attributes & 0x100)) { + CGGameUI::ShowEnergizeFeedback(target, powerType, amount); + } + + UnitCombatLogEnergize(caster, target, spellId, powerType, amount, (spell.m_attributesExC & 0x2000000) != 0, timeOffset); + } + + return 1; +} + +// VERIFY: 4b332cb3 manual +// OFFSET: 0x00750860 +void SendHealEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t amount, int32_t overheal, int32_t absorbed, bool crit, uint32_t timeOffset) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, spell); + entry->m_infoFlags |= 0x20; + entry->m_info.m_values[1] = overheal; + entry->m_info.m_values[0] = amount; + entry->m_info.m_values[2] = absorbed; + reinterpret_cast(entry->m_info.m_values[3]) = crit; + QueueCombatLogEntry(entry, timeOffset); + + if (event == 35) { + SpellDurationRec* duration = g_spellDurationDB.GetRecord(spell->m_durationIndex); + + if (duration) { + int32_t value = duration->m_duration + duration->m_durationPerLevel * static_cast(Spell_C_GetSpellLevel(spell, 0, 0)) >= duration->m_maxDuration ? duration->m_maxDuration : duration->m_duration + duration->m_durationPerLevel * static_cast(Spell_C_GetSpellLevel(spell, 0, 0)); + + if (value > 30000) { + return; + } + } + } + + if (s_combatTextActiveUnit == dest) { + if (absorbed) { + if (event == 35) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%s%d%d", s_combatTextTypes[44], GetObjectNameFromGuid(source), amount, absorbed); + } else { + SendToCombatText(crit ? 45 : 46, GetObjectNameFromGuid(source), amount, absorbed); + } + } else if (event == 35) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%s%d", s_combatTextTypes[27], GetObjectNameFromGuid(source), amount); + } else { + SendToCombatText(crit ? 37 : 38, GetObjectNameFromGuid(source), amount); + } + } else { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(dest, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->AddWorldHealingText(source, amount, spell, crit, 0); + } + } +} + +// VERIFY: f15c546c manual +// OFFSET: 0x00750A90 +void SendEnergizeEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t powerType, int32_t amount, uint32_t timeOffset) { + int32_t value = amount / Spell_C_GetPowerDisplayMod(powerType); + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, spell); + entry->m_infoFlags |= 0x40; + entry->m_info.m_values[0] = value; + entry->m_info.m_values[1] = powerType; + QueueCombatLogEntry(entry, timeOffset); + + if (s_combatTextActiveUnit == dest) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%d%s", s_combatTextTypes[(event == 36) + 28], value, GetPowerString(powerType)); + } +} + +// VERIFY: a94001c7 manual +// OFFSET: 0x00750B60 +void AddPowerDrainEntry(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t amount, int32_t powerType, int32_t extra, uint32_t timeOffset) { + uint32_t mod = Spell_C_GetPowerDisplayMod(powerType); + int32_t value = amount / mod; + int32_t extraValue = extra / mod; + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, spell); + entry->m_infoFlags |= 0x80; + entry->m_info.m_values[2] = extraValue; + entry->m_info.m_values[0] = value; + entry->m_info.m_values[1] = powerType; + QueueCombatLogEntry(entry, timeOffset); + + if (s_combatTextActiveUnit == dest && value) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%d%s", s_combatTextTypes[28], -value, GetPowerString(powerType)); + } + + if (s_combatTextActiveUnit == source && extraValue) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%d%s", s_combatTextTypes[(event == 38) + 28], extraValue, GetPowerString(powerType)); + } +} + +// VERIFY: d355aaa8 manual +// OFFSET: 0x00752100 +void UnitCombatLogPowerDrain(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, uint32_t powerType, uint32_t amount, float multiplier, bool a7, uint32_t timeOffset) { + if (!amount) { + return; + } + + if (powerType == 4) { + CGChat::LogPetHappinessDecrease(casterGuid, targetGuid, amount / Spell_C_GetPowerDisplayMod(4)); + return; + } + + CGUnit_C* target = static_cast(ClntObjMgrObjectPtr(targetGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (target) { + target->ModifyPredictedPower(powerType, -static_cast(amount)); + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x180) && *spell.m_name) { + int32_t extra = CMath::ftrunc(amount * multiplier); + int32_t event = extra ? (a7 ? 38 : 13) : (a7 ? 37 : 12); + AddPowerDrainEntry(event, casterGuid, targetGuid, &spell, amount, powerType, extra, timeOffset); + } +} + +// VERIFY: 048b1785 auto +// OFFSET: 0x0074D3D0 +bool SpellHasOpenLockEffect(const SpellRec* spell) { + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effect[i] == 33) { + return true; + } + } + + return false; +} + +// VERIFY: f32a38df auto +// OFFSET: 0x0074D3F0 +bool SpellIsHiddenInCombatLog(const SpellRec* spell) { + if ((spell->m_attributes & 0x180) || !*spell->m_name) { + return true; + } + + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effect[i] == 36) { + return true; + } + } + + return (spell->m_attributesExD & 0x1) != 0; +} + +// VERIFY: 6e0bb93c auto +// OFFSET: 0x0074DA00 +static bool ShouldShowMechanicText(WOWGUID guid, const SpellRec* spell) { + if (!(spell->m_attributesExF & 0x200000)) { + return false; + } + + CVar* all = CVar::Lookup("fctAllSpellMechanics"); + + if (all && all->m_intValue > 0) { + return true; + } + + CVar* mechanics = CVar::Lookup("fctSpellMechanics"); + + if (!mechanics || !mechanics->m_intValue) { + return false; + } + + CVar* other = CVar::Lookup("fctSpellMechanicsOther"); + + if (IsCombatTextActiveUnit(guid)) { + return true; + } + + return other && other->m_intValue; +} + +// VERIFY: 9c33925c manual +// OFFSET: 0x0074DA70 +void DisplayMechanicEffect(const WOWGUID* unitGuid, const WOWGUID* sourceGuid, const SpellRec* spell, const SpellMechanicRec* mechanic) { + if (!ShouldShowMechanicText(*sourceGuid, spell)) { + return; + } + + char text[148]; + uint16_t wide[64]; + char state[64]; + SUniConvertUTF8to16(wide, 64, mechanic->m_stateName, STORM_MAX_STR, nullptr, nullptr); + wide[0] = ToUpper(wide[0]); + SUniConvertUTF16to8(state, 64, wide, STORM_MAX_STR, nullptr, nullptr); + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*unitGuid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (s_combatTextActiveUnit == *sourceGuid) { + SStrCopy(text, state, STORM_MAX_STR); + } else { + SStrPrintf(text, sizeof(text), "%s (%s)", state, GetObjectNameFromGuid(*sourceGuid)); + } + + if (unit) { + PlayerNameCreateText(unit->m_nameDesc, 0, text, reinterpret_cast(&s_mechanicTextColor), nullptr); + } +} + +// VERIFY: 0a6910f9 manual +// OFFSET: 0x0074DB80 +void UnitCombatLogSpellMechanic(const WOWGUID& guid, const AuraData* aura, const SpellRec* spell) { + if (SpellIsHiddenInCombatLog(spell)) { + return; + } + + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effect[i] == 33) { + return; + } + } + + for (int32_t i = 0; i < 3; i++) { + int32_t mechanicId = spell->m_effectMechanic[i]; + + if (!mechanicId) { + continue; + } + + bool duplicate = false; + + for (int32_t j = i - 1; j >= 0; j--) { + if (mechanicId == spell->m_effectMechanic[j]) { + duplicate = true; + } + } + + if (duplicate) { + continue; + } + + SpellMechanicRec* mechanic = g_spellMechanicDB.GetRecord(mechanicId); + + if (mechanic && mechanic->m_id != 26) { + DisplayMechanicEffect(&guid, &aura->m_creator, spell, mechanic); + } + } + + int32_t mechanicId = spell->m_mechanic; + + if (!mechanicId) { + return; + } + + bool listed = spell->m_effectMechanic[0] == mechanicId; + + if (spell->m_effectMechanic[1] == mechanicId) { + listed = true; + } + + if (spell->m_effectMechanic[2] == mechanicId || listed) { + return; + } + + SpellMechanicRec* mechanic = g_spellMechanicDB.GetRecord(mechanicId); + + if (mechanic && mechanic->m_id != 26) { + DisplayMechanicEffect(&guid, &aura->m_creator, spell, mechanic); + } +} + +// VERIFY: ecea9cd0 manual +// OFFSET: 0x00751920 +void UnitCombatLogCastStart(const WOWGUID& caster, const WOWGUID& target, int32_t spellId) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !SpellIsHiddenInCombatLog(&spell) && unit->GetSpellCastingTime(&spell)) { + WOWGUID dest = { 0 }; + CombatLogEntry* entry = GetCombatLogEntry(caster, dest, 5, &spell); + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: d9765cf5 manual +// OFFSET: 0x007519E0 +void UnitCombatLogCastGo(const WOWGUID& caster, const WOWGUID& target, int32_t spellId) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || SpellIsHiddenInCombatLog(&spell) || SpellHasOpenLockEffect(&spell)) { + return; + } + + if (!unit->GetSpellCastingTime(&spell)) { + CombatLogEntry* entry = GetCombatLogEntry(caster, target, 6, &spell); + QueueCombatLogEntry(entry, 0); + } + + if (IsCombatTextActiveUnit(caster) && (spell.m_attributesExF & 0x40)) { + SendToCombatText(30, spell.m_name); + } +} + +// VERIFY: 5bc10808 auto +// OFFSET: 0x00752930 +void CombatLog::AddAuraReplacedEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t replacedSpellId, uint8_t harmful, bool stolen, uint32_t timeOffset) { + SpellRec spell; + SpellRec replaced; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x180) || !*spell.m_name) { + return; + } + + if (!g_spellDB.GetRecord(replacedSpellId, &replaced) || (replaced.m_attributes & 0x180) || !*replaced.m_name) { + return; + } + + CombatLogEntry* entry = GetCombatLogEntry(source, dest, stolen + 26, &spell); + entry->m_infoFlags |= 0x500; + entry->m_info.m_values[0] = replacedSpellId; + reinterpret_cast(entry->m_info.m_values[1]) = harmful; + QueueCombatLogEntry(entry, timeOffset); + + if (IsCombatTextActiveUnit(dest)) { + SendToCombatText(40, replaced.m_name); + } +} + +// VERIFY: c935fa27 auto +// OFFSET: 0x00752A40 +void CombatLog::AddSpellRemoveEntry(const WOWGUID& source, const WOWGUID& dest, int32_t dispelSpellId, int32_t spellId, uint8_t harmful) { + SpellRec dispel; + SpellRec spell; + memset(&dispel, 0, sizeof(dispel)); + + if (dispelSpellId && (!g_spellDB.GetRecord(dispelSpellId, &dispel) || (dispel.m_attributes & 0x180) || !*dispel.m_name)) { + return; + } + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x180) || !*spell.m_name) { + return; + } + + WOWGUID remover = (dispel.m_attributesExD & 0x2000) ? WOWGUID{ 0 } : source; + CombatLogEntry* entry = GetCombatLogEntry(remover, dest, (dispelSpellId != 0) + 28, &spell); + + if (dispelSpellId) { + entry->m_infoFlags |= 0x100; + entry->m_info.m_values[0] = dispelSpellId; + } + + entry->m_infoFlags |= 0x400; + reinterpret_cast(entry->m_info.m_values[1]) = harmful; + QueueCombatLogEntry(entry, 0); + + if (s_combatTextActiveUnit == dest) { + SendToCombatText(40, spell.m_name); + } +} + +// VERIFY: 6403f90e auto +// OFFSET: 0x00752BA0 +void UnitCombatLogAuraRefreshed(CGUnit_C* unit, const AuraData* aura, int32_t spellId, uint8_t a4) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x180) || !*spell.m_name || (spell.m_attributes & 0x40) || (spell.m_attributesExF & 0x400)) { + return; + } + + WOWGUID guid = unit->m_obj->m_guid; + CombatLogEntry* entry = GetCombatLogEntry(aura->m_creator, guid, 25, &spell); + entry->m_infoFlags |= 0x400; + reinterpret_cast(entry->m_info.m_values[1]) = a4; + QueueCombatLogEntry(entry, 0); + + WOWGUID unitGuid = unit->m_obj->m_guid; + UnitCombatLogSpellMechanic(unitGuid, aura, &spell); +} + +// VERIFY: 9d679be0 manual +// OFFSET: 0x00750660 +void SendDamageEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t damage, int32_t overkill, uint32_t school, int32_t resisted, int32_t blocked, int32_t absorbed, bool crit, bool a11, bool a12, uint32_t timeOffset) { + if (event != 1) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(dest, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->ModifyPredictedHealth(-damage); + } + } + + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, spell); + entry->m_infoFlags |= 0x10; + entry->m_info.m_values[3] = school; + entry->m_info.m_values[4] = absorbed; + entry->m_info.m_values[1] = damage; + entry->m_info.m_values[5] = resisted; + entry->m_info.m_values[2] = overkill; + entry->m_info.m_values[6] = blocked; + entry->m_infoBits = (entry->m_infoBits & ~0x7) | (crit & 1) | (((a11 & 1) | ((a12 & 1) << 1)) << 1); + QueueCombatLogEntry(entry, timeOffset); + + if (s_combatTextActiveUnit != dest) { + return; + } + + if (resisted > 0) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%d%d", s_combatTextTypes[event == 9 ? 22 : 10], damage, resisted); + } else if (blocked) { + SendToCombatText(event == 9 ? 23 : 11, damage, blocked); + } else if (absorbed) { + SendToCombatText(event == 9 ? 24 : 12, damage, absorbed); + } else if (crit) { + SendToCombatText(event == 9 ? 13 : 1, damage); + } else if (event == 40) { + SendToCombatText(39, damage); + } else { + SendToCombatText(event == 9 ? 14 : 2, damage); + } +} + +// VERIFY: d14d7c4f manual +// OFFSET: 0x00751C40 +void UnitCombatLogSpellDamage(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, int32_t overkill, uint32_t school, int32_t absorbed, int32_t resisted, int32_t blocked, uint32_t hitInfo, bool periodic, uint32_t timeOffset) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x180) || !*spell.m_name) { + return; + } + + if (damage) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(dest, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->TriggerDamageFeedback(); + } + + int32_t event = periodic ? 34 : ((spell.m_attributesExC & 0x8000) ? 3 : 9); + SendDamageEvent(event, source, dest, &spell, damage, overkill, school, resisted, blocked, absorbed, (hitInfo >> 1) & 1, false, false, timeOffset); + return; + } + + int32_t event = periodic ? 33 : ((spell.m_attributesExC & 0x8000) ? 4 : 8); + + if (absorbed) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, &spell); + entry->m_infoFlags |= 0x2004; + entry->m_info.m_values[0] = 10; + entry->m_info.m_values[4] = absorbed; + + if (s_combatTextActiveUnit == dest) { + SendToCombatText(event == 8 ? 24 : 12); + } + + QueueCombatLogEntry(entry, 0); + } else if (blocked) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, &spell); + entry->m_infoFlags |= 0x8004; + entry->m_info.m_values[0] = 5; + entry->m_info.m_values[6] = blocked; + + if (s_combatTextActiveUnit == dest) { + SendToCombatText(event == 8 ? 23 : 11); + } + + QueueCombatLogEntry(entry, 0); + } else if (resisted) { + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, &spell); + entry->m_infoFlags |= 0x4004; + entry->m_info.m_values[0] = 2; + entry->m_info.m_values[5] = resisted; + + if (s_combatTextActiveUnit == dest) { + SendToCombatText(event == 8 ? 22 : 10); + } + + QueueCombatLogEntry(entry, 0); + } +} + +// VERIFY: 9129ea05 manual +// OFFSET: 0x00752DE0 +void UnitCombatLogSplitDamage(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, int32_t overkill, uint32_t school, int32_t absorbed, int32_t resisted, int32_t blocked, uint32_t hitInfo, uint32_t timeOffset) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributes & 0x180) || !*spell.m_name) { + return; + } + + SendDamageEvent(42, source, dest, &spell, damage, overkill, school, resisted, blocked, absorbed, (hitInfo >> 1) & 1, false, false, timeOffset); + + if (s_combatTextActiveUnit == dest) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMBAT_TEXT_UPDATE, "%s%d", s_combatTextTypes[42], damage); + } +} + +// VERIFY: 06a9b4e3 auto +// OFFSET: 0x006CE2B0 +int32_t CombatLog::HandleSpellRemoveLog(NETMESSAGE msgId, CDataStore* msg, int32_t timeOffset) { + uint32_t dispelSpellId = 0; + uint8_t unused = 0; + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + msg->Get(dispelSpellId); + msg->Get(unused); + uint32_t count = 0; + msg->Get(count); + + while (count) { + count--; + uint32_t spellId; + msg->Get(spellId); + uint8_t harmful; + msg->Get(harmful); + + if (msgId == SMSG_SPELL_BREAK_LOG) { + CombatLog::AddSpellRemoveEntry(caster, target, dispelSpellId, spellId, harmful != 0); + } else { + CombatLog::AddAuraReplacedEntry(caster, target, dispelSpellId, spellId, harmful != 0, msgId == SMSG_SPELL_STEAL_LOG, timeOffset); + } + } + + return 1; +} + +// VERIFY: f5db08bc manual +// OFFSET: 0x006D3840 +int32_t CombatLog::HandleSpellNonMeleeDamageLog(CDataStore* msg, int32_t timeOffset) { + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + uint32_t spellId = 0; + msg->Get(spellId); + uint32_t damage = 0; + msg->Get(damage); + uint32_t overkill = 0; + msg->Get(overkill); + uint8_t schoolByte = 0; + msg->Get(schoolByte); + uint32_t school = schoolByte; + uint32_t absorbed = 0; + msg->Get(absorbed); + uint32_t resisted = 0; + msg->Get(resisted); + uint8_t periodic = 0; + msg->Get(periodic); + uint8_t unused = 0; + msg->Get(unused); + uint32_t blocked = 0; + msg->Get(blocked); + uint32_t hitInfo = 0; + msg->Get(hitInfo); + uint8_t debug = 0; + msg->Get(debug); + + bool crit = (hitInfo & 0x2) != 0; + uint32_t flags = crit ? 0x200 : 0; + + if (absorbed) { + flags |= 0x20; + } + + if (blocked) { + flags |= 0x2000; + } + + if (resisted) { + flags |= 0x80; + } + + SpellRec spell; + int32_t found = g_spellDB.GetRecord(spellId, &spell); + + if (hitInfo & 0x8) { + UnitCombatLogSplitDamage(caster, target, spellId, damage, overkill, school, absorbed, resisted, blocked, hitInfo, timeOffset); + + if (found && !(spell.m_attributes & 0x100)) { + CGGameUI::ShowCombatFeedback(target, damage, school, flags); + } + + return 1; + } + + WOWGUID source = (hitInfo & 0x10) ? target : caster; + UnitCombatLogSpellDamage(source, target, spellId, damage, overkill, school, absorbed, resisted, blocked, hitInfo, periodic, timeOffset); + + if (found && !(spell.m_attributes & 0x100)) { + CGGameUI::ShowCombatFeedback(target, damage, school, flags); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (damage) { + unit->AddWorldDamageText(caster, damage, &spell, crit, false, false); + } else if (absorbed) { + unit->AddWorldText(caster, 10, &spell, false); + } else if (blocked) { + unit->AddWorldText(caster, 5, &spell, false); + } else if (resisted) { + unit->AddWorldText(caster, 2, &spell, false); + } + } + } + + if (debug) { + float value; + + if (hitInfo & 0x1) { + value = 0.0f; + msg->Get(value); + value = 0.0f; + msg->Get(value); + } + + if (hitInfo & 0x4) { + value = 0.0f; + msg->Get(value); + value = 0.0f; + msg->Get(value); + } + + if (hitInfo & 0x20) { + for (uint32_t i = 0; i < 6; i++) { + value = 0.0f; + msg->Get(value); + } + } + } + + return 1; +} + +// VERIFY: f255adaa manual +// OFFSET: 0x007531F0 +int32_t CombatLog::HandlePeriodicAuraLog(CDataStore* msg, int32_t timeOffset) { + SmartGUID target; + SmartGUID caster; + *msg >> target; + *msg >> caster; + uint32_t spellId = 0; + msg->Get(spellId); + uint32_t count = 0; + msg->Get(count); + + SpellRec spell; + CGUnit_C* unit; + + if (!g_spellDB.GetRecord(spellId, &spell) || !(unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)))) { + msg->m_read = msg->m_size; + return 1; + } + + for (int32_t i = 0; i < static_cast(count); i++) { + uint32_t auraType = 0; + msg->Get(auraType); + + switch (auraType) { + case 3: + case 89: { + uint32_t damage = 0; + msg->Get(damage); + uint32_t overkill = 0; + msg->Get(overkill); + uint32_t school = 0; + msg->Get(school); + uint32_t absorbed = 0; + msg->Get(absorbed); + uint32_t resisted = 0; + msg->Get(resisted); + uint8_t crit = 0; + msg->Get(crit); + uint8_t hitInfo = 0; + + if (!(spell.m_attributes & 0x100)) { + if (damage) { + unit->AddWorldDamageText(caster, damage, &spell, crit != 0, true, false); + } else if (absorbed) { + unit->AddWorldText(caster, 10, &spell, true); + } else if (resisted) { + unit->AddWorldText(caster, 2, &spell, true); + } + + uint32_t flags = 0; + + if (absorbed) { + flags = 0x20; + } + + if (resisted) { + flags |= 0x80; + } + + if (crit) { + flags |= 0x200; + hitInfo = 2; + } + + CGGameUI::ShowCombatFeedback(target, damage, school, flags); + } + + UnitCombatLogSpellDamage(caster, target, spellId, damage, overkill, school, absorbed, resisted, 0, hitInfo, true, timeOffset); + break; + } + + case 8: + case 20: { + uint32_t amount = 0; + msg->Get(amount); + uint32_t overheal = 0; + msg->Get(overheal); + uint32_t absorbed = 0; + msg->Get(absorbed); + uint8_t crit = 0; + msg->Get(crit); + + if (!(spell.m_attributes & 0x100)) { + if (!amount && absorbed) { + unit->AddWorldText(caster, 10, &spell, true); + } + + CGGameUI::ShowHealingFeedback(target, amount, crit != 0); + } + + UnitCombatLogHeal(caster, target, spellId, amount, overheal, absorbed, crit != 0, true, timeOffset); + break; + } + + case 21: + case 24: { + uint32_t powerType = 0; + msg->Get(powerType); + uint32_t amount = 0; + msg->Get(amount); + + if (!(spell.m_attributes & 0x100)) { + CGGameUI::ShowEnergizeFeedback(target, powerType, amount); + } + + UnitCombatLogEnergize(caster, target, spellId, powerType, amount, true, timeOffset); + break; + } + + case 64: { + uint32_t powerType = 0; + msg->Get(powerType); + uint32_t amount = 0; + msg->Get(amount); + float multiplier = 0.0f; + msg->Get(multiplier); + UnitCombatLogPowerDrain(caster, target, spellId, powerType, amount, multiplier, true, timeOffset); + break; + } + + default: + msg->m_read = msg->m_size; + return 1; + } + } + + return 1; +} + +// VERIFY: 150dd800 auto +// OFFSET: 0x00753710 +int32_t Packet_SMSG_PERIODICAURALOG(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + return CombatLog::HandlePeriodicAuraLog(msg, 0); +} + +// VERIFY: c5d9ed0a manual +// OFFSET: 0x00752ED0 +void UnitCombatLogUnitDead(CGUnit_C* unit) { + int32_t event = 44; + WOWGUID none = WOWGUID(); + CreatureStats_C* creature = g_creatureDBCache.GetRecord(unit->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (creature && creature->m_type == 13) { + event = 49; + } else { + SpellRec spell; + + if (!g_spellDB.GetRecord(unit->m_unit->m_unitCreatedBySpell, &spell) && spell.m_effect[0] == 28) { + SummonPropertiesRec* summon = g_summonPropertiesDB.GetRecord(spell.m_effectMiscValueB[0]); + + if (summon && static_cast(summon->m_slot - 1) <= 3) { + event = 45; + } + } + } + + WOWGUID dest = unit->m_obj->m_guid; + WOWGUID source = WOWGUID(); + CombatLogEntry* entry = GetCombatLogEntry(source, dest, event, nullptr); + QueueCombatLogEntry(entry, 0); +} diff --git a/WoW/Source/Object/ObjectClient/UnitCombatLog_C.h b/WoW/Source/Object/ObjectClient/UnitCombatLog_C.h index ae7853e..70d8b75 100644 --- a/WoW/Source/Object/ObjectClient/UnitCombatLog_C.h +++ b/WoW/Source/Object/ObjectClient/UnitCombatLog_C.h @@ -52,6 +52,7 @@ struct CombatLogEntry : public TSLinkedNode { void PackEvent(char* buffer, uint32_t size); void SetFailReason(const char* reason); void SetMissInfo(int32_t missType, int32_t amount); + void SetExecuteItem(int32_t itemId); }; struct InvalidatedName : public TSLinkedNode { @@ -94,6 +95,15 @@ class CombatLog { static int32_t HandleSpellHealLog(CDataStore* msg, int32_t timeOffset); static int32_t HandleSpellLogEnergizeLog(CDataStore* msg, int32_t timeOffset); static int32_t HandlePeriodicAuraLog(CDataStore* msg, int32_t timeOffset); + static void AddSpellCastEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId); + static void AddSpellResurrectEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId); + static void AddSpellDamageEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, uint32_t timeOffset); + static void AddSpellExecuteEntry(const WOWGUID& source, const WOWGUID& dest, int32_t itemId, int32_t spellId); + static void AddSpellEnergizeEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId); + static void AddAuraReplacedEntry(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t replacedSpellId, uint8_t harmful, bool stolen, uint32_t timeOffset); + static void AddSpellRemoveEntry(const WOWGUID& source, const WOWGUID& dest, int32_t dispelSpellId, int32_t spellId, uint8_t harmful); + static void GetSpellLogLinkInfo(const WOWGUID& source, const WOWGUID& dest, int32_t spellId); + static void QueueMissedSpellText(const WOWGUID& source, const WOWGUID& dest, int32_t event, const SpellRec* spell, int32_t missType, int32_t amount, uint32_t timeOffset); }; void UnitCombatLogInstakill(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId); @@ -111,7 +121,9 @@ char* GUIDToHexString(WOWGUID guid, char* buffer); WOWGUID StringToGuid(const char* string); void UnitCombatLog(const WOWGUID& guid, uint32_t type, int32_t damage, int32_t absorbed, int32_t resisted); void UnitCombatLog(const ATTACKROUNDINFO& info); +void UnitCombatLogUnitDead(CGUnit_C* unit); void UnitCombatLogCastGo(const WOWGUID& caster, const WOWGUID& target, int32_t spellId); +void UnitCombatLogSpellFail(const WOWGUID& caster, int32_t spellId, const char* reason); class AuraData; void UnitCombatLogAuraDose(CGUnit_C* unit, const AuraData* aura, int32_t spellId, int32_t oldStack, int32_t newStack, uint8_t a6); void UnitCombatLogAuraRefreshed(CGUnit_C* unit, const AuraData* aura, int32_t spellId, uint8_t a4); @@ -129,7 +141,23 @@ void SendToCombatText(int32_t type, int32_t amount, int32_t overflow); void SendToCombatText(int32_t type, int32_t amount); void SendToCombatText(int32_t type, const char* text); void SendToCombatText(int32_t type); +void UnitCombatLogAuraAddedOrRemoved(CGUnit_C* unit, AuraData* aura, const SpellRec* spell, uint8_t harmful, int32_t added); void UnitCombatLogProcGo(const WOWGUID& casterGuid, const SpellRec* spell); +void UnitCombatLogPowerDrain(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, uint32_t powerType, uint32_t amount, float multiplier, bool a7, uint32_t timeOffset); +void UnitCombatLogInterrupt(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t interruptedSpellId); +void UnitCombatLogHeal(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t amount, int32_t overheal, int32_t absorbed, bool crit, bool periodic, uint32_t timeOffset); +void UnitCombatLogEnergize(const WOWGUID& casterGuid, const WOWGUID& targetGuid, int32_t spellId, int32_t powerType, int32_t amount, bool periodic, uint32_t timeOffset); +void SendHealEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t amount, int32_t overheal, int32_t absorbed, bool crit, uint32_t timeOffset); +void SendEnergizeEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t powerType, int32_t amount, uint32_t timeOffset); +void AddPowerDrainEntry(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t amount, int32_t powerType, int32_t extra, uint32_t timeOffset); +void SendDamageEvent(int32_t event, const WOWGUID& source, const WOWGUID& dest, const SpellRec* spell, int32_t damage, int32_t overkill, uint32_t school, int32_t resisted, int32_t blocked, int32_t absorbed, bool crit, bool a11, bool a12, uint32_t timeOffset); +void UnitCombatLogSpellDamage(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, int32_t overkill, uint32_t school, int32_t absorbed, int32_t resisted, int32_t blocked, uint32_t hitInfo, bool periodic, uint32_t timeOffset); +void UnitCombatLogSplitDamage(const WOWGUID& source, const WOWGUID& dest, int32_t spellId, int32_t damage, int32_t overkill, uint32_t school, int32_t absorbed, int32_t resisted, int32_t blocked, uint32_t hitInfo, uint32_t timeOffset); +void UnitCombatLogSpellMechanic(const WOWGUID& guid, const AuraData* aura, const SpellRec* spell); +bool SpellIsHiddenInCombatLog(const SpellRec* spell); +bool SpellHasOpenLockEffect(const SpellRec* spell); +class SpellMechanicRec; +void DisplayMechanicEffect(const WOWGUID* unitGuid, const WOWGUID* sourceGuid, const SpellRec* spell, const SpellMechanicRec* mechanic); int32_t Script_CombatLogAdvanceEntry(lua_State* L); void UnitCombatLogRegisterScriptFunctions(); diff --git a/WoW/Source/Object/ObjectClient/UnitMissileTrajectory_C.h b/WoW/Source/Object/ObjectClient/UnitMissileTrajectory_C.h index 01c3c48..13121b6 100644 --- a/WoW/Source/Object/ObjectClient/UnitMissileTrajectory_C.h +++ b/WoW/Source/Object/ObjectClient/UnitMissileTrajectory_C.h @@ -4,7 +4,9 @@ #include #include +class C3Vector; class CGUnit_C; +class SpellMissileRec; class CMissileCollision; class CMissileCollisionHeap { @@ -34,6 +36,8 @@ class CMissileCollision { CMissileCollision(); void Free(); + int32_t Init(const C3Vector* start, const C3Vector* end, float pitch, float speed, const SpellMissileRec* missile, CGUnit_C* caster); + float ComputeSegmentImpactTime(const C3Vector* start, const C3Vector* end); }; #endif diff --git a/WoW/Source/Object/ObjectClient/Unit_C.cpp b/WoW/Source/Object/ObjectClient/Unit_C.cpp index df10d40..8139deb 100644 --- a/WoW/Source/Object/ObjectClient/Unit_C.cpp +++ b/WoW/Source/Object/ObjectClient/Unit_C.cpp @@ -1,4 +1,5 @@ #include "Unit_C.h" +#include #include #include "Engine/Source/Base/CDataStore.h" #include "Engine/Source/Model2/M2Model.h" @@ -106,6 +107,20 @@ #include "_Triage/CMovementStatus.h" #include "WoW/Source/Object/MovementShared.h" #include "WoW/Source/UIUtil/Cursor.h" +#include "WoW/Source/DB/Rec/SpellDispelTypeRec.h" +#include "WoW/Source/Magic/Spell.h" +#include "WoW/Source/Magic/MagicClient/SpellTable.h" +#include "WoW/Source/DB/Rec/SkillRaceClassInfoRec.h" +#include "WoW/Source/DB/Rec/SkillLineAbilityRec.h" +#include "WoW/Source/Game/GameTime.h" +#include "WoW/Source/Game/GameClient/tables.h" +#include "WoW/Source/Ui/StableInfo.h" +#include "WoW/Source/DB/Rec/SpellVisualEffectNameRec.h" +#include "WoW/Source/DB/Rec/SpellMissileMotionRec.h" +#include "WoW/Source/Ui/RuneInfo.h" +#include "WoW/Source/Game/ViolenceLevels.h" +#include "WoW/Source/Ui/Tutorial.h" +#include "WoW/Source/Ui/ChatFrame.h" // STATIC: 0x00CA11A8 static WOWGUID s_unk_CA11A8; @@ -129,7 +144,7 @@ int32_t g_environmentalDamageVisualKits[6]; static EmotesRec* s_talkEmotes[5]; // STATIC: 0x00CA1244 -static uint32_t* s_unitThreatPool; +static UnitThreatHeap* s_unitThreatPool; // STATIC: 0x00CA1254 int32_t CGUnit_C::s_initialized; @@ -718,7 +733,7 @@ void CGUnit_C::PostAnimate(CGWorldFrame* worldFrame) { } } -// VERIFY: 18d99912 manual +// VERIFY: 1c8f109c manual // OFFSET: 0x00734390 void CGUnit_C::UpdateDisplay(uint32_t time) { this->Unk72E270(); @@ -732,7 +747,7 @@ void CGUnit_C::UpdateDisplay(uint32_t time) { this->ReleaseMissiles(this->m_animEventPosition); } - if (static_cast(time - this->unk_09E8 - 2000) >= 0) { + if (static_cast(time - this->m_lastMissileTime - 2000) >= 0) { C3Vector position(0.0f, 0.0f, 0.0f); position = this->GetMissileFirePosition(); this->ReleaseMissiles(position); @@ -1296,7 +1311,7 @@ void CGUnit_C::ModelLoaded(CM2Model* model) { } } -// VERIFY: 0cdb0e67 manual +// VERIFY: 82112df4 manual // OFFSET: 0x0073DAB0 void CGUnit_C::PreAnimate(CGWorldFrame* frame) { uint32_t time = FrameTime::s_curTimeMs; @@ -1349,12 +1364,12 @@ void CGUnit_C::PreAnimate(CGWorldFrame* frame) { this->CGObject_C::PreAnimate(frame); - while (this->m_pendingMissiles && static_cast(time - this->m_pendingMissiles->unk_009C) >= 0) { + while (this->m_pendingMissiles && static_cast(time - this->m_pendingMissiles->m_destroyTime) >= 0) { this->m_pendingMissiles->DeleteSelf(); } for (CMissile* missile = this->m_pendingMissiles; missile; missile = missile->m_next) { - float t = static_cast(missile->unk_009C - time) * 0.0005f; + float t = static_cast(missile->m_destroyTime - time) * 0.0005f; float alpha; if (t < 0.0f) { @@ -4835,7 +4850,7 @@ bool CGUnit_C::CanInteractNow(const CGUnit_C* unit) const { return static_cast(this)->CanInteract(unit); } -// VERIFY: 1abec503 manual +// VERIFY: 2220328b manual // OFFSET: 0x00731260 void CGUnit_C::OnRightClick() { CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); @@ -4918,7 +4933,7 @@ void CGUnit_C::OnRightClick() { WOWGUID target = this->m_obj->m_guid; - if (!player->CanAttackNow(this) || !player->VerifyAttackIconPressed(target, 1, 0, 0, true)) { + if (!player->CanAttackNow(this) || !player->VerifyAttackIconPressed(&target, 1, 0, 0, true)) { if (vehicleAllows) { this->HandleNPCFeedback(); } @@ -5043,7 +5058,7 @@ void CGUnit_C::UnregisterMirrorHandlers() { ClntObjMgrUnsetTypeMirrorHandler(ID_UNIT, offsetof(CGUnitData, m_unitFieldHoverheight), HoverHeightChangeHandler, nullptr); } -// VERIFY: 28c9a3d4 manual +// VERIFY: 33345d3b manual // OFFSET: 0x00742220 void CGUnit_C::Initialize() { ClientServices::SetMessageHandler(MSG_MOVE_START_FORWARD, CGUnit_C::HandleMovementPacket, nullptr); @@ -5205,7 +5220,7 @@ void CGUnit_C::Initialize() { CVehicleCamera_C::InitSystem(); CGUnit_C::InitMissileTrajectorySystem(); CGUnit_C::VehiclePassengerInitWorldCameraState(); - s_unitThreatPool = new (__FILE__, __LINE__) uint32_t(ObjectAllocAddHeap(sizeof(UnitThreat), 16, "Unit Threat", true)); + s_unitThreatPool = new (__FILE__, __LINE__) UnitThreatHeap{ ObjectAllocAddHeap(sizeof(UnitThreat), 16, "Unit Threat", true) }; CGUnit_C::s_deferredClientControlUpdateGUID = WOWGUID(); CGUnit_C::s_deferredClientControlUpdateState = 0; CGUnit_C::s_initialized = 1; @@ -9734,7 +9749,7 @@ ATTACKROUNDINFO::ATTACKROUNDINFO() { } } -// VERIFY: 59559f5d manual +// VERIFY: b7b8d211 manual // OFFSET: 0x0073F660 CGUnit_C::CGUnit_C(uint32_t time, const CClientObjCreate& create) : CGObject_C(time, create), @@ -9768,12 +9783,12 @@ CGUnit_C::CGUnit_C(uint32_t time, const CClientObjCreate& create) unk_09D0(0), m_displayId(0), m_groundNormal(0.0f, 0.0f, 1.0f), - unk_09E8(0), + m_lastMissileTime(0), m_missiles(nullptr), m_pendingMissiles(nullptr), m_shapeshiftSuppressed(0), unk_09F8(0), - unk_0A1C(0), + m_nextBloodPoolTime(0), m_combat(), m_stopAttackSent(0), m_animationState(0x70), @@ -9846,7 +9861,7 @@ CGUnit_C::CGUnit_C(uint32_t time, const CClientObjCreate& create) unk_0FA4(-1), m_precastMissileModel(nullptr), m_predictedHealth(this->m_unit->m_unitFieldHealth), - unk_0FD0(0), + m_powerRegenRemainder(0), m_manaRegenInterruptTime(0) { this->m_movement = &this->m_movementData; this->unk_0A34 = 0; @@ -10055,7 +10070,7 @@ void CGUnit_C::InitializeActivePlayerComponent() { } } -// VERIFY: c420fadb manual +// VERIFY: 8241be39 manual // OFFSET: 0x0073FCC0 void CGUnit_C::PostInit(uint32_t time, const CClientObjCreate& create, bool reenable) { this->m_movementData.UpdateTransportStatus(create); @@ -10130,7 +10145,7 @@ void CGUnit_C::PostInit(uint32_t time, const CClientObjCreate& create, bool reen } else { this->m_lootableTime = time; this->ClearEffectList(0); - this->Unk717BA0(); + this->ShowLootEffect(); } int32_t groundType; @@ -10316,7 +10331,7 @@ void CGUnit_C::SetAttacking(WOWGUID guid) { this->m_combat.m_attackSent = 0; } -// VERIFY: 45113d1b manual +// VERIFY: 2844abe5 manual // OFFSET: 0x007237F0 void CGUnit_C::Reenable() { CGObject_C::Reenable(); @@ -10341,7 +10356,7 @@ void CGUnit_C::Reenable() { this->m_predictedHealth = this->m_unit->m_unitFieldHealth; this->InitPredictedPower(); - this->unk_0FD0 = 0; + this->m_powerRegenRemainder = 0; this->m_manaRegenInterruptTime = 0; if (static_cast(this->m_unit->m_unitFieldHealth) / static_cast(this->m_unit->m_unitFieldMaxhealth) < 0.2f && !this->IsDeadOrGhost() && this->m_bloodlevels) { @@ -10364,7 +10379,7 @@ void CGUnit_C::Reenable() { this->m_worldModel->m_lastAnimTime = 0; } - this->Unk717BA0(); + this->ShowLootEffect(); for (int32_t i = 0; i < 3; i++) { ItemRec* rec = g_itemDB.GetRecord(this->m_unit->m_unitVirtualItemSlotId[i]); @@ -10404,7 +10419,7 @@ void CGUnit_C::Reenable() { this->UpdateObjectEffectMovementStates(); } -// VERIFY: 10fdac8a manual +// VERIFY: 6423fc74 manual // OFFSET: 0x007402B0 void CGUnit_C::PostReenable() { CGObject_C::PostReenable(); @@ -10430,7 +10445,7 @@ void CGUnit_C::PostReenable() { if (this->m_unit->m_unitFieldHealth <= 0 && !this->m_lootableTime) { this->m_lootableTime = FrameTime::s_curTimeMs; - this->Unk717BA0(); + this->ShowLootEffect(); } this->m_movementData.SnapToGroundIfCloseEnough(); @@ -13943,7 +13958,7 @@ void AuraData::Unpack(CGUnit_C* unit, uint32_t time, CDataStore* msg) { } } -// VERIFY: a32c84f6 manual +// VERIFY: 32bbf304 manual // OFFSET: 0x0072F360 void CGUnit_C::AddAuraSlot(uint8_t slot) { uint32_t count = this->m_auras.m_count == 0xFFFFFFFF ? this->m_auras.m_dynamic.m_count : this->m_auras.m_count; @@ -13962,8 +13977,8 @@ void CGUnit_C::AddAuraSlot(uint8_t slot) { this->m_sortedAuras[j].SetCount(slot + 1); for (uint32_t i = count; i <= slot; i++) { - this->m_sortedAuras[j][i].unk_0000 = 256; - this->m_sortedAuras[j][i].unk_0004 = 0; + this->m_sortedAuras[j][i].m_auraIndex = 256; + this->m_sortedAuras[j][i].m_spellId = 0; } } @@ -15035,7 +15050,7 @@ void CGUnit_C::AnimEndCallback(CM2Model* model, uint32_t boneId, uint32_t sequen } } -// VERIFY: 42b3a719 manual +// VERIFY: 798be0ff manual // OFFSET: 0x0073BBD0 void CGUnit_C::AnimEndHandler(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time) { if (this->m_vehiclePassenger && this->m_vehiclePassenger->m_state) { @@ -15054,7 +15069,7 @@ void CGUnit_C::AnimEndHandler(CM2Model* model, uint32_t boneId, uint32_t sequenc this->m_lootableTime = FrameTime::s_curTimeMs; } - this->Unk717BA0(); + this->ShowLootEffect(); } if (static_cast(sequenceId) == this->GetPrecastStartAnim()) { @@ -16084,13 +16099,13 @@ int32_t CGUnit_C::GetDisplayClassGender(const CGUnit_C* unit, const NameCache* n return displaySex; } -// VERIFY: 792154c7 manual +// VERIFY: 61b56493 manual // OFFSET: 0x007283A0 -bool CGUnit_C::AffectedByAura(int32_t auraType, const SpellRec* spell) { +bool CGUnit_C::AffectedByAura(int32_t auraType, const SpellRec* spell) const { SpellRec auraSpell; for (uint32_t i = 0; i < this->GetAuraCount(); i++) { - AuraData* aura = &this->m_auras[i]; + const AuraData* aura = &const_cast(this)->m_auras[i]; if (!g_spellDB.GetRecord(aura->m_spellId, &auraSpell)) { continue; @@ -16213,3 +16228,4303 @@ const char* CGUnit_C::GetDisplayClassName(const CGUnit_C* unit, const NameCache* return CGUnit_C::GetDisplayClassName(unit, name, nullptr); } + +// VERIFY: 96f9d57c auto +// OFFSET: 0x00726240 +void CGUnit_C::DelayCast(int32_t delay) { + this->m_castStartTime += delay; + this->m_castEndTime += delay; + this->m_channelSpellId = 0; + this->m_channelStartTime = 0; + this->m_channelEndTime = 0; + this->UpdateSpellCastBars(FrameTime::s_curTimeMs); +} + +// VERIFY: e645d0ea auto +// OFFSET: 0x0072AC50 +void CGUnit_C::SetUICastingDirect(int32_t spellId, const WOWGUID& target, uint32_t start, uint32_t end) { + this->m_castingSpellId = spellId; + this->m_castingObject = target; + this->m_castStartTime = start; + this->m_castEndTime = end; + + if (this->m_obj->m_guid == CGGameUI::m_lockedTarget || this->m_obj->m_guid == CGGameUI::unk_BD07D0) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + this->ProcessCastNotInterruptible(&spell); + } + } + + this->m_channelSpellId = 0; + this->m_channelStartTime = 0; + this->m_channelEndTime = 0; + this->UpdateSpellCastBars(FrameTime::s_curTimeMs); +} + +// VERIFY: 06954a90 auto +// OFFSET: 0x0072AE00 +void CGUnit_C::SetUIChannelDirect(int32_t spellId, uint32_t start, uint32_t end) { + this->m_channelSpellId = spellId; + this->m_channelStartTime = start; + this->m_channelEndTime = end; + + if (this->m_obj->m_guid == CGGameUI::m_lockedTarget || this->m_obj->m_guid == CGGameUI::unk_BD07D0) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + this->ProcessCastNotInterruptible(&spell); + } + } + + this->m_castingSpellId = 0; + this->m_castStartTime = 0; + this->m_castEndTime = 0; + this->UpdateSpellCastBars(FrameTime::s_curTimeMs); +} + +// VERIFY: 49e3df47 auto +// OFFSET: 0x00741210 +void CGUnit_C::UpdateChainTargets(const TSStackArray& targets, int32_t spellId) { + WOWGUID first = targets.m_data[0]; + + if (first && first != this->m_unit->m_unitFieldChannelObject) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && (spell.m_attributesEx & 0x4)) { + this->m_unit->m_unitFieldChannelObject = targets.m_data[0]; + } + } + + this->SaveChainSpellTargets(targets); + this->OnChannelSpellChanged(spellId); +} + +// VERIFY: ab8a24d3 manual +// OFFSET: 0x0074C7F0 +void CGUnit_C::VehicleExit() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (this->m_obj->m_guid == CGUnit_C::s_activeMover && player && player->GetTransportGUID() == this->m_obj->m_guid.m_guid) { + CGPetInfo::PetDismiss(); + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_REQUEST_VEHICLE_EXIT)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 63490106 auto +// OFFSET: 0x0071F060 +void WriteMovementPacket(CGUnit_C* unit, uint32_t msgId, CDataStore* msg, int32_t include) { + if (!include || !unit || !unit->IsAllowedToSendMessage(msgId)) { + msg->Put(static_cast(0)); + return; + } + + msg->Put(static_cast(1)); + unit->BuildMovementUpdate(MovementGetIdleTime(), msgId, msg, 0.0f, 0); +} + +// VERIFY: 0ca23980 manual +// OFFSET: 0x00728500 +bool CGUnit_C::HasDispellableAura(int32_t dispelType, int32_t harmful, bool mechanic, bool steal) { + uint32_t mask = 0; + + if (!mechanic) { + SpellDispelTypeRec* rec = g_spellDispelTypeDB.GetRecord(dispelType); + mask = rec && rec->m_mask ? rec->m_mask : 1 << dispelType; + } + + bool charmed = false; + + if (this->m_unit->m_unitFieldCharmedby && (this->m_obj->m_guid.m_guid & 0xF0F0000000000000ull) != 0xF050000000000000ull) { + if (!harmful) { + return false; + } + + if (harmful == 1) { + harmful = 0; + charmed = true; + } + } + + for (uint32_t i = 0; i < this->GetAuraCount(); i++) { + uint32_t count = this->m_auras.m_count == 0xFFFFFFFF ? this->m_auras.m_dynamic.m_count : this->m_auras.m_count; + AuraData* aura = i < count ? &this->m_auras[i] : nullptr; + + if (harmful == 1 && (aura->m_flags & 0x80)) { + continue; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_auras[i].m_spellId, &spell) || (spell.m_attributes & 0x40)) { + continue; + } + + bool area = false; + + for (uint32_t j = 0; j < 3; j++) { + if ((aura->m_flags & (1 << j)) && Spell_IsAreaAuraEffect(spell.m_effect[j])) { + area = true; + break; + } + } + + if (area) { + continue; + } + + if (charmed) { + bool charm = false; + + if ((spell.m_effect[0] == 6 || spell.m_effect[0] == 177 || spell.m_effect[0] == 2) && (this->m_auras[i].m_flags & 0x1)) { + charm = true; + } + + if ((spell.m_effect[1] == 6 || spell.m_effect[1] == 177 || spell.m_effect[1] == 2) && (this->m_auras[i].m_flags & 0x2)) { + charm = true; + } + + if ((spell.m_effect[2] == 6 || spell.m_effect[2] == 177 || spell.m_effect[2] == 2) && (this->m_auras[i].m_flags & 0x4)) { + charm = true; + } + + if (!charm) { + continue; + } + } + + if (steal && ((spell.m_attributesEx & 0x44) || (spell.m_attributesExD & 0x40))) { + continue; + } + + if (mechanic) { + if (spell.m_mechanic == dispelType) { + return true; + } + + int32_t effects = 0; + + if (spell.m_effect[0] && spell.m_effectMechanic[0] == dispelType) { + effects = 1; + } + + if (spell.m_effect[1] && spell.m_effectMechanic[1] == dispelType) { + effects |= 2; + } + + if (spell.m_effect[2] && spell.m_effectMechanic[2] == dispelType) { + effects |= 4; + } + + if (effects) { + return true; + } + } else if ((1 << spell.m_dispelType) & mask) { + return true; + } + } + + return false; +} + +// VERIFY: 29d19ef8 manual +// OFFSET: 0x0074CCE0 +void CGUnit_C::CheckVehicleExitOnCast() { + VehicleSeatRec* seat = this->m_vehiclePassenger ? this->m_vehiclePassenger->m_seatRec : nullptr; + + if (!seat || !(seat->m_flagsB & 0x100000)) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (this->m_obj->m_guid != CGUnit_C::s_activeMover || !player || player->GetTransportGUID() != this->m_obj->m_guid.m_guid) { + this->VehicleExit(); + } +} + +// VERIFY: 96853cac manual +// OFFSET: 0x0071C8F0 +uint8_t CGUnit_C::GetActivePlayerFieldBytes0() { + if (this->m_obj->m_guid != ClntObjMgrGetActivePlayer()) { + return 0; + } + + return static_cast(this)->m_player->m_playerFieldBytes[0]; +} + +// VERIFY: b01b02ca auto +// OFFSET: 0x00720B30 +bool CGUnit_C::GetSpellRequiredLevel(int32_t spellId, int32_t* level) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return false; + } + + SkillLineAbilityRec* ability = this->LookupAbility(spellId); + + if (!ability) { + return false; + } + + const SkillRaceClassInfoRec* info = SpellTableLookupInfo(this->m_unit->m_unitFieldBytes0[0], this->m_unit->m_unitFieldBytes0[1], ability->m_skillLine); + + if (info) { + int32_t required = info->m_minLevel; + + if (spell.m_spellLevel > required) { + required = spell.m_spellLevel; + } + + *level = required; + return true; + } + + *level = spell.m_spellLevel; + return true; +} + +// VERIFY: 51855a30 manual +// OFFSET: 0x00739650 +bool CGUnit_C::CheckAndReportSpellInhibitFlags(PendingSpellCast* cast, const SpellRec* spell, const CGItem_C* item) { + if (!spell) { + SErrSetLastError(STORM_ERROR_INVALID_PARAMETER); + return false; + } + + MapRec* map = g_mapDB.GetRecord(CGGameUI::m_iCurrentMapID); + + if (map) { + if (!CGUnit_C::IsSpellAllowedInArena(spell)) { + Spell_C_SpellFailed(cast, spell, 151, -1, -1, false); + return false; + } + + if (map->m_instanceType != 4 && (spell->m_attributesExF & 0x2)) { + Spell_C_SpellFailed(cast, spell, 168, -1, -1, false); + return false; + } + } + + if (item) { + if (Spell_C_GetItemCooldown(const_cast(item), nullptr, nullptr, nullptr)) { + Spell_C_SpellFailed(cast, spell, 45, -1, -1, false); + return false; + } + } else { + bool player = this->m_obj->m_guid == ClntObjMgrGetActivePlayer(); + + if (Spell_C_GetSpellCooldown(spell->m_id, !player, nullptr, nullptr, nullptr)) { + Spell_C_SpellFailed(cast, spell, 67, -1, -1, false); + return false; + } + + if (!Spell_C_HaveSpellPower(this, spell)) { + Spell_C_SpellFailed(cast, spell, 85, -1, -1, false); + return false; + } + } + + for (uint32_t i = 0; i < sizeof(spell->m_effect) / sizeof(spell->m_effect[0]); i++) { + int32_t effect = spell->m_effect[i]; + + if (effect == 36) { + int32_t learn = spell->m_effectTriggerSpell[i]; + + if (!learn) { + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(item->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (stats) { + for (uint32_t j = 0; j < 5; j++) { + if (stats->m_spellTrigger[j] == 6) { + learn = stats->m_spellId[j]; + break; + } + } + } + } + + if (this->IsSpellKnown(learn) || this->IsSpellSuperceded(learn)) { + SpellRec known; + + if (g_spellDB.GetRecord(learn, &known)) { + CGGameUI::DisplayError(ERR_SPELL_ALREADY_KNOWN_S, known.m_name); + } else { + CGGameUI::DisplayError(ERR_SPELL_ALREADY_KNOWN_S, "UNKNOWN"); + } + + return false; + } + } + + if (effect == 56 || effect == 55 || spell->m_effectAura[i] == 6 || spell->m_effectAura[i] == 2) { + const WOWGUID* controlled = &this->m_unit->m_unitFieldCharm; + + if (!*controlled) { + controlled = &this->m_unit->m_unitFieldSummon; + } + + if (*controlled && !(spell->m_attributesEx & 0x1)) { + Spell_C_SpellFailed(cast, spell, this->m_unit->m_unitFieldCharm ? 6 : 7, -1, -1, false); + return false; + } + } + + if (spell->m_implicitTargetA[i] == 5 || spell->m_implicitTargetB[i] == 5) { + const WOWGUID* controlled = &this->m_unit->m_unitFieldCharm; + + if (!*controlled) { + controlled = &this->m_unit->m_unitFieldSummon; + } + + if (!*controlled) { + Spell_C_SpellFailed(cast, spell, 84, -1, -1, false); + return false; + } + + if (effect == 36) { + const WOWGUID* pet = &this->m_unit->m_unitFieldCharm; + + if (!*pet) { + pet = &this->m_unit->m_unitFieldSummon; + } + + CGUnit_C* petUnit = static_cast(ClntObjMgrObjectPtr(*pet, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (petUnit) { + int32_t learn = spell->m_effectTriggerSpell[i]; + int32_t level; + + if (!petUnit->GetSpellRequiredLevel(learn, &level)) { + Spell_C_SpellFailed(cast, spell, 107, -1, -1, false); + return false; + } + + if (petUnit->IsSpellKnown(learn) || petUnit->IsSpellSuperceded(learn)) { + CGGameUI::DisplayError(ERR_PET_SPELL_ALREADY_KNOWN_S, spell->m_name); + Spell_C_SpellFailed(cast, spell, 27, -1, -1, false); + return false; + } + } + } + } + } + + int32_t reason; + + if (this->m_unit->m_unitFieldHealth > 0) { + if ((this->m_obj->m_type & TYPEMASK_PLAYER) && (static_cast(this)->m_player->m_playerFieldBytes[0] & 0x4)) { + Spell_C_SpellFailed(cast, spell, 105, -1, -1, false); + return false; + } + + if (this->m_unit->m_unitFieldCharmedby && this->m_unit->m_unitFieldCharmedby != ClntObjMgrGetActivePlayer() && !Spell_C_CancelsCharm(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 24, -1, -1, false); + } + + return false; + } + + if ((this->m_unit->m_unitFieldFlags & 0x40000) && !(spell->m_attributesExE & 0x8) && !(spell->m_attributesExG & 0x100000) && !Spell_C_CancelsStun(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 108, -1, -1, false); + } + + return false; + } + + if (spell->m_preventionType == 1 && (this->m_unit->m_unitFieldFlags & 0x2000) && !Spell_C_CancelsSilence(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 104, -1, -1, false); + } + + return false; + } + + if (spell->m_preventionType == 2 && (this->m_unit->m_unitFieldFlags & 0x20000) && !Spell_C_CancelsPacify(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 98, -1, -1, false); + } + + return false; + } + + if ((this->m_unit->m_unitFieldFlags & 0x800000) && !(spell->m_attributesExE & 0x20000) && !(spell->m_attributesExG & 0x100000) && !Spell_C_CancelsFear(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 34, -1, -1, false); + } + + return false; + } + + if ((this->m_unit->m_unitFieldFlags & 0x400000) && !(spell->m_attributesExE & 0x40000) && !(spell->m_attributesExG & 0x100000) && !Spell_C_CancelsConfuse(this, spell, &reason)) { + if (reason) { + Spell_C_SpellFailed(cast, spell, 147, reason, -1, false); + } else { + Spell_C_SpellFailed(cast, spell, 26, -1, -1, false); + } + + return false; + } + } + + int32_t auraInterrupt = spell->m_auraInterruptFlags; + + if (((auraInterrupt & 0x200) && !this->m_sheatheState) || ((spell->m_attributesEx & 0x44) && (spell->m_channelInterruptFlags & 0x200) && !this->m_sheatheState)) { + Spell_C_SpellFailed(cast, spell, 72, -1, -1, false); + return false; + } + + if (((auraInterrupt & 0x40) && (this->m_mountDisplayId <= 0 || (this->m_clientFlags & 0x10000000))) || ((spell->m_attributesEx & 0x44) && (spell->m_channelInterruptFlags & 0x40) && !this->IsMounted())) { + Spell_C_SpellFailed(cast, spell, 91, -1, -1, false); + return false; + } + + if (!(spell->m_attributes & 0x1000000) && this->m_mountDisplayId > 0 && !(this->m_clientFlags & 0x10000000) && !this->MountedCombatAllowed() && !this->CanAutoDismount()) { + Spell_C_SpellFailed(cast, spell, 64, -1, -1, false); + return false; + } + + if (!(spell->m_attributes & 0x8000000) && this->GetClientStandState() && !this->CanAutoStand()) { + Spell_C_SpellFailed(cast, spell, 69, -1, -1, false); + return false; + } + + if ((spell->m_attributes & 0x1000) && !g_clientGameTime.IsDaytime()) { + Spell_C_SpellFailed(cast, spell, 89, -1, -1, false); + return false; + } + + if ((spell->m_attributes & 0x2000) && g_clientGameTime.IsDaytime()) { + Spell_C_SpellFailed(cast, spell, 92, -1, -1, false); + return false; + } + + auraInterrupt = spell->m_auraInterruptFlags; + int32_t channeled = spell->m_attributesEx & 0x44; + + if (((auraInterrupt & 0x100) && !(this->m_clientFlags & 0x200000)) || (channeled && (spell->m_channelInterruptFlags & 0x100) && !(this->m_clientFlags & 0x200000))) { + Spell_C_SpellFailed(cast, spell, 96, -1, -1, false); + return false; + } + + if (((auraInterrupt & 0x80) && (this->m_clientFlags & 0x200000)) || (channeled && (spell->m_channelInterruptFlags & 0x80) && (this->m_clientFlags & 0x200000))) { + Spell_C_SpellFailed(cast, spell, 88, -1, -1, false); + return false; + } + + if ((channeled && (spell->m_channelInterruptFlags & 0x18) && (this->m_movement->m_flags & 0xC0100F) && !(spell->m_targets & 0x60)) || ((spell->m_interruptFlags & 0x1) && (this->m_movement->m_flags & 0xC0100F) && !(spell->m_targets & 0x60) && !(spell->m_attributesExB & 0x20) && (SpellRec::GetCastTime(spell, this->m_unit->m_unitFieldPetnumber != 0, 0, 0) || (spell->m_auraInterruptFlags & 0x18)))) { + Spell_C_SpellFailed(cast, spell, 51, -1, -1, false); + return false; + } + + if (!this->CheckShapeshiftRules(spell, &reason) && (reason == 94 || !this->CanAutoUnshift())) { + Spell_C_SpellFailed(cast, spell, reason, -1, -1, false); + return false; + } + + if (!this->CheckStealthRules(spell, &reason)) { + Spell_C_SpellFailed(cast, spell, reason, -1, -1, false); + return false; + } + + if ((spell->m_attributes & 0x10000000) && (this->m_unit->m_unitFieldFlags & 0x80000) && !this->IgnoresAuraState(spell)) { + Spell_C_SpellFailed(cast, spell, 1, -1, -1, false); + return false; + } + + if (spell->m_casterAuraState && !this->HasAuraState(spell->m_casterAuraState) && !this->IgnoresAuraState(spell)) { + Spell_C_SpellFailed(cast, spell, 22, -1, -1, false); + return false; + } + + if (spell->m_excludeCasterAuraState && this->HasAuraState(spell->m_excludeCasterAuraState) && !this->IgnoresAuraState(spell)) { + Spell_C_SpellFailed(cast, spell, 22, -1, -1, false); + return false; + } + + int32_t casterAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_casterAuraSpell); + + if (casterAura && !this->HasAuraBySpellId(casterAura) && !this->IgnoresAuraState(spell)) { + Spell_C_SpellFailed(cast, spell, 22, -1, -1, false); + return false; + } + + int32_t excludeCasterAura = QuestTextParser::Spell_C_SpellGetSpellIDForDifficulty(spell->m_excludeCasterAuraSpell); + + if (excludeCasterAura && this->HasAuraBySpellId(excludeCasterAura) && !this->IgnoresAuraState(spell)) { + Spell_C_SpellFailed(cast, spell, 22, -1, -1, false); + return false; + } + + if (spell->m_minFactionID && GetRepListRepValue(spell->m_minFactionID) < CGReputationInfo::m_reactionThresholds[spell->m_minReputation]) { + Spell_C_SpellFailed(cast, spell, 149, -1, -1, false); + return false; + } + + if (spell->m_requiredAreasID > 0) { + AreaTableRec* area = CGGameUI::GetCurrentSubzoneRec(); + + if (!area) { + Spell_C_SpellFailed(cast, spell, 39, -1, -1, false); + return false; + } + + int32_t group = spell->m_requiredAreasID; + int32_t checked; + + if (!CGUnit_C::IsAreaInAreaGroup(area->m_id, group, &checked)) { + if (checked == 1) { + AreaGroupRec* groupRec = g_areaGroupDB.GetRecord(group); + + if (groupRec) { + Spell_C_SpellFailed(cast, spell, 101, groupRec->m_areaID[0], -1, false); + return false; + } + } + + Spell_C_SpellFailed(cast, spell, 39, -1, -1, false); + return false; + } + } + + if (spell->m_attributes & 0xC000) { + if (this->IsOutdoors()) { + if (spell->m_attributes & 0x4000) { + Spell_C_SpellFailed(cast, spell, 90, -1, -1, false); + return false; + } + } else if (spell->m_attributes & 0x8000) { + Spell_C_SpellFailed(cast, spell, SpellRec::HasAura(spell, 78) ? 83 : 93, -1, -1, false); + return false; + } + } + + if ((spell->m_attributesExD & 0x4000000) && !static_cast(this)->IsInFlyableZone(!(spell->m_attributesExG & 0x400000))) { + Spell_C_SpellFailed(cast, spell, 60, -1, -1, false); + return false; + } + + int32_t mapId = CGGameUI::m_iCurrentMapID; + MapRec* current; + + if ((spell->m_attributesExC & 0x800) && (current = g_mapDB.GetRecord(mapId)) != nullptr && current->m_instanceType != 3) { + Spell_C_SpellFailed(cast, spell, 142, -1, -1, false); + return false; + } + + if ((spell->m_attributesExF & 0x800) && (current = g_mapDB.GetRecord(mapId)) != nullptr && current->m_instanceType == 2) { + Spell_C_SpellFailed(cast, spell, 167, -1, -1, false); + return false; + } + + if ((spell->m_attributesExB & 0x10000) && (this->m_obj->m_type & TYPEMASK_PLAYER) && (this->GetActivePlayerFieldBytes0() & 0x1)) { + Spell_C_PetTameFailure(2); + Spell_C_SpellFailed(cast, spell, 27, -1, -1, false); + return false; + } + + return true; +} + +// VERIFY: 90d66722 manual +// OFFSET: 0x00727C00 +void CGUnit_C::InsertSortedAura(uint32_t list, uint32_t auraIndex, int32_t position) { + AuraData* aura = auraIndex < this->GetAuraCount() ? &this->m_auras[auraIndex] : nullptr; + WOWGUID player = ClntObjMgrGetActivePlayer(); + TSCGrowableArray& sorted = this->m_sortedAuras[list]; + + if (position) { + if (CGSpellBook::IsAuraCaster(player, &aura->m_creator)) { + int32_t i = position - 1; + + for (; i >= 0; i--) { + uint32_t otherIndex = sorted[i].m_auraIndex; + AuraData* other = otherIndex < this->GetAuraCount() ? &this->m_auras[otherIndex] : nullptr; + + if (CGSpellBook::IsAuraCaster(player, &other->m_creator)) { + break; + } + + sorted[i + 1] = sorted[i]; + } + + position = i + 1; + } else if (CGSpellBook::CanApplyAura(aura)) { + int32_t i = position - 1; + + for (; i >= 0; i--) { + AuraData* other = this->GetAura(sorted[i].m_auraIndex); + + if (CGSpellBook::IsAuraCaster(player, &other->m_creator) || CGSpellBook::CanApplyAura(other)) { + break; + } + + sorted[i + 1] = sorted[i]; + } + + position = i + 1; + } + } + + sorted[position].m_auraIndex = auraIndex; + sorted[position].m_spellId = aura->m_spellId; +} + +// VERIFY: 2d8ce268 manual +// OFFSET: 0x0072C510 +void CGUnit_C::SortAuras() { + for (uint32_t list = 0; list < 2; list++) { + TSCGrowableArray& sorted = this->m_sortedAuras[list]; + uint32_t i = 0; + + while (i < this->GetAuraCount() && sorted[i].m_spellId) { + AuraData& aura = this->m_auras[sorted[i].m_auraIndex]; + + if (aura.m_spellId == sorted[i].m_spellId && (aura.m_flags & 0x7)) { + i++; + continue; + } + + uint32_t last = this->GetAuraCount() - 1; + + if (i < last) { + memcpy(&sorted[i], &sorted[i + 1], sizeof(SortedAuraInfo) * (last - i)); + } + + sorted[last].m_auraIndex = 256; + sorted[last].m_spellId = 0; + } + } + + SpellRec spell; + + for (uint32_t index = this->GetAuraCount(); index; ) { + index--; + + AuraData* aura = index < this->GetAuraCount() ? &this->m_auras[index] : nullptr; + + if (!aura->m_spellId || !(aura->m_flags & 0x7) || !g_spellDB.GetRecord(aura->m_spellId, &spell)) { + continue; + } + + if (!CGSpellBook::CanShowAura(&spell, &aura->m_creator, (this->m_auras[index].m_flags & 0x8) != 0)) { + continue; + } + + for (uint32_t j = 0; j < this->GetAuraCount(); j++) { + if (this->m_sortedAuras[0][j].m_spellId <= 0) { + this->InsertSortedAura(0, index, j); + break; + } + + if (this->m_sortedAuras[0][j].m_spellId == aura->m_spellId && this->m_sortedAuras[0][j].m_auraIndex == index) { + break; + } + } + + if ((!(aura->m_flags & 0x80) && CGSpellBook::FindRaidBuff(aura->m_spellId)) || ((aura->m_flags & 0x80) && CGSpellBook::FindRaidDispel(spell.m_dispelType))) { + for (uint32_t j = 0; j < this->GetAuraCount(); j++) { + if (this->m_sortedAuras[1][j].m_spellId <= 0) { + this->InsertSortedAura(1, index, j); + break; + } + + if (this->m_sortedAuras[1][j].m_spellId == aura->m_spellId && this->m_sortedAuras[1][j].m_auraIndex == index) { + break; + } + } + } + } + + this->m_clientFlags |= 0x40000; +} + +// VERIFY: 170ff0ae manual +// OFFSET: 0x0072C9B0 +uint32_t CGUnit_C::GetSortedAuraSlot(int32_t index, const char* name, const char* rank, uint32_t filter) { + if (index < 0 && !name) { + return 0xFFFFFFFF; + } + + if (!(this->m_clientFlags & 0x40000)) { + this->SortAuras(); + } + + WOWGUID player = ClntObjMgrGetActivePlayer(); + bool helpful = filter & 0x1; + bool playerOnly = (filter & 0x4) != 0; + int32_t found = 0; + + if (!this->GetAuraCount()) { + return 0xFFFFFFFF; + } + + TSCGrowableArray& sorted = this->m_sortedAuras[(filter & 0x8) != 0]; + + for (uint32_t i = 0; i < this->GetAuraCount(); i++) { + uint32_t auraIndex = sorted[i].m_auraIndex; + AuraData* aura = auraIndex < this->GetAuraCount() ? &this->m_auras[auraIndex] : nullptr; + + if (!aura || !aura->m_spellId || helpful != !(aura->m_flags & 0x80)) { + continue; + } + + if (playerOnly && !CGSpellBook::IsAuraCaster(player, &aura->m_creator)) { + continue; + } + + if ((aura->m_flags & 0x10) ? (filter & 0x20) : (filter & 0x10)) { + continue; + } + + if (index >= 0) { + if (index == found) { + return auraIndex; + } + + found++; + continue; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(this->GetAuraSpellId(auraIndex), &spell) && !SStrCmpUTF8I(name, spell.m_name, STORM_MAX_STR) && (!rank || !SStrCmpUTF8I(rank, spell.m_nameSubtext, STORM_MAX_STR))) { + return auraIndex; + } + } + + return 0xFFFFFFFF; +} + +// VERIFY: 35708e69 auto +// OFFSET: 0x0071AB80 +void CGUnit_C::ReleaseAurasBySpell(int32_t spellId) { + CEffect* effect = this->m_auraEffects; + + while (effect) { + CEffect* next = effect->m_next; + + if (effect->m_spellId == static_cast(spellId)) { + this->m_forceWorldModelAlpha = effect->m_kitRec && (effect->m_kitRec->m_flags & 0x400); + effect->Release(); + } + + effect = next; + } +} + +// VERIFY: 0c11fba1 auto +// OFFSET: 0x0071BB70 +float CGUnit_C::GetSpellChanceToCrit() const { + float base = GetGameTableValue(5, 0, this->m_unit->m_unitFieldBytes0[1] - 1); + float ratio = GetGameTableValue(4, this->m_unit->m_unitFieldLevel - 1, this->m_unit->m_unitFieldBytes0[1] - 1); + + if (ratio == 0.0f) { + return 0.0f; + } + + int32_t intellect = this->m_unit->m_unitFieldStat[3]; + return (ratio * (intellect < 0 ? 0 : intellect) + base) * 100.0f; +} + +// VERIFY: 8a2697bd auto +// OFFSET: 0x00722090 +void CGUnit_C::OnAuraRemoved(uint32_t index, uint8_t a3, AuraData* aura, int32_t spellId) { + SpellRec spell; + memset(&spell, 0, sizeof(spell)); + g_spellDB.GetRecord(spellId, &spell); + this->RemoveAuraEffect(index, &spell); + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGActionBar::OnAuraChanged(spellId); + + if (CGSpellBook::IsTrackingSpell(spellId)) { + CGMinimapFrame::SetTrackingSpell(0); + } + + if (CGSpellBook::IsShapeshiftSpell(spellId) && !SpellRec::HasAura(&spell, 36)) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_SHAPESHIFT_FORM, nullptr); + } + } + + UnitCombatLogAuraAddedOrRemoved(this, aura, &spell, a3, 0); +} + +// VERIFY: c0256707 auto +// OFFSET: 0x00727760 +void CGUnit_C::OnAuraAdded(uint32_t index, uint8_t a3, AuraData* aura, int32_t spellId) { + SpellRec spell; + memset(&spell, 0, sizeof(spell)); + g_spellDB.GetRecord(spellId, &spell); + this->AddAuraEffect(index, &spell); + UnitCombatLogAuraAddedOrRemoved(this, aura, &spell, a3, 1); + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGActionBar::OnAuraChanged(spellId); + + if (spellId != CGMinimapFrame::s_trackingSpell && CGSpellBook::IsTrackingSpell(spellId)) { + CGMinimapFrame::SetTrackingSpell(spellId); + } + + if (CGSpellBook::IsShapeshiftSpell(spellId) && !SpellRec::HasAura(&spell, 36)) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_SHAPESHIFT_FORM, nullptr); + } + } +} + +// VERIFY: 1f07a103 manual +// OFFSET: 0x00727A70 +void CGUnit_C::AuraVisionUpdated(uint8_t vision) { + bool changed = false; + + for (uint32_t i = 0; i < this->GetAuraCount(); i++) { + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_auras[i].m_spellId, &spell)) { + continue; + } + + uint8_t mask = GetRequiredAuraVisionBitmask(&spell); + + if (!(mask & vision)) { + continue; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (mask & reinterpret_cast(&player->m_player->m_playerFieldBytes2)[3]) { + this->AddAuraEffect(i, &spell); + } else { + this->RemoveAuraEffect(i, &spell); + } + + changed = true; + } + + if (changed) { + Script_SendUniqueSignal(this->m_obj->m_guid, SCRIPT_EVENT_UNIT_AURA); + } +} + +// VERIFY: 9c454b2a manual +// OFFSET: 0x00728E70 +void CGUnit_C::ScanAuraSpellsOnDisplayUpdate() { + SpellRec spell; + + for (uint32_t i = this->GetAuraCount(); i; ) { + i--; + + int32_t spellId = this->m_auras[i].m_spellId; + + if (spellId && g_spellDB.GetRecord(spellId, &spell)) { + this->AddAuraEffect(i, &spell); + } + } +} + +// VERIFY: 975b5867 manual +// OFFSET: 0x00724820 +void CGUnit_C::AddAuraEffect(uint32_t index, const SpellRec* spell) { + uint32_t count = this->unk_0EDC.m_count == 0xFFFFFFFF ? this->unk_0EDC.m_dynamic.m_count : this->unk_0EDC.m_count; + + if (index >= count) { + return; + } + + int32_t spellId = this->m_auras[index].m_spellId; + bool hasSpell = spell != nullptr; + + if (this->unk_0EDC[index]) { + if (!hasSpell) { + goto store; + } + + if (this->unk_0EDC[index] == static_cast(spell->m_id)) { + return; + } + + SpellRec current; + + if (g_spellDB.GetRecord(this->unk_0EDC[index], ¤t) && current.m_spellPriority > spell->m_spellPriority) { + return; + } + } + + if (hasSpell) { + uint32_t mask = GetRequiredAuraVisionBitmask(spell); + + if (mask) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || !(static_cast(mask) & reinterpret_cast(&player->m_player->m_playerFieldBytes2)[3])) { + return; + } + } + } + +store: + this->unk_0EDC[index] = spellId; + + if (!hasSpell) { + return; + } + + const int32_t* visualIds = spell->m_spellVisualID; + + if (!visualIds) { + return; + } + + if (this->IsActivePlayer()) { + for (uint32_t i = 0; i < 3; i++) { + switch (spell->m_effectAura[i]) { + case 76: + CGWorldFrame::GetActiveCamera()->SetTelescope(spell->m_effectMiscValue[i]); + break; + + case 233: + EnumVisibleForAuraEffect(spell, spell->m_effectMiscValue[i], spell->m_effectMiscValueB[i]); + break; + + case 260: + CGWorldFrame::UpdateScreenEffect(); + break; + + case 262: + case 275: + CGSpellBook::UpdateUsable(); + break; + + case 273: + CGPlayer_C::UpdateXRayVision(spell); + break; + + default: + break; + } + } + } + + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effectAura[i] == 78) { + CGSpellBook::SendCompanionUpdate(1); + + if (visualIds[0]) { + SpellVisualRec* visual = g_spellVisualDB.GetRecord(visualIds[0]); + SpellVisualKitRec* kit = visual ? g_spellVisualKitDB.GetRecord(visual->m_stateKit) : nullptr; + + if (kit && kit->m_animID >= 0) { + this->m_mountAnimBehaviorId = kit->m_animID; + } + } + } else if (spell->m_effectAura[i] == 279) { + WOWGUID guid = this->m_obj->m_guid; + CGGameUI::UnitNameUpdate(guid); + } + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (this->GetControllingPlayer() == player || this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effectAura[i] == 48) { + int32_t period = spell->m_effectAuraPeriod[i]; + Spell_C_ModifySpellValue(spell, period, 19); + Spell_C_AddPeriodicClientTrigger(this->m_obj->m_guid, spell->m_id, spell->m_effectTriggerSpell[i], period); + } + } + } + + const SpellVisualRec* visual = GetSpellVisual(spell); + + if (!visual) { + return; + } + + if (visual->m_hasMissile) { + for (CMissile* missile = this->m_missiles; missile; missile = missile->m_next) { + if (missile->m_spellID == static_cast(spellId)) { + return; + } + } + } + + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + + if (!kit) { + return; + } + + for (uint32_t i = 0; i < 4; i++) { + if (kit->m_charProc[i] == 11 && !this->m_worldModel->IsLoaded(0, 0)) { + this->unk_0A8C = spell->m_id; + goto handItems; + } + } + + { + PlaySpellVisuaKitData data(spell, kit, 2); + data.m_someGUID = this->m_auras[index].m_creator; + this->PlaySpellVisualKit(data); + } + +handItems: + if (visual->m_flags & 0x8) { + this->ShowHandItemSpellEffects(1, 1); + } +} + +// VERIFY: e85d416f manual +// OFFSET: 0x0071E930 +void CGUnit_C::RemoveAuraEffect(uint32_t index, const SpellRec* spell) { + uint32_t count = this->unk_0EDC.m_count == 0xFFFFFFFF ? this->unk_0EDC.m_dynamic.m_count : this->unk_0EDC.m_count; + + if (index >= count) { + return; + } + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + for (uint32_t i = 0; i < 3; i++) { + switch (spell->m_effectAura[i]) { + case 76: + CGWorldFrame::GetActiveCamera()->SetTelescope(0); + break; + + case 78: { + CGSpellBook::SendCompanionUpdate(1); + + if (spell->m_spellVisualID[0]) { + SpellVisualRec* visual = g_spellVisualDB.GetRecord(spell->m_spellVisualID[0]); + + if (visual) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_stateKit); + + if (kit && kit->m_animID >= 0 && this->m_mountAnimBehaviorId == kit->m_animID) { + this->m_mountAnimBehaviorId = 91; + } + } + } + + break; + } + + case 233: + EnumVisibleForAuraEffect(spell, 0, 0); + break; + + case 260: + CGWorldFrame::UpdateScreenEffect(); + break; + + case 262: + case 275: + CGSpellBook::UpdateUsable(); + break; + + case 273: + CGPlayer_C::UpdateXRayVision(spell); + break; + + case 292: + CGStableInfo::CloseStables(true); + break; + + default: + break; + } + } + } + + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effectAura[i] == 279) { + WOWGUID guid = this->m_obj->m_guid; + CGGameUI::UnitNameUpdate(guid); + } + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (this->GetControllingPlayer() == player || this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + for (uint32_t i = 0; i < 3; i++) { + if (spell->m_effectAura[i] == 48) { + Spell_C_RemovePeriodicClientTrigger(this->m_obj->m_guid, spell->m_id); + } + } + } + + if (!this->unk_0EDC[index]) { + return; + } + + this->ReleaseAurasBySpell(this->unk_0EDC[index]); + + float alpha = this->GetBaseAlpha(); + uint32_t time = 1000; + + if (this->m_auraEffects) { + alpha *= this->m_auraEffects->unk_00E8; + + if (this->m_auraEffects->unk_00A0) { + time = this->m_auraEffects->unk_00A0; + } + } + + this->DoFade(alpha, time); + + uint32_t auraSpellId = this->unk_0EDC[index]; + + for (CEffect* effect = this->m_procEffects; effect; ) { + CEffect* next = effect->m_next; + + if (effect->m_spellId == auraSpellId) { + effect->Release(); + } + + effect = next; + } + + this->ClearSpellEffect(this->unk_0EDC[index], 1); + + const SpellVisualRec* visual = GetSpellVisual(spell); + + if (visual) { + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_stateDoneKit); + + if (kit) { + PlaySpellVisuaKitData data(nullptr, kit, 8); + this->PlaySpellVisualKit(data); + } + } + + this->unk_0EDC[index] = 0; +} + +// VERIFY: 5fb49f97 auto +// OFFSET: 0x0072AB60 +void CGUnit_C::SetUICastingSpell(int32_t spellId, const WOWGUID& target, int32_t castTime) { + this->m_castingSpellId = spellId; + this->m_castingObject = target; + this->m_castStartTime = FrameTime::s_curTimeMs; + this->m_castEndTime = castTime + FrameTime::s_curTimeMs; + + int32_t arenaIndex; + + if (this->m_obj->m_guid == CGGameUI::m_lockedTarget || this->m_obj->m_guid == CGGameUI::unk_BD07D0 || CGBattlefieldInfo::GetArenaOpponentIndex(this->m_obj->m_guid, &arenaIndex)) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + this->ProcessCastNotInterruptible(&spell); + } + } + + this->m_channelSpellId = 0; + this->m_channelStartTime = 0; + this->m_channelEndTime = 0; + this->UpdateSpellCastBars(FrameTime::s_curTimeMs); +} + +// VERIFY: 6f62e5de auto +// OFFSET: 0x0072AD20 +void CGUnit_C::SetUIChannelSpell(int32_t spellId, int32_t duration) { + this->m_channelSpellId = spellId; + this->m_channelStartTime = FrameTime::s_curTimeMs; + this->m_channelEndTime = duration + FrameTime::s_curTimeMs; + + int32_t arenaIndex; + + if (this->m_obj->m_guid == CGGameUI::m_lockedTarget || this->m_obj->m_guid == CGGameUI::unk_BD07D0 || CGBattlefieldInfo::GetArenaOpponentIndex(this->m_obj->m_guid, &arenaIndex)) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell)) { + this->ProcessCastNotInterruptible(&spell); + } + } + + this->m_castingSpellId = 0; + this->m_castStartTime = 0; + this->m_castEndTime = 0; + this->UpdateSpellCastBars(FrameTime::s_curTimeMs); +} + +// VERIFY: 117c6766 manual +// OFFSET: 0x0073EB50 +void CGUnit_C::OnChannelSpellChanged(int32_t oldSpell) { + if (oldSpell) { + this->ReleaseAurasBySpell(oldSpell); + + float alpha = this->GetBaseAlpha(); + uint32_t time = 1000; + + if (this->m_auraEffects) { + alpha *= this->m_auraEffects->unk_00E8; + + if (this->m_auraEffects->unk_00A0) { + time = this->m_auraEffects->unk_00A0; + } + } + + this->DoFade(alpha, time); + this->ReleaseEffectsBySpell(oldSpell); + this->ClearSpellEffect(oldSpell, 1); + + if (this->m_fishingLineEffect) { + this->m_fishingLineEffect->Release(); + this->m_fishingLineEffect = nullptr; + } + + for (uint32_t i = 0; i < (this->unk_0EDC.m_count == 0xFFFFFFFF ? this->unk_0EDC.m_dynamic.m_count : this->unk_0EDC.m_count); i++) { + if (this->unk_0EDC[i] && this->unk_0EDC[i] == static_cast(oldSpell)) { + this->unk_0EDC[i] = 0; + } + } + } + + if (this->m_unit->m_unitChannelSpell) { + this->UpdateChannelEffects(); + return; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(oldSpell, &spell) && (spell.m_attributesEx & 0x4000) && this->IsActiveMoverTracking(2)) { + this->ClearTrackingTarget(false, true); + } + + this->ClearSpellEffect(oldSpell, 1); + + if (this->m_fishingLineEffect) { + this->m_fishingLineEffect->Release(); + this->m_fishingLineEffect = nullptr; + } +} + +// VERIFY: 49638f19 manual +// OFFSET: 0x00755850 +void CGUnit_C::PlayCombatSpellMissEffects(uint32_t reason, const WOWGUID& source) { + if ((this->m_unit->m_unitFieldFlags2 & 0x1) || this->GetClientStandState() == 7) { + return; + } + + CGUnit_C* attacker = static_cast(ClntObjMgrObjectPtr(source, TYPEMASK_UNIT, __FILE__, __LINE__)); + const CGUnitVirtualItem* weapon = nullptr; + + if (attacker && attacker->m_sheatheState) { + const CGUnitVirtualItem* item = attacker->GetVirtualItem(0, false); + weapon = item && item->m_classID == 2 ? item : nullptr; + } + + WOWGUID mover = CGUnit_C::s_activeMover; + + switch (reason) { + case 3: + this->PlayBaseAnimation(ANIM_DODGE, 0); + break; + + case 4: { + this->PlayParryAnimation(); + C3Vector position = this->GetPosition(); + SI2::PlayParrySound(weapon, this->GetParryingItem(false), 0, &position, mover == source); + break; + } + + case 5: { + this->PlayBaseAnimation(ANIM_SHIELD_BLOCK, 0); + this->GetVirtualItem(0, false); + const CGUnitVirtualItem* shield = this->GetVirtualItem(1, false); + + if (shield && shield->m_classID != 2 && shield->m_classID != 4) { + shield = nullptr; + } + + C3Vector position = this->GetPosition(); + SI2::PlayParrySound(nullptr, shield, 0, &position, mover == source); + break; + } + + default: + break; + } +} + +// VERIFY: 47ba34f4 auto +// OFFSET: 0x00763570 +void CGUnit_C::HandleSpellEventSound() { + if (!this->m_castSpellId) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_castSpellId, &spell)) { + SysMsgPrintf(STATUS_ERROR, 2, "NOSPELLIDFOUND|%d", this->m_castSpellId); + return; + } + + SpellVisualRec visualRec; + const SpellVisualRec* visual = this->GetAppropriateSpellVisual(&spell, visualRec, 0, 0); + + if (!visual) { + SysMsgPrintf(STATUS_ERROR, 2, "SPELLVISUALIDNOTFOUND|%d", spell.m_spellVisualID[0]); + return; + } + + if (visual->m_animEventSoundID) { + C3Vector position = this->GetPosition(); + position.z += 1.0f; + SI2::PlaySoundKit(visual->m_animEventSoundID, &position, nullptr, nullptr, 0, nullptr, 1, 0); + } +} + +// VERIFY: 28e7526d auto +// OFFSET: 0x0072AF60 +int32_t CGUnit_C::PlaySpellVisualKit_DelayLightningEffects(const SpellRec* spell, const SpellVisualKitRec* kit, SPELL_VISUAL_KIT_TYPE type, const C3Vector* position, WOWGUID guid, int32_t a6, int32_t a7, int32_t a8, int32_t a9, uint32_t a10, const SpellVisualRec* visual) { + if (!spell || !visual || !Spell_C_SpellVisualHasChainEffect(visual) || a8 || !(kit->m_flags & 0x1)) { + return 0; + } + + this->DelaySpellVisualKit(spell->m_id, kit->m_id, type, position, guid, a6, a7, a9, 0, FrameTime::s_curTimeMs + 10000); + return 1; +} + +// VERIFY: 6c474fbc auto +// OFFSET: 0x0073A6C0 +void CGUnit_C::PlaySpellVisualKit_HandleWeapons(const SpellRec* spell, const SpellVisualKitRec* kit, const C3Vector* position, WOWGUID guid, uint32_t a5, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), int32_t* hasEffect) { + int32_t spellId = 0; + + if (spell) { + spellId = spell->m_id; + } + + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(kit->m_leftWeaponEffect); + + if (effectName && !(this->GetModelData()->m_flags & 0x10)) { + if (!spell || !(spell->m_attributes & 0x40000)) { + this->SetSheatheState(0, 1, 0); + } + + this->PlayEffectName(2, 0, spellId, kit, effectName, &flags, callback, position, guid, a5, nullptr); + *hasEffect = 1; + } + + effectName = g_spellVisualEffectNameDB.GetRecord(kit->m_rightWeaponEffect); + + if (effectName && !(this->GetModelData()->m_flags & 0x10)) { + if (!spell || !(spell->m_attributes & 0x40000)) { + this->SetSheatheState(0, 1, 0); + } + + this->PlayEffectName(1, 0, spellId, kit, effectName, &flags, callback, position, guid, a5, nullptr); + *hasEffect = 1; + } +} + +// VERIFY: b9a18a7a manual +// OFFSET: 0x0071D510 +static int32_t IsWoundAnim(int32_t animId) { + AnimationDataRec* anim = g_animationDataDB.GetRecord(animId); + return anim && anim->m_behaviorID >= 8 && anim->m_behaviorID <= 10; +} + +// VERIFY: 90fbcaf2 manual +// OFFSET: 0x0073B140 +void CGUnit_C::PlaySpellVisualKit_PlayAnims(const SpellRec* spell, const SpellVisualKitRec* kit, SPELL_VISUAL_KIT_TYPE type, const C3Vector* position, int32_t a5, int32_t a6, WOWGUID guid, uint32_t a8, const SpellVisualRec* visual, uint32_t a10, int32_t a11) { + int32_t spellId = 0; + + if (spell) { + spellId = spell->m_id; + } + + this->m_animationState &= ~0x4000; + + if (spell && (spell->m_attributes & 0x2) && (type == 4 || type == 0)) { + this->SetSheatheState(2, 1, 0); + } + + if (a5) { + uint8_t animFlags = 0; + + if (kit->m_flags & 0x4) { + animFlags = 2; + } + + if (kit->m_flags & 0x8) { + animFlags |= 0x4; + } + + if (kit->m_flags & 0x10) { + animFlags |= 0x8; + } + + if (kit->m_flags & 0x100) { + animFlags |= 0x20; + } + + if (spell && (spell->m_attributes & 0x40000)) { + animFlags |= 0x20; + } + + if (visual && static_cast(visual->m_missileModel) >= 0xFFFFFFFE) { + animFlags |= 0x20; + } + + if ((a10 & 0x40) && kit->m_startAnimID >= 0) { + this->PlayBaseAnimation(kit->m_startAnimID, animFlags); + this->m_animationState |= 0x10000; + } else if (kit->m_animID >= 0) { + SpellVisualKitRec* castKit = visual ? g_spellVisualKitDB.GetRecord(visual->m_castKit) : nullptr; + bool sameAnim = castKit && castKit->m_animID > 0 && castKit->m_animID == this->GetCurrentTorsoAnimId(); + bool noCastTime = this->GetSpellCastingTime(spell) <= 0; + int32_t holdCast = (a10 & 0x40) && !noCastTime && sameAnim; + int32_t holdChannel = (a10 & 0x1000) && sameAnim; + + if (type == 2) { + if (!holdChannel && !a11) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + WOWGUID owner = this->m_obj->m_guid; + effect->AddAnimKitEffect(spellId, kit, &owner, a10, a8); + effect->Release(); + } + + int32_t animId = kit->m_animID; + + if (this->GetCurrentTorsoAnimId() != animId) { + if (IsDeadOrDyingAnim(animId)) { + this->PlayBaseAnimation(animId, animFlags); + } + + this->UpdateBaseAnimation(animFlags, -1); + } + } else if (!(a10 & 0x40) || (!noCastTime && !holdCast)) { + if (IsWoundAnim(kit->m_animID)) { + this->PlayWoundAnimKit(kit->m_animID == ANIM_COMBAT_CRITICAL); + } else { + this->PlayBaseAnimation(kit->m_animID, animFlags); + } + + if (a10 & 0x80) { + this->unk_0FA4 = kit->m_animID; + } + } + + if (!a11 && (holdCast || holdChannel)) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + WOWGUID owner = this->m_obj->m_guid; + effect->AddAnimKitEffect(spellId, kit, &owner, a10, a8); + effect->Release(); + } + + this->m_animationState &= ~0x10000; + } + + if (a6) { + this->PlayWoundAnimKit(0); + } + } + + this->CreateProceduralEffect(spell, visual, kit, 0, a10, guid); + + if (this->unk_0B34[1]) { + this->UpdateWeaponTrails(&this->unk_0B34[0], this->unk_0B34[1]); + this->unk_0B34[1] = 0; + } + + if (!(a10 & 0x400) && kit->m_soundID) { + CEffect* effect = new (SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0)) CEffect(); + effect->m_flags = a10; + effect->m_kitRec = kit; + effect->AddSoundEffect(kit->m_soundID, 0, spellId, position, this, a8); + effect->Release(); + } + + if (!a11 && kit->m_shakeID > 0) { + C3Vector objectPosition; + const C3Vector* shakePosition = position; + + if (!shakePosition) { + objectPosition = this->GetPosition(); + shakePosition = &objectPosition; + } + + SpellVisualsPlayCameraShakeID(kit->m_shakeID, shakePosition); + } +} + +// VERIFY: c1ea52b3 manual +// OFFSET: 0x00736640 +void CGUnit_C::PlayWoundAnimKit(int32_t crit) { + if (this->IsDeadOrAttachmentDying() || !this->m_worldModel || !this->m_worldModel->IsLoaded(0, 0) || this->DoNotPlayWoundAnim()) { + return; + } + + for (CEffect* effect = this->m_effectList; effect; effect = effect->m_next) { + if (effect->m_flags & 0x4) { + return; + } + } + + uint32_t animId; + uint32_t keyBone = this->m_torsoKeyBone; + + if (crit) { + animId = 10; + } else if (this->m_combat.m_attacking.m_guid) { + animId = 9; + } else { + animId = 8; + + if (!this->m_mountModel && !(this->m_movement->m_flags & 0x2E0100F) && !this->m_movementData.IsSplineFlyerOrHovering() && !this->IsSitting() && GetAnimBehaviorId(this->GetCurrentTorsoAnimId()) != 98) { + keyBone = 0xFFFFFFFF; + } + } + + if (keyBone == static_cast(this->m_torsoKeyBone)) { + uint32_t sequenceId = this->m_worldModel->GetBoneSequenceId(0xFFFFFFFF); + + if (IsWeaponReadyAnim(sequenceId) || !sequenceId) { + keyBone = 0xFFFFFFFF; + } + } + + uint32_t resolved = this->ResolveAnimForModel(animId, nullptr); + + if (this->m_worldModel->HasSequence(resolved)) { + this->SetKeyBoneSequence(this->m_worldModel, keyBone, resolved, 0xFFFFFFFF, 0, 1.0f, 0, 0, 0); + } + + this->UpdateObjectEffectAnimationStates(); +} + +// VERIFY: fa22acc6 manual +// OFFSET: 0x00715D60 +void CGUnit_C::TriggerDamageFeedback() { + if (this->m_namePlateFrame) { + this->m_namePlateFrame->TriggerDamageFeedback(); + } +} + +// VERIFY: b7d9f2a8 manual +// OFFSET: 0x0072BDB0 +int32_t CGUnit_C::VerifyAttackIconPressed(WOWGUID* target, int32_t useGiven, int32_t checkRange, bool autoTarget, bool showErrors) { + if (this->IsDeadOrGhost()) { + CGPlayer_C* player; + + if (this->m_obj->m_guid != ClntObjMgrGetActivePlayer() || !(player = ClntObjMgrGetActivePlayerObj()) || !player->GetPossessedUnit()) { + if (showErrors) { + CGGameUI::DisplayError(ERR_ATTACK_DEAD); + } + + return 0; + } + } else { + if ((this->m_obj->m_type & TYPEMASK_PLAYER) && (static_cast(this)->m_player->m_playerFlags & 0x1000000)) { + if (showErrors) { + CGGameUI::DisplayError(ERR_CLIENT_LOCKED_OUT); + } + + return 0; + } + + int32_t mechanic; + + if (this->m_unit->m_unitFieldCharmedby && this->m_unit->m_unitFieldCharmedby != ClntObjMgrGetActivePlayer()) { + Spell_C_CancelsCharm(this, nullptr, &mechanic); + + if (!showErrors) { + return 0; + } + + if (!mechanic) { + CGGameUI::DisplayError(ERR_ATTACK_CHARMED); + return 0; + } + } else { + uint32_t flags = this->m_unit->m_unitFieldFlags; + + if (flags & 0x40000) { + Spell_C_CancelsStun(this, nullptr, &mechanic); + + if (!showErrors) { + return 0; + } + + if (!mechanic) { + CGGameUI::DisplayError(ERR_ATTACK_STUNNED); + return 0; + } + } else if (flags & 0x20000) { + Spell_C_CancelsPacify(this, nullptr, &mechanic); + + if (!showErrors) { + return 0; + } + + if (!mechanic) { + CGGameUI::DisplayError(ERR_ATTACK_PACIFIED); + return 0; + } + } else if (flags & 0x800000) { + Spell_C_CancelsFear(this, nullptr, &mechanic); + + if (!showErrors) { + return 0; + } + + if (!mechanic) { + CGGameUI::DisplayError(ERR_ATTACK_FLEEING); + return 0; + } + } else if (flags & 0x400000) { + Spell_C_CancelsConfuse(this, nullptr, &mechanic); + + if (!showErrors) { + return 0; + } + + if (!mechanic) { + CGGameUI::DisplayError(ERR_ATTACK_CONFUSED); + return 0; + } + } else { + mechanic = -1; + } + } + + if (mechanic != -1) { + SpellMechanicRec* mechanicRec = g_spellMechanicDB.GetRecord(mechanic); + CGGameUI::DisplayError(ERR_ATTACK_PREVENTED_BY_MECHANIC_S, mechanicRec ? mechanicRec->m_stateName : "UNKNOWN"); + return 0; + } + + if (this->m_unit->m_unitChannelSpell) { + SpellRec spell; + + if (g_spellDB.GetRecord(this->m_unit->m_unitChannelSpell, &spell)) { + if ((spell.m_attributesEx & 0x1000) && showErrors) { + CGGameUI::DisplayError(ERR_ATTACK_CHANNEL); + } + + return 0; + } + } + + if (this->IsMounted() && !this->MountedCombatAllowed() && !this->CanAutoDismount()) { + if (showErrors) { + CGGameUI::DisplayError(ERR_ATTACK_MOUNTED); + } + + return 0; + } + } + + if (!useGiven) { + bool haveTarget = true; + + if (!*target) { + *target = CGGameUI::m_lockedTarget; + haveTarget = static_cast(*target); + } + + if (haveTarget) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && this->IsFriendly(unit)) { + *target = WOWGUID(); + } else if (*target) { + CGGameUI::Target(*target); + *target = CGGameUI::m_lockedTarget; + goto checkTarget; + } + } + + if (autoTarget) { + TargetNearestEnemy(0, 1); + } + + *target = CGGameUI::m_lockedTarget; + } + +checkTarget: + if (!*target) { + if (showErrors) { + CGGameUI::DisplayError(ERR_NO_ATTACK_TARGET); + } + + return 0; + } + + if (this->IsActivePlayer()) { + CGGameUI::Target(*target); + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return 0; + } + + if (this->IsMounted() && !this->MountedCombatAllowed() && checkRange) { + float minRange; + float maxRange; + int32_t spellId; + + if (this->IsActivePlayer() && (spellId = GetModalNextSpell())) { + Spell_C::GetSpellRange(this, spellId, &minRange, &maxRange, unit); + } else { + maxRange = this->GetMeleeRange(unit); + } + + if (maxRange * maxRange < this->GetDistanceToPos(unit->GetPosition())) { + if (showErrors) { + CGGameUI::DisplayError(ERR_OUT_OF_RANGE); + } + + return 0; + } + } + + if (this->CanAttackNow(unit)) { + return 1; + } + + if (showErrors) { + CGGameUI::DisplayError(ERR_INVALID_ATTACK_TARGET); + } + + return 0; +} + +// VERIFY: 34778608 manual +// OFFSET: 0x0072C2B0 +int32_t CGUnit_C::OnAttackIconPressed(WOWGUID target, int32_t a3) { + WOWGUID previousTarget = CGGameUI::m_lockedTarget; + int32_t targetChanged = 0; + + if (!this->VerifyAttackIconPressed(&target, a3, 1, 1, 1)) { + return 0; + } + + if (previousTarget != target) { + targetChanged = 1; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + int32_t controlsPet = 0; + + if (player && player->GetTransportGUID() == CGPetInfo::GetPet(0).m_guid) { + const WOWGUID& charm = player->m_unit->m_unitFieldCharm ? player->m_unit->m_unitFieldCharm : player->m_unit->m_unitFieldSummon; + + if (charm == CGPetInfo::GetPet(0)) { + controlsPet = 1; + } + } + + int32_t isPlayer = (ClntObjMgrGetActivePlayer() == this->m_obj->m_guid) || controlsPet; + int32_t petAttack = (CGPetInfo::GetPet(0) == this->m_obj->m_guid) || controlsPet; + + if (isPlayer) { + if (((player->m_combatModeFlags & 2) || player->m_combat.m_attacking) && CGGameUI::m_hasControl) { + player->SetCombatMode(); + } else { + player->CombatModeEnter(target, targetChanged, 0); + } + + if (petAttack) { + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)); + CGUnit_C* victim = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!pet || !victim || !pet->CanAttackNow(victim)) { + petAttack = 0; + } + } + + if (player->m_obj->m_guid == CGUnit_C::s_activeMover && player->HasVehicleTransport()) { + player->CheckVehicleExitOnCast(); + } + } + + if (petAttack) { + CGPetInfo::PetAttackTarget(target, a3); + + if (CGPetInfo::GetPet(0) == CGUnit_C::s_activeMover) { + CGUnit_C* mover = static_cast(ClntObjMgrObjectPtr(CGUnit_C::s_activeMover, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (mover && mover->HasVehicleTransport()) { + mover->CheckVehicleExitOnCast(); + } + } + } + + return 1; +} + +// VERIFY: 96b12266 auto +// OFFSET: 0x0072BAC0 +bool CGUnit_C::CheckShapeshiftRules(const SpellRec* spell, int32_t* reason) { + int32_t form = this->m_shapeshiftSuppressed ? 0 : this->m_unit->m_unitFieldBytes2[3]; + + if (SpellRec::NotUsableInShapeshiftForm(spell, form - 1)) { + if (!this->AffectedByAura(275, spell)) { + *reason = 68; + return false; + } + + return true; + } + + form = this->m_shapeshiftSuppressed ? 0 : this->m_unit->m_unitFieldBytes2[3]; + + if (SpellRec::UsableInShapeshift(spell, form - 1)) { + return true; + } + + if (this->IsShapeShifted()) { + if (spell->m_attributes & 0x10000) { + if (!this->AffectedByAura(275, spell)) { + *reason = 68; + return false; + } + + return true; + } + + form = this->m_shapeshiftSuppressed ? 0 : this->m_unit->m_unitFieldBytes2[3]; + SpellShapeshiftFormRec* shapeshift = g_spellShapeshiftFormDB.GetRecord(form); + + if (shapeshift && (shapeshift->m_flags & 0x400)) { + if (!this->AffectedByAura(275, spell)) { + *reason = 68; + return false; + } + + return true; + } + } else if (spell->m_attributesExB & 0x80000) { + return true; + } + + if ((spell->m_shapeshiftMask[0] || spell->m_shapeshiftMask[1]) && !this->AffectedByAura(275, spell)) { + *reason = 94; + return false; + } + + return true; +} + +// VERIFY: b86e26b0 manual +// OFFSET: 0x007191A0 +void CGUnit_C::AddWorldXPGainText(int32_t amount) { + char text[64] = {}; + char label[64]; + SStrCopy(label, FrameScript_GetText("XP", -1, GENDER_NOT_APPLICABLE), sizeof(label)); + SStrPrintf(text, sizeof(text), "%s: %d", label, amount); + PlayerNameCreateText(this->m_nameDesc, 4, text, nullptr, nullptr); +} + +// VERIFY: b3ec4bfc manual +// OFFSET: 0x0072CD90 +UnitThreat* UnitThreatHeap::New() { + uint32_t memHandle; + void* memory = nullptr; + + if (!ObjectAlloc(this->m_heapId, &memHandle, &memory, false)) { + return nullptr; + } + + UnitThreat* threat = memory ? new (memory) UnitThreat : nullptr; + threat->m_memHandle = memHandle; + + return threat; +} + +// VERIFY: 9e64e02c manual +// OFFSET: 0x007374C0 +bool CGUnit_C::CalculateThreat(const WOWGUID& guid, uint8_t* status, uint8_t* rawPercent, float* percent, int32_t* threat) { + UnitThreat* entry = this->m_threats.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (!this->m_highestThreatGuid || !entry) { + if (status) { + *status = entry != nullptr; + } + + if (rawPercent) { + *rawPercent = 0; + } + + if (percent) { + *percent = 0.0f; + } + + if (threat) { + *threat = 0; + } + + return false; + } + + if (status) { + *status = entry->m_status; + } + + if (rawPercent) { + *rawPercent = entry->m_percent; + } + + if (percent) { + if (guid == this->m_highestThreatGuid) { + *percent = 100.0f; + } else { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + float range; + + if (unit && (range = this->GetMeleeRange(unit), range * range >= this->GetDistanceToPos(unit->GetPosition()))) { + *percent = entry->m_percent * 0.90909088f; + } else { + *percent = entry->m_percent * 0.76923078f; + } + } + } + + if (threat) { + *threat = entry->m_threat; + } + + return true; +} + +// VERIFY: ebb6b704 manual +// OFFSET: 0x007345C0 +void CGUnit_C::ClearThreatList() { + if (!this->m_threats.m_fulllist.Head()) { + return; + } + + UnitThreat* entry; + + while ((entry = this->m_threats.m_fulllist.Head())) { + WOWGUID target = entry->m_key.m_guid; + Script_SendUniqueSignal(target, SCRIPT_EVENT_UNIT_THREAT_SITUATION_UPDATE); + CGGameUI::ThreatMapRemove(this->m_obj->m_guid, target); + this->m_threats.Unlink(entry); + UnitThreatHeap* heap = s_unitThreatPool; + entry->~UnitThreat(); + ObjectFree(heap->m_heapId, entry->m_memHandle); + } + + this->m_highestThreatGuid = WOWGUID(); + Script_SendUniqueSignal(this->m_obj->m_guid, SCRIPT_EVENT_UNIT_THREAT_LIST_UPDATE); + CGGameUI::UnitTooltipUpdate(this->m_obj->m_guid); +} + +// VERIFY: 09b44ad3 auto +// OFFSET: 0x00719220 +void CGUnit_C::AddWorldThreatUpdateText(int32_t oldStatus, int32_t newStatus) { + if (!CGGameUI::m_threatWarningEnabled || !g_threatWorldTextCVar->m_intValue) { + return; + } + + if ((oldStatus == 2 && newStatus == 1) || (oldStatus == 3 && newStatus == 4)) { + return; + } + + char token[32]; + SStrPrintf(token, sizeof(token), "COMBAT_THREAT_%s_%d", newStatus > oldStatus ? "INCREASE" : "DECREASE", newStatus); + const char* text = FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE); + + if (*text) { + PlayerNameDeleteText(this->m_nameDesc, 10); + PlayerNameCreateText(this->m_nameDesc, 10, text, nullptr, nullptr); + } +} + +// VERIFY: a407c868 manual +// OFFSET: 0x007416F0 +UnitThreat* CGUnit_C::CreateThreatEntry(const WOWGUID& guid) { + UnitThreat* entry = this->m_threats.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (entry) { + return entry; + } + + entry = s_unitThreatPool->New(); + entry->m_status = 1; + entry->m_percent = 0xFF; + entry->m_threat = 0; + this->m_threats.Insert(entry, static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (guid == ClntObjMgrGetActivePlayer()) { + this->m_clientFlags |= 0x8; + } + + CGGameUI::ThreatMapAdd(this->m_obj->m_guid, guid); + return entry; +} + +// VERIFY: 4feabe73 manual +// OFFSET: 0x0071C3B0 +bool CGUnit_C::UpdateThreatEntry(UnitThreat* entry, int32_t highestThreat, bool activePlayer) { + bool changed = false; + uint8_t percent; + + if (!highestThreat) { + percent = 100; + } else if (entry->m_threat <= 0) { + percent = 0; + } else { + int64_t scaled = 100ll * entry->m_threat / highestThreat; + percent = scaled >= 250 ? 250 : static_cast(scaled); + } + + if (percent == entry->m_percent) { + return changed; + } + + entry->m_percent = percent; + uint8_t status = percent < 100 ? 1 : 2; + + if (status != entry->m_status) { + if (activePlayer) { + if (s_cvThreatPlaySounds->m_intValue && status == 2 && entry->m_status == 1) { + SI2::PlayUISound(15262); + } + + if (!(this->m_clientFlags & 0x8)) { + this->AddWorldThreatUpdateText(entry->m_status, status); + } + } + + entry->m_status = status; + Script_SendUniqueSignal(entry->m_key.m_guid, SCRIPT_EVENT_UNIT_THREAT_SITUATION_UPDATE); + changed = true; + } + + if (activePlayer) { + this->m_clientFlags &= ~0x8u; + CGGameUI::UnitTooltipUpdate(this->m_obj->m_guid); + } + + return changed; +} + +// VERIFY: 1e748a95 manual +// OFFSET: 0x00737620 +void CGUnit_C::UpdateThreatStatus() { + UnitThreat* highest = this->m_threats.Ptr(static_cast(this->m_highestThreatGuid.m_guid), CHashKeyGUID(this->m_highestThreatGuid.m_guid)); + + if (!highest) { + return; + } + + uint8_t status = 4; + + for (UnitThreat* entry = this->m_threats.m_fulllist.Head(); entry; entry = this->m_threats.m_fulllist.Next(entry)) { + if (entry->m_key.m_guid != this->m_highestThreatGuid && entry->m_status == 2) { + status = 3; + } + } + + if (status != highest->m_status) { + if (this->m_highestThreatGuid == ClntObjMgrGetActivePlayer() && !(this->m_clientFlags & 0x8)) { + this->AddWorldThreatUpdateText(highest->m_status, status); + + if (s_cvThreatPlaySounds->m_intValue) { + SI2::PlayUISound(15263); + } + } + + highest->m_status = status; + Script_SendUniqueSignal(this->m_highestThreatGuid, SCRIPT_EVENT_UNIT_THREAT_SITUATION_UPDATE); + } + + if (this->m_highestThreatGuid == ClntObjMgrGetActivePlayer()) { + this->m_clientFlags &= ~0x8u; + CGGameUI::UnitTooltipUpdate(this->m_obj->m_guid); + } +} + +// VERIFY: 84ad87b6 auto +// OFFSET: 0x007417A0 +void CGUnit_C::UpdateThreat(CDataStore* msg, bool highest) { + WOWGUID activePlayer = ClntObjMgrGetActivePlayer(); + bool highestInList = highest; + + if (highest) { + SmartGUID highestGuid; + *msg >> highestGuid; + this->m_highestThreatGuid = highestGuid; + + if (highestGuid) { + this->CreateThreatEntry(this->m_highestThreatGuid); + } + } + + uint32_t count; + msg->Get(count); + UnitThreat** entries = static_cast(alloca(count * sizeof(UnitThreat*))); + + for (uint32_t i = 0; i < count; i++) { + SmartGUID guid; + *msg >> guid; + uint32_t threat; + msg->Get(threat); + WOWGUID target = guid; + UnitThreat* entry = this->CreateThreatEntry(target); + entry->m_threat = threat; + + if (guid == this->m_highestThreatGuid) { + highestInList = true; + } + + entries[i] = entry; + } + + bool changed = false; + UnitThreat* top = this->m_threats.Ptr(static_cast(this->m_highestThreatGuid.m_guid), CHashKeyGUID(this->m_highestThreatGuid.m_guid)); + + if (this->m_highestThreatGuid && top) { + int32_t highestThreat = top->m_threat; + + if (highestInList) { + for (UnitThreat* entry = this->m_threats.m_fulllist.Head(); entry; entry = this->m_threats.m_fulllist.Next(entry)) { + if (entry->m_key.m_guid != this->m_highestThreatGuid && this->UpdateThreatEntry(entry, highestThreat, entry->m_key.m_guid == activePlayer)) { + changed = true; + } + } + } else { + for (uint32_t i = 0; i < count; i++) { + UnitThreat* entry = entries[i]; + + if (entry->m_key.m_guid != this->m_highestThreatGuid && this->UpdateThreatEntry(entry, highestThreat, entry->m_key.m_guid == activePlayer)) { + changed = true; + } + } + } + } + + if (highest || changed) { + this->UpdateThreatStatus(); + } + + Script_SendUniqueSignal(this->m_obj->m_guid, SCRIPT_EVENT_UNIT_THREAT_LIST_UPDATE); +} + +// VERIFY: 2c8e0d1d manual +// OFFSET: 0x00737750 +void CGUnit_C::RemoveThreat(const WOWGUID& guid) { + UnitThreat* entry = this->m_threats.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (!entry) { + return; + } + + bool update = false; + + if (guid == this->m_highestThreatGuid) { + this->m_highestThreatGuid = WOWGUID(); + } else if (entry->m_status > 1) { + update = true; + } + + CGGameUI::ThreatMapRemove(this->m_obj->m_guid, guid); + this->m_threats.Unlink(entry); + UnitThreatHeap* heap = s_unitThreatPool; + entry->~UnitThreat(); + ObjectFree(heap->m_heapId, entry->m_memHandle); + Script_SendUniqueSignal(guid, SCRIPT_EVENT_UNIT_THREAT_SITUATION_UPDATE); + + if (update) { + this->UpdateThreatStatus(); + } + + Script_SendUniqueSignal(this->m_obj->m_guid, SCRIPT_EVENT_UNIT_THREAT_LIST_UPDATE); + + if (guid == ClntObjMgrGetActivePlayer()) { + CGGameUI::UnitTooltipUpdate(this->m_obj->m_guid); + } +} + +// VERIFY: 57fe3eca manual +// OFFSET: 0x00741C90 +int32_t Packet_ThreatUpdate(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->UpdateThreat(msg, msgId == SMSG_HIGHEST_THREAT_UPDATE); + } else { + msg->m_read = msg->m_size; + } + + return 1; +} + +// VERIFY: 4727a576 manual +// OFFSET: 0x00737B20 +int32_t Packet_SMSG_THREAT_REMOVE(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + *msg >> guid; + WOWGUID target = guid; + unit->RemoveThreat(target); + } else { + msg->m_read = msg->m_size; + } + + return 1; +} + +// VERIFY: cff5fd96 manual +// OFFSET: 0x00734B00 +int32_t Packet_SMSG_THREAT_CLEAR(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->ClearThreatList(); + } + + return 1; +} + +// VERIFY: 396f9c6a auto +// OFFSET: 0x007474B0 +void CGUnit_C::OnAiReaction(int32_t reaction) { + if (reaction == 4 && this->m_creatureCacheEntry && (this->m_creatureCacheEntry->m_typeFlags & 0x1000000)) { + return; + } + + if (!this->m_soundData || SI2::IsPlaying(&this->m_aiSound)) { + return; + } + + SE2SoundKitObject* object = &this->m_npcSound; + + if (SI2::IsPlaying(object) && reaction <= static_cast(this->unk_0930)) { + return; + } + + this->unk_0930 = reaction; + static CVar* s_enablePetSounds = CVar::Lookup("Sound_EnablePetSounds"); + int32_t soundKitId; + + switch (this->unk_0930) { + case 0: + if (s_enablePetSounds && !s_enablePetSounds->m_intValue && this->m_unit->m_unitFieldPetnumber) { + return; + } + + soundKitId = this->m_soundData->m_soundAggroID; + break; + + case 1: + if (s_enablePetSounds && !s_enablePetSounds->m_intValue && this->m_unit->m_unitFieldPetnumber) { + return; + } + + soundKitId = this->m_soundData->m_soundPetOrderID; + break; + + case 2: + if (s_enablePetSounds && !s_enablePetSounds->m_intValue && this->m_unit->m_unitFieldPetnumber) { + return; + } + + soundKitId = this->m_soundData->m_soundPetAttackID; + break; + + case 4: + soundKitId = this->m_soundData->m_soundDeathID; + break; + + default: + return; + } + + C3Vector position = this->GetAttachmentPosition(17, nullptr); + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + int32_t activeMover; + int32_t listenerAtCharacter; + + if (CGUnit_C::s_activeMover == this->m_obj->m_guid) { + activeMover = 1; + listenerAtCharacter = s_listenerAtCharacter->m_intValue ? 1 : 0; + } else { + activeMover = 0; + listenerAtCharacter = 0; + } + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (activeMover) { + properties.m_priority = 110; + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_unit->m_unitFieldBytes0[1] == 6) { + properties.m_useDspChain = 1; + SI2::DK_GetPlayerFilterName(player, properties.m_dspChainName, sizeof(properties.m_dspChainName)); + } + + if (listenerAtCharacter) { + properties.m_volumeScale = 0.64999998f; + } + } + + SI2::PlaySoundKit(soundKitId, listenerAtCharacter ? nullptr : &position, object, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: b7f4a97f manual +// OFFSET: 0x00716B10 +int32_t Packet_SMSG_AI_REACTION(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + uint32_t reaction; + msg->Get(reaction); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (!reaction) { + unit->PlayUnitSound(8, 0); + } else if (reaction == 2) { + unit->OnAiReaction(0); + } + } + + return 1; +} + +// VERIFY: f7c851d8 manual +// OFFSET: 0x00716B90 +int32_t Packet_SMSG_PET_ACTION_SOUND(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + uint32_t action; + msg->Get(action); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if (!action) { + unit->OnAiReaction(1); + } else if (action == 1) { + unit->OnAiReaction(2); + } + } + + return 1; +} + +// VERIFY: 4b8cff5c manual +// OFFSET: 0x00722D80 +void CGUnit_C::DoPowerRegen(int32_t powerType, uint32_t elapsed) { + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer() && (reinterpret_cast(&static_cast(this)->m_player->m_playerFieldBytes2)[2] & (1 << powerType))) { + return; + } + + bool interrupted = false; + + if (!powerType) { + if (this->m_manaRegenInterruptTime) { + if (static_cast(FrameTime::s_curTimeMs - this->m_manaRegenInterruptTime) < 0) { + interrupted = true; + } else { + this->m_manaRegenInterruptTime = 0; + } + } + + int32_t channelSpell = this->m_unit->m_unitChannelSpell; + + if (channelSpell) { + SpellRec spell; + + if (g_spellDB.GetRecord(channelSpell, &spell) && !(spell.m_attributesExB & 0x2000000) && !spell.m_powerType && Spell_C_GetPowerCost(&spell, this) > 0) { + interrupted = true; + } + } + } else { + interrupted = (this->m_unit->m_unitFieldFlags & 0x80000) || (this->m_auraEffectMask[11] & 0x40); + } + + float regen = this->GetPowerRegen(powerType, interrupted); + + if (fabs(regen) < 0.00000023841858f) { + return; + } + + float delta = regen * static_cast(elapsed) * 0.001f; + + if (delta >= 0.0f) { + int32_t maxPower = powerType == -2 ? this->m_unit->m_unitFieldMaxhealth : this->m_unit->m_unitFieldMaxpower[powerType]; + + if (this->GetPredictedPower(powerType) < maxPower) { + int32_t predicted = this->GetPredictedPower(powerType); + this->m_powerRegenRemainder += static_cast(delta * 1000.0f); + this->SetPredictedPower(powerType, predicted + this->m_powerRegenRemainder / 1000); + this->m_powerRegenRemainder %= 1000; + return; + } + } + + if (delta < 0.0f && this->GetPredictedPower(powerType) > 0 && !(this->m_unit->m_unitFieldFlags2 & 0x100)) { + int32_t predicted = this->GetPredictedPower(powerType); + float value = delta + (static_cast(this->m_powerRegenRemainder) * 0.001f + static_cast(predicted)); + + if (value < 0.0f) { + value = 0.0f; + } + + int32_t power = CMath::ftrunc(value); + this->SetPredictedPower(powerType, power); + float remainder = value * 1000.0f - static_cast(static_cast(power * 1000)); + this->m_powerRegenRemainder = CMath::fint_(remainder - 0.5f); + } +} + +// VERIFY: fb2878d0 manual +// OFFSET: 0x00728A20 +void CGUnit_C::DoPowerRegen(uint32_t elapsed) { + if (this->IsDeadOrGhost() || !(this->m_unit->m_unitFieldFlags2 & 0x800)) { + return; + } + + int32_t powerType = this->m_unit->m_unitFieldBytes0[3]; + this->DoPowerRegen(powerType, elapsed); + + if (this->m_unit->m_unitFieldBytes0[1] == 11) { + if (powerType) { + this->DoPowerRegen(0, elapsed); + } + + if (powerType != 3) { + this->DoPowerRegen(3, elapsed); + } + } + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer() && powerType == 6) { + uint32_t runes = CGRuneInfo::m_predictedRunes; + uint32_t previous = CGRuneInfo::m_predictedRunes; + uint32_t now = FrameTime::s_curTimeMs; + + for (int32_t i = 0; i < 8; i++) { + uint32_t bit = 1 << i; + + if (!(bit & CGRuneInfo::m_predictedRunes) && static_cast(now - CGRuneInfo::GetRuneRechargeTime(i)) >= 0) { + runes |= bit; + } + } + + if (runes != previous) { + CGRuneInfo::SetPredictedRunes(previous, runes, nullptr); + } + } +} + +// VERIFY: 08043232 manual +// OFFSET: 0x0072E3A0 +void CGUnit_C::OnLevelChange() { + void* memory = SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0); + CEffect* effect = memory ? new (memory) CEffect() : nullptr; + WOWGUID guid = this->m_obj->m_guid; + effect->AddSpecialEffect(5, guid, CGObject_C::EffectOnceHandler); + effect->m_flags |= 0x20; + effect->Release(); + + if (this->m_obj->m_type & TYPEMASK_PLAYER) { + static_cast(this)->OnLevelChange(); + } else { + this->UpdateModelScale(nullptr); + } + + if (this->m_namePlateFrame) { + this->m_namePlateFrame->UpdateLevelDisplay(this); + } +} + +// VERIFY: 0e2e20d4 manual +// OFFSET: 0x00720220 +void CGUnit_C::HandleBloodPool(uint32_t time) { + if (!this->m_bloodlevels) { + return; + } + + if (!g_unitBloodDB.GetRecord(this->m_bloodlevels->m_violencelevel[ViolenceGetLevel()])) { + return; + } + + if (static_cast(time - this->m_nextBloodPoolTime) < 0) { + return; + } + + this->m_nextBloodPoolTime = static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * 3000) >> 32) + time + 2000; + CRandom::sfloat_(g_rndSeed); + CRandom::sfloat_(g_rndSeed); +} + +// VERIFY: ee364054 manual +// OFFSET: 0x007561E0 +void CGUnit_C::OnDeathAnimate() { + if (!this->DoNotLogDeath()) { + UnitCombatLogUnitDead(this); + } + + this->PlayDeathAnimation(0); + + if (!(this->m_obj->m_type & TYPEMASK_PLAYER) || !(static_cast(this)->m_player->m_playerFlags & 0x4000)) { + this->OnAiReaction(4); + } + + this->KillCreatureLoopSound(); + + if (this->IsActivePlayer()) { + CGGameUI::UpdateActivePlayer(); + } +} + +// VERIFY: 92571cc6 auto +// OFFSET: 0x0071BC00 +void CGUnit_C::ReadLootList(CDataStore* msg) { + SmartGUID guid; + *msg >> guid; + this->m_masterLooter = guid; + *msg >> guid; + this->m_looter = guid; +} + +// VERIFY: dcd2c019 manual +// OFFSET: 0x0071CA50 +int32_t Packet_SMSG_LOOT_LIST(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid; + msg->Get(guid.m_guid); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->ReadLootList(msg); + } else { + msg->m_read = msg->m_size; + } + + return 1; +} + +// VERIFY: f3d87698 auto +// OFFSET: 0x00717C20 +void CGUnit_C::RemoveLootEffect() { + for (CEffect* effect = this->m_effectList; effect; effect = effect->m_next) { + if (effect->m_flags & 0x8) { + effect->MoveToDestroyList(); + return; + } + } +} + +// VERIFY: d074dfc8 auto +// OFFSET: 0x0073D530 +void CGUnit_C::OnLife(bool a1) { + this->m_clientFlags &= ~0x1u; + this->CheckLoopSound(); + this->m_lootableTime = 0; + this->SetKeyBoneSequenceSpeed(this->m_worldModel, 0xFFFFFFFF, 1.0f, 0); + this->UpdateBaseAnimation(0, -1); + PlayerNameTriggerColorUpdate(this->m_nameDesc); + + if (this->m_namePlateFrame) { + this->m_namePlateFrame->UpdateColorDisplay(this); + } + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer() && !a1) { + SendQuestGiverStatusMultipleQuery(); + CGGameUI::UnlockAllItems(); + FrameScript_SignalEvent(257, nullptr); + } +} + +// VERIFY: 8d2dd6f2 manual +// OFFSET: 0x00740570 +void CGUnit_C::OnDynamicFlagsChanged(uint32_t oldFlags) { + uint32_t flags = this->m_unit->m_unitDynamicFlags; + + if ((oldFlags & 1) && !(flags & 1)) { + this->RemoveLootEffect(); + } else if (!(oldFlags & 1) && (flags & 1)) { + CGTutorial::TriggerTutorial(6); + } + + if ((oldFlags ^ this->m_unit->m_unitDynamicFlags) & 0x20) { + Script_SendUnitSignal(this->m_obj->m_guid, 18); + Script_SendUnitSignal(this->m_obj->m_guid, this->m_unit->m_unitFieldBytes0[3] + 19); + + if (this->m_unit->m_unitDynamicFlags & 0x20) { + this->OnDeath(); + } else { + this->OnLife(true); + } + } + + if (static_cast(this->m_unit->m_unitFieldHealth) <= 0 && (this->m_unit->m_unitDynamicFlags & 1)) { + if (this->m_lootableTime) { + this->ClearEffectList(0); + } + + this->ShowLootEffect(); + } + + if ((oldFlags ^ this->m_unit->m_unitDynamicFlags) & 4) { + Script_SendUnitSignal(this->m_obj->m_guid, 49); + } +} + +// VERIFY: 7f96f710 manual +// OFFSET: 0x00718F00 +static int32_t PetColorUpdateProc(WOWGUID guid, void* param) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return 1; + } + + const WOWGUID& owner = unit->m_unit->m_unitFieldCharmedby ? unit->m_unit->m_unitFieldCharmedby : unit->m_unit->m_unitFieldCreatedby; + + if (owner == static_cast(param)->m_obj->m_guid && !(unit->m_unit->m_unitFieldFlags & 0x100)) { + PlayerNameTriggerColorUpdate(unit->m_nameDesc); + + if (unit->m_namePlateFrame) { + unit->m_namePlateFrame->UpdateColorDisplay(unit); + } + + Script_SendUnitSignal(unit->m_obj->m_guid, 49); + } + + return 1; +} + +// VERIFY: 56f522e1 auto +// OFFSET: 0x00718FB0 +void CGUnit_C::UpdatePetReaction() { + ClntObjMgrEnumVisibleObjects(PetColorUpdateProc, this); +} + +// VERIFY: 632e6ebd manual +// OFFSET: 0x00717BA0 +void CGUnit_C::ShowLootEffect() { + if (!(this->m_unit->m_unitDynamicFlags & 1)) { + return; + } + + for (CEffect* effect = this->m_effectList; effect; effect = effect->m_next) { + if (effect->m_flags & 0x8) { + return; + } + } + + void* memory = SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0); + CEffect* effect = memory ? new (memory) CEffect() : nullptr; + effect->AddLootEffect(this, nullptr); + effect->Release(); +} + +// VERIFY: 6fa47b02 auto +// OFFSET: 0x007412B0 +void CGUnit_C::CompleteMountTransition() { + if (this->m_mountTransitionEffect) { + this->OnMountDisplayChanged(this->m_mountTransitionEffect->m_displayId); + } + + this->m_mountTransitionEffect = nullptr; + this->m_mountTransition = nullptr; +} + +// VERIFY: 845aa7ca manual +// OFFSET: 0x00723730 +void CGUnit_C::RefreshComponentItem(int32_t itemSlot) { + if (this->CanEquipItemsInThisForm() && (this->m_obj->m_type & TYPEMASK_PLAYER)) { + if (!this->GetBag()) { + return; + } + + INVENTORY_SLOTS invSlot = CCharacterComponent::GetInvSlotForItemSlot(static_cast(itemSlot)); + + if (invSlot == -1) { + return; + } + + this->m_characterComponent->RemoveItem(static_cast(itemSlot)); + const VisibleItem_C* item = static_cast(this)->GetVisibleItem(invSlot); + + if (item && abs(item->m_itemId)) { + static_cast(this)->EquipVisibleItem(item, invSlot); + } + } else if (this->m_characterComponent && this->m_displayInfoExtra) { + this->m_characterComponent->RemoveItem(static_cast(itemSlot)); + int32_t displayId = this->m_displayInfoExtra->m_npcitemDisplay[itemSlot]; + + if (displayId) { + this->m_characterComponent->AddItem(static_cast(itemSlot), displayId, 0); + } + } +} + +// VERIFY: 0f53e72a manual +// OFFSET: 0x0072E430 +void CGUnit_C::ClearCastingSpell(int32_t spellId, bool clearChannel, bool a4) { + if (spellId != this->m_castSpellId) { + return; + } + + this->m_animationState &= ~0x400u; + this->m_castCount = 0; + this->m_castSpellId = 0; + this->m_castSchoolImmunities = 0; + this->m_castImmunities = 0; + + if (!a4) { + return; + } + + if (clearChannel) { + if (this->IsAutoTracking() && !CGUnit_C::s_trackingType) { + CGObject_C* target = ClntObjMgrObjectPtr(CGUnit_C::s_trackingGUID, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (target) { + C3Vector targetPosition = target->GetPosition(); + C3Vector position = this->GetPosition(); + float facing = CalculateFacingTo(&position, &targetPosition); + C3Vector none = C3Vector(); + WOWGUID guid = WOWGUID(); + static_cast(this)->ClickToMove(2, &guid, &none, facing); + } + } + + SpellRec spell; + + if (g_spellDB.GetRecord(this->m_unit->m_unitChannelSpell, &spell) && (spell.m_attributesEx & 0x4000) && this->IsActiveMoverTracking(2)) { + this->ClearTrackingTarget(false, true); + } + } + + this->m_chainSpellTargets.SetCount(0); + + if (spellId != Spell_C_GetAutoRepeatingSpell()) { + this->CancelRangedMode(); + } + + if (this->m_fishingLineEffect) { + this->m_fishingLineEffect->Release(); + this->m_fishingLineEffect = nullptr; + } + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGGameUI::CloseLoot(true, (this->m_movement->m_flags & 0xC0100F) != 0, false); + } +} + +// VERIFY: 388611be manual +// VERIFY: d1a0635a manual +// OFFSET: 0x0072DF00 +void CGUnit_C::ReleaseMissiles(const C3Vector& position) { + if (this->m_missiles) { + this->CancelRangedMode(); + } + + SpellRec spell; + + while (this->m_missiles) { + CM2Model* model = this->m_missiles->m_model; + + if (model) { + if (!model->IsLoaded(0, 0)) { + this->m_clientFlags |= 0x800; + break; + } + + this->m_missiles->m_model->m_fadeAlpha = 1.0f; + } + + if (this->IsMissileTrajectoryUpdateWaitingForMissileRelease() && this->m_missileTrajectoryReleased == this->m_missiles->m_castID) { + this->SendFinalMissileTrajectoryUpdate(); + } + + PendingSpellCast* cast = Spell_C_GetDelayedTrajectoryCast(); + + if (cast && this->m_missiles->m_castID == cast->m_data.m_castCount) { + if (!Spell_C_SendDelayedMissileTrajectoryCast(this)) { + if (!this->m_missiles) { + break; + } + + if (this->m_precastMissileModel == this->m_missiles->m_model) { + if (this->m_precastMissileModel) { + if (this->m_precastMissileModel->m_attachParent) { + this->m_precastMissileModel->DetachFromParent(); + } + + this->m_precastMissileModel->Release(); + this->m_precastMissileModel = nullptr; + this->m_precastCastCount = 0; + } + + this->m_clientFlags &= ~0x1000000u; + } + + this->m_missiles->DeleteSelf(); + continue; + } + + if (!this->m_missiles) { + break; + } + } + + CM2Model* precast = this->m_precastMissileModel; + + if (precast && precast == this->m_missiles->m_model) { + precast->Animate(); + C44Matrix transform = precast->m_matrixF4 * precast->m_scene->m_viewInv; + + if (this->m_precastMissileModel) { + if (this->m_precastMissileModel->m_attachParent) { + this->m_precastMissileModel->DetachFromParent(); + } + + this->m_precastMissileModel->Release(); + this->m_precastMissileModel = nullptr; + this->m_precastCastCount = 0; + } + + this->m_clientFlags &= ~0x1000000u; + this->m_missiles->m_flags |= 0x2000000; + CM2Model* missileModel = this->m_missiles->m_model; + missileModel->m_fFlags |= 0x8000; + missileModel->m_worldTransform = transform; + C3Vector firePosition(transform.d0, transform.d1, transform.d2); + this->m_missiles->FireMissiles(&firePosition); + continue; + } + + if (!g_spellDB.GetRecord(this->m_missiles->m_spellID, &spell)) { + continue; + } + + C3Vector overridePosition = C3Vector(); + + if (this->OverrideMissileFirePos(&overridePosition, &spell)) { + this->m_missiles->FireMissiles(&overridePosition); + } else { + this->m_missiles->FireMissiles(&position); + } + } + + if (this->m_precastMissileModel) { + if (this->m_precastMissileModel->m_attachParent) { + this->m_precastMissileModel->DetachFromParent(); + } + + this->m_precastMissileModel->Release(); + this->m_precastMissileModel = nullptr; + this->m_precastCastCount = 0; + } + + this->m_clientFlags &= ~0x1000000u; +} + +// VERIFY: 402547fa manual +// OFFSET: 0x0073A520 +void CGUnit_C::OnChannelObjectChanged(WOWGUID oldObject, int32_t oldSpell) { + CGObject_C* object = ClntObjMgrObjectPtr(oldObject, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (object && oldSpell) { + object->ClearEffectKit(oldSpell, 2, 0, 0, 0); + object->ClearEffectKit(oldSpell, 1, 0, 0, 0); + object->ClearEffectKit(oldSpell, 5, 0, 0, 0); + object->ClearEffectKit(oldSpell, 6, 0, 0, 0); + } + + if (this->m_fishingLineEffect) { + this->m_fishingLineEffect->Release(); + this->m_fishingLineEffect = nullptr; + } + + CGGameObject_C* gameObject = static_cast(ClntObjMgrObjectPtr(this->m_unit->m_unitFieldChannelObject, TYPEMASK_GAMEOBJECT, __FILE__, __LINE__)); + + if (gameObject && this->m_unit->m_unitChannelSpell && gameObject->m_gameObject->m_typeID == 17) { + if (this->m_sheatheState == 1) { + this->CreateFishingLineEffect(); + } else { + this->SetSheatheState(1, 1, 0); + } + + return; + } + + if (!ClntObjMgrObjectPtr(this->m_unit->m_unitFieldChannelObject, TYPEMASK_UNIT, __FILE__, __LINE__)) { + return; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(this->m_unit->m_unitChannelSpell, &spell) && (spell.m_attributesEx & 0x4000) && this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + WOWGUID target = this->m_unit->m_unitFieldChannelObject; + this->SetTrackingTarget(target, 1); + } +} + +// VERIFY: 694d4b34 manual +// OFFSET: 0x0072BC70 +void CGUnit_C::UpdateChannelEffects() { + this->m_clientFlags &= ~0x8000u; + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_unit->m_unitChannelSpell, &spell)) { + return; + } + + if (spell.m_attributesEx & 0x4000) { + this->m_clientFlags |= 0x8000; + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + WOWGUID target = this->m_unit->m_unitFieldChannelObject; + this->SetTrackingTarget(target, 1); + } + } + + const SpellVisualRec* visual = GetSpellVisual(&spell); + + if (!visual) { + return; + } + + SpellVisualKitRec* kit = g_spellVisualKitDB.GetRecord(visual->m_channelKit); + + if (!kit) { + return; + } + + uint32_t playAnim = 1; + SpellVisualKitRec* castKit = g_spellVisualKitDB.GetRecord(visual->m_castKit); + + if (castKit && this->GetCurrentTorsoAnimId() == static_cast(castKit->m_animID)) { + playAnim = 0; + } + + PlaySpellVisuaKitData data(&spell, kit, 2); + data.unk_0018 = playAnim; + this->PlaySpellVisualKit(data); + this->CreateFishingLineEffect(); +} + +// VERIFY: 66625199 manual +// OFFSET: 0x0071F8B0 +bool CGUnit_C::CanInteract(const CGGameObject_C* gameObject) const { + return (!(this->m_obj->m_type & TYPEMASK_PLAYER) || !(static_cast(this)->m_player->m_playerFlags & 0x10)) && gameObject->ObjectReaction(this) >= 3; +} + +// VERIFY: a3dabf99 manual +// OFFSET: 0x00718E50 +static int32_t UnitColorUpdateProc(WOWGUID guid, void* param) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit || unit->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + return 1; + } + + const WOWGUID& owner = unit->m_unit->m_unitFieldCharmedby ? unit->m_unit->m_unitFieldCharmedby : unit->m_unit->m_unitFieldCreatedby; + + if (owner != ClntObjMgrGetActivePlayer()) { + PlayerNameTriggerColorUpdate(unit->m_nameDesc); + + if (unit->m_namePlateFrame) { + unit->m_namePlateFrame->UpdateColorDisplay(unit); + } + + Script_SendUnitSignal(unit->m_obj->m_guid, 49); + } + + return 1; +} + +// VERIFY: 550305c8 auto +// OFFSET: 0x0071F8F0 +void CGUnit_C::UpdateReaction(bool a1) { + PlayerNameTriggerColorUpdate(this->m_nameDesc); + + if (this->m_namePlateFrame) { + this->m_namePlateFrame->UpdateColorDisplay(this); + } + + Script_SendUnitSignal(this->m_obj->m_guid, 49); + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + SendQuestGiverStatusMultipleQuery(); + ClntObjMgrEnumVisibleObjects(UnitColorUpdateProc, nullptr); + return; + } + + if (a1) { + ClntObjMgrEnumVisibleObjects(PetColorUpdateProc, this); + } + + this->RefreshInteractIcon(); +} + +// VERIFY: 8da8cbd4 manual +// OFFSET: 0x00728F70 +void CGUnit_C::OnFlagChangedActivePlayer(uint32_t oldFlags, uint32_t changed) { + if (changed & 0x40000) { + uint32_t time = OsGetAsyncTimeMs(); + CGInputControl::GetActive()->UpdatePlayer(time, 1); + } + + if (changed & 0x1C20000) { + CGSpellBook::UpdateUsable(); + } + + if (changed & 0x80000) { + CGSpellBook::UpdateUsable(); + CGGameUI::SetRegenEnabled(!(this->m_unit->m_unitFieldFlags & 0x80000)); + } + + if (changed & 0x100000) { + if (this->m_unit->m_unitFieldFlags & 0x100000) { + this->ClearTrackingTarget(false, true); + } else if (!CGGameUI::m_inCinematic) { + CGChat::ZoneUpdate(); + } + } +} + +// VERIFY: a548f0b4 manual +// OFFSET: 0x0073C330 +void CGUnit_C::OnFlagChanged(uint32_t oldFlags) { + uint32_t flags = this->m_unit->m_unitFieldFlags; + uint32_t changed = oldFlags ^ flags; + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + this->OnFlagChangedActivePlayer(flags, changed); + } else if (static_cast(this->m_unit->m_unitFieldHealth) > 0 && (changed & 0x400)) { + this->UpdateBaseAnimation(0, -1); + } + + if (changed & 0x200000) { + const CGUnitVirtualItem* mainHand = this->GetVirtualItem(0, true); + + if (mainHand && mainHand->m_classID == 2) { + const CGUnitVirtualItem* item; + + if ((this->m_unit->m_unitFieldFlags & 0x200000) && (item = this->GetVirtualItem(0, true)) && item->m_classID == 2 && this->m_sheatheState <= 1) { + CCharacterComponent::RemoveHandItem(this->m_worldModel, INVSLOT_MAINHAND, static_cast(this->m_sheatheState ? 0 : mainHand->m_sheatheType), false); + } else { + if (this->unk_0988) { + this->unk_0988->DeleteSelf(); + } + + this->AddHandItem(0); + } + } + + const CGUnitVirtualItem* offHand = this->GetVirtualItem(1, true); + + if (offHand && offHand->m_classID == 2) { + const CGUnitVirtualItem* item; + + if ((((this->m_unit->m_unitFieldFlags & 0x200000) && (this->GetVirtualItem(0, true), !this->IsDisarmed(0)) && (item = this->GetVirtualItem(1, true)) && item->m_classID == 2) || static_cast(this->m_unit->m_unitFieldFlags2) < 0) && this->m_sheatheState == 1) { + CCharacterComponent::RemoveHandItem(this->m_worldModel, INVSLOT_OFFHAND, SHEATHE_NONE, false); + } else { + this->AddHandItem(1); + } + } + + if (this->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + CGSpellBook::UpdateUsable(); + } + } + + if (changed & 0x180) { + this->UpdateReaction(false); + } + + if (changed & 0x800) { + const WOWGUID& owner = this->m_unit->m_unitFieldCharmedby ? this->m_unit->m_unitFieldCharmedby : this->m_unit->m_unitFieldSummonedby; + + if (owner == ClntObjMgrGetActivePlayer()) { + CGPetInfo::SetIsAttackingTarget((flags >> 11) & 1); + } + } + + if (changed & 0x4000000) { + CGGameUI::UnitTooltipUpdate(this->m_obj->m_guid); + } + + if (changed & 0x8000000) { + Script_SendUniqueSignal(this->m_obj->m_guid, 142); + } + + if ((changed & 0x2000000) && (this->m_unit->m_unitFieldFlags & 0x2000000)) { + CGGameUI::BreakTarget(this->m_obj->m_guid); + } +} + +// VERIFY: a4d452c0 manual +// OFFSET: 0x00734A40 +void CGUnit_C::AnimEventCallback(CM2Model* model, uint32_t boneId, uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time, uint64_t param) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(WOWGUID{ param }, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + if (std::isnan(static_cast(position->x)) || std::isnan(static_cast(position->y)) || std::isnan(static_cast(position->z))) { + unit->GetUnitName(nullptr, 1); + } + + unit->HandleAnimEvent(boneId, eventId, data, position, time); +} + +// VERIFY: 88971327 manual +// OFFSET: 0x00732650 +void CGUnit_C::HandleAnimEvent(uint32_t boneId, uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time) { + switch (eventId) { + case 0x48414324: + case 0x48544424: + case 0x50504324: + case 0x50574224: + case 0x53534324: + case 0x30484124: + case 0x31484124: + case 0x32484124: + case 0x33484124: + this->HandleCombatAnimEvent(eventId, data, position, time); + return; + + case 0x31444624: + case 0x32444624: + case 0x33444624: + case 0x34444624: + case 0x35444624: + case 0x36444624: + case 0x37444624: + case 0x38444624: + case 0x39444624: + case 0x58444624: + this->HandlePlayStandSound(eventId, data); + return; + + case 0x4C534324: + case 0x52534324: + case 0x54534324: + if (this->m_missiles) { + this->SetAnimEventPosition(position); + } + return; + + case 0x304C4224: + case 0x304C4624: + case 0x304C5224: + case 0x304C5324: + case 0x304C5724: + case 0x314C4224: + case 0x314C4624: + case 0x314C5224: + case 0x314C5324: + case 0x314C5724: + case 0x324C4224: + case 0x324C4624: + case 0x324C5224: + case 0x324C5324: + case 0x324C5724: + case 0x334C4224: + case 0x334C4624: + case 0x334C5224: + case 0x334C5324: + case 0x334C5724: + this->FootstepAnimEventHit(position, 1); + return; + + case 0x30524224: + case 0x30524624: + case 0x30525224: + case 0x30525324: + case 0x30525724: + case 0x31524224: + case 0x31524624: + case 0x31525224: + case 0x31525324: + case 0x31525724: + case 0x32524224: + case 0x32524624: + case 0x32525224: + case 0x32525324: + case 0x32525724: + case 0x33524224: + case 0x33524624: + case 0x33525224: + case 0x33525324: + case 0x33525724: + this->FootstepAnimEventHit(position, 0); + return; + + case 0x30475624: + case 0x31475624: + case 0x32475624: + case 0x33475624: + case 0x34475624: + case 0x35475624: + case 0x36475624: + case 0x37475624: + case 0x38475624: + if (this->m_vehicle && this->m_vehicle->m_vehicleRec) { + this->m_vehicle->HandleBoneAnimGrabEvent(boneId, eventId); + } + return; + + case 0x30545624: + case 0x31545624: + case 0x32545624: + case 0x33545624: + case 0x34545624: + case 0x35545624: + case 0x36545624: + case 0x37545624: + case 0x38545624: + if (this->GetVehicleRec()) { + this->m_vehicle->HandleBoneAnimThrowEvent(boneId, eventId); + } + return; + + case 0x44435324: + if (this->m_soundData) { + SI2::PlaySoundKit(this->m_soundData->m_spellCastDirectedSoundID, position, nullptr, nullptr, 0, nullptr, 1, 0); + } + return; + + case 0x4C485324: + this->ExchangeSheathedWeapon(position, 1, 0x200000); + return; + + case 0x52485324: + this->ExchangeSheathedWeapon(position, 0, 0x100000); + return; + + case 0x48544224: { + if (ClntObjMgrGetPlayerType() == 1 || !this->m_modelData || (this->m_modelData->m_flags & 2)) { + return; + } + + int32_t type; + + if ((this->m_obj->m_type & TYPEMASK_PLAYER) && static_cast(this)->GetDrunknessTurnValue() >= 0.5f) { + type = 7; + } else if (this->m_clientFlags & 0x20) { + type = 2; + } else if (this->m_clientFlags & 0x40) { + type = 3; + } else { + return; + } + + void* memory = SMemAlloc(sizeof(CEffect), __FILE__, __LINE__, 0); + CEffect* effect = memory ? new (memory) CEffect() : nullptr; + WOWGUID guid = this->m_obj->m_guid; + effect->AddSpecialEffect(type, guid, CGObject_C::EffectOnceHandler); + effect->m_flags |= 0x20; + effect->Release(); + return; + } + + case 0x474D5324: + if (this->m_soundData) { + SI2::PlaySoundKit(this->m_soundData->m_submergeSoundID, position, nullptr, nullptr, 0, nullptr, 1, 0); + } + return; + + case 0x444D5324: + if (this->m_soundData) { + SI2::PlaySoundKit(this->m_soundData->m_submergedSoundID, position, nullptr, nullptr, 0, nullptr, 1, 0); + } + return; + + case 0x474E5724: + this->PlayUnitSound(7, 0); + return; + + case 0x47475724: + this->PlayUnitSound(10, 0); + return; + + case 0x44534524: + this->PlayEmoteStateSound(position); + return; + + case 0x44534624: + this->HandleFootfallAnimEvent(*position); + return; + + case 0x44534324: + this->PlayEmoteSound(data, true, -1); + return; + + case 0x44525424: + if (this->m_obj->m_type & TYPEMASK_PLAYER) { + static_cast(this)->HandleSpellEventSound(); + } + return; + + case 0x54524224: + if (this->m_soundData) { + SI2::PlaySoundKit(this->m_soundData->m_birthSoundID, position, nullptr, nullptr, 0, nullptr, 1, 0); + } + return; + + case 0x52574224: { + if (!CGUnit_C::s_trackingType) { + this->ClearTrackingTarget(false, true); + } + + if (this->m_animationState & 0x4000) { + this->m_animationState &= ~0x4000u; + } + + if (this->m_missiles) { + C3Vector eventPosition; + + if (IsBowAnim(this->GetCurrentTorsoAnimId()) && this->m_worldModel->HasAttachment(35)) { + eventPosition = this->m_worldModel->GetAttachmentPosition(35); + + if (this->unk_0B40) { + this->unk_0B40->SetBoneSequence(0xFFFFFFFF, 0, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } + } else if (IsRifleAnim(this->GetCurrentTorsoAnimId()) && this->m_worldModel->HasAttachment(36)) { + eventPosition = this->m_worldModel->GetAttachmentPosition(36); + + if (this->unk_0B40) { + this->unk_0B40->SetBoneSequence(0xFFFFFFFF, 161, 0xFFFFFFFF, 0, 1.0f, 1, 1); + } + } else { + eventPosition = *position; + } + + this->SetAnimEventPosition(&eventPosition); + } + + if (this->m_ammoModel && this->m_ammoModel->m_attachParent) { + this->m_ammoModel->DetachFromParent(); + } + + return; + } + + default: + return; + } +} + +// VERIFY: 7ce6616c manual +// OFFSET: 0x00756240 +void CGUnit_C::HandleCombatAnimEvent(uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time) { + CGUnit_C* attacker = nullptr; + CGUnit_C* target = nullptr; + + if (this->m_lastAttackRound.m_attacker) { + attacker = static_cast(ClntObjMgrObjectPtr(this->m_lastAttackRound.m_attacker, TYPEMASK_UNIT, __FILE__, __LINE__)); + } + + if (this->m_lastAttackRound.m_target) { + target = static_cast(ClntObjMgrObjectPtr(this->m_lastAttackRound.m_target, TYPEMASK_UNIT, __FILE__, __LINE__)); + } + + switch (eventId) { + case 0x30484124: + case 0x31484124: + case 0x32484124: + case 0x33484124: + if (this->m_lastAttackRound.m_damage && attacker && attacker->m_soundData) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 14; + + switch (eventId) { + case 0x30484124: + SI2::PlaySoundKit(attacker->m_soundData->m_customAttack[0], position, nullptr, &properties, 0, nullptr, 1, 0); + break; + + case 0x31484124: + SI2::PlaySoundKit(attacker->m_soundData->m_customAttack[1], position, nullptr, &properties, 0, nullptr, 1, 0); + break; + + case 0x32484124: + SI2::PlaySoundKit(attacker->m_soundData->m_customAttack[2], position, nullptr, &properties, 0, nullptr, 1, 0); + break; + + case 0x33484124: + SI2::PlaySoundKit(attacker->m_soundData->m_customAttack[3], position, nullptr, &properties, 0, nullptr, 1, 0); + break; + } + + this->m_lastAttackRound.m_hitInfo |= 0x200000; + } + + case 0x48414324: + if (attacker) { + uint32_t victimState = attacker->m_lastAttackRound.m_victimState; + + if (!victimState || victimState == 2 || victimState == 6) { + attacker->SetKeyBoneSequenceSpeed(attacker->m_worldModel, 0xFFFFFFFF, 0.5f, 0); + } + } else if (!target) { + if (this->m_obj->m_type & TYPEMASK_PLAYER) { + static_cast(this)->HandleSpellEventSound(); + } else { + CreatureSoundDataRec* soundData = this->GetSoundData(); + + if (soundData) { + SI2::PlaySoundKit(soundData->m_soundExertionID, position, nullptr, nullptr, 0, nullptr, 0, 0); + } + } + } + + if (target) { + target->PlayVictimRound(this->m_lastAttackRound); + } + + this->m_lastAttackRound.m_attacker = WOWGUID(); + this->m_lastAttackRound.m_target = WOWGUID(); + return; + + case 0x53534324: { + if (!attacker) { + return; + } + + uint32_t victimState = this->m_lastAttackRound.m_victimState; + + if (!victimState || victimState == 2 || victimState == 6) { + return; + } + + int32_t swingType = 0; + + if (this->GetWeaponSwingType(!(this->m_lastAttackRound.m_hitInfo & 4), &swingType) && this->m_lastAttackRound.m_victimState) { + int32_t self = CGUnit_C::s_activeMover == this->m_lastAttackRound.m_attacker || CGUnit_C::s_activeMover == this->m_lastAttackRound.m_target; + SI2::PlayWeaponSwooshSound(swingType, this->m_lastAttackRound.m_hitInfo & 0x200, position, this->m_lastAttackRound.m_hitInfo & 0x10, self); + } + + return; + } + + case 0x50574224: { + if (this->IsActivePlayer()) { + SpellRec spell; + + if (!g_spellDB.GetRecord(this->m_castSpellId, &spell) || !(spell.m_attributes & 2)) { + if (!g_spellDB.GetRecord(Spell_C_GetAutoRepeatingSpell(), &spell) || !(spell.m_attributes & 2)) { + return; + } + } + } + + if (this->m_movementData.m_flags & 0x2E0100F) { + return; + } + + this->PlayRangedItemPull(); + const CGUnitVirtualItem* item = this->GetVirtualItem(2, false); + + if (!item || item->m_classID != 2 || (item->m_subclassID != 3 && item->m_subclassID != 18)) { + if (this->m_ammoModel && !this->m_ammoModel->m_attachParent) { + this->m_ammoModel->AttachToParent(this->m_worldModel, 35, nullptr, 0); + } + } + + this->m_animationState |= 0x4000; + return; + } + + case 0x48544424: + this->PlayDeathThud(); + this->ShakeCameraOnHit(); + this->ShowLootEffect(); + return; + + case 0x50504324: { + if (!target || (target->m_unit->m_unitFieldFlags2 & 1) || target->GetClientStandState() == 7) { + return; + } + + uint32_t victimState = this->m_lastAttackRound.m_victimState; + + if (victimState == 3) { + if (!target->m_creatureCacheEntry || !(target->m_creatureCacheEntry->m_typeFlags & 0x200000)) { + target->PlayParryAnimation(); + } + + this->m_lastAttackRound.m_hitInfo &= ~2u; + } else if (victimState == 2 || victimState == 8) { + if (!target->m_creatureCacheEntry || !(target->m_creatureCacheEntry->m_typeFlags & 0x200000)) { + target->PlayBaseAnimation(ANIM_DODGE, 0); + } + + this->m_lastAttackRound.m_hitInfo &= ~2u; + } else if (this->m_lastAttackRound.m_blocked) { + if (!target->m_creatureCacheEntry || !(target->m_creatureCacheEntry->m_typeFlags & 0x200000)) { + target->PlayBaseAnimation(ANIM_SHIELD_BLOCK, 0); + } + + this->m_lastAttackRound.m_hitInfo &= ~2u; + } + + return; + } + + default: + return; + } +} + +// VERIFY: 927340f4 auto +// OFFSET: 0x0073B050 +void CGUnit_C::PlayParryAnimation() { + if (this->IsDeadOrAttachmentDying() || !this->m_worldModel->IsLoaded(0, 0) || this->DoNotPlayWoundAnim()) { + return; + } + + const CGUnitVirtualItem* item = this->GetVirtualItem(0, false); + + if (!item || item->m_classID != 2 || !this->m_unit->m_unitFieldBytes2[0]) { + this->PlayBaseAnimation(ANIM_PARRY_UNARMED, 0); + return; + } + + uint32_t twoHandAnim = ANIM_PARRY_2H - (this->GetVirtualItem(1, false) != nullptr); + + switch (item->m_subclassID) { + case 0: + case 4: + case 7: + case 11: + case 14: + case 15: + case 20: + this->PlayBaseAnimation(ANIM_PARRY_1H, 0); + break; + + case 1: + case 5: + case 8: + case 12: + this->PlayBaseAnimation(twoHandAnim, 0); + break; + + case 6: + case 10: + case 17: + this->PlayBaseAnimation(ANIM_PARRY_2HL, 0); + break; + + case 13: + this->PlayBaseAnimation(ANIM_PARRY_UNARMED, 0); + break; + + default: + break; + } +} + +// VERIFY: bb462764 manual +// OFFSET: 0x00732FF0 +void CGUnit_C::CreateMissile(const WOWGUID* target, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, int32_t hit, uint32_t missReason, uint32_t reflectResult, const SpellVisualRec* visual, int32_t spellId, const TSStackArray* targets, const TSStackArray* missReasons, const TSStackArray* reflectResults, uint32_t delay) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + float scale = 1.0f; + CM2Model* model = nullptr; + + if (this->m_precastMissileModel && !(this->m_clientFlags & 0x1000000)) { + this->m_precastMissileModel->m_refCount++; + this->m_clientFlags |= 0x1000000; + model = this->m_precastMissileModel; + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + scale = effectName->m_scale; + } + } else if (visual->m_missileModel) { + switch (visual->m_missileModel) { + case -5: + case -4: + model = this->CreateItemModel(ammoDisplayId, ammoInventoryType, nullptr); + break; + + case -3: + model = this->CreateItemModel(2, &scale); + break; + + case -2: + model = this->CreateItemModel(1, &scale); + break; + + case -1: + model = this->CreateItemModel(0, &scale); + break; + + default: { + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + model = World::s_m2Scene->CreateModel(effectName->m_fileName, 0x40); + scale = effectName->m_scale; + } + + break; + } + } + } else if (ammoDisplayId) { + ItemDisplayInfoRec displayRec; + + if (g_itemDisplayInfoDB.GetRecord(ammoDisplayId, &displayRec)) { + model = CCharacterComponent::MakeAmmoModel(this->m_worldModel, &displayRec, ammoInventoryType); + } + } + + if (!model) { + model = World::s_m2Scene->CreateModel("Spells\\ErrorCube.mdx", 0); + } + + AnimationDataRec* animation = g_animationDataDB.GetRecord(this->GetCurrentTorsoAnimId()); + + if (animation && (animation->m_behaviorID == 49 || animation->m_behaviorID == 106 || animation->m_behaviorID == 110)) { + model->m_fadeAlpha = 0.0f; + } + + CMissile* missile = CMissile::NewMissile(); + missile->m_model = model; + missile->m_casterGuid = this->m_obj->m_guid; + missile->m_targetGuid = *target; + missile->m_spellID = spell.m_id; + missile->m_castID = data->m_castCount; + missile->m_speed = spell.m_speed; + missile->m_baseSpeed = spell.m_speed; + missile->m_hitResult = missReason; + missile->m_missReason = reflectResult; + + if (hit) { + missile->m_flags |= 1; + } + + if (spell.m_attributes & 2) { + const CGUnitVirtualItem* item = this->GetVirtualItem(2, false); + + if (item && item->m_classID == 2 && (item->m_subclassID == 2 || item->m_subclassID == 18 || item->m_subclassID == 16)) { + missile->m_flags |= 4; + } + } + + if (missReason == 11 && (spell.m_attributesExG & 0x20000000)) { + missile->m_flags |= 0x8000000; + } + + missile->m_scale = scale; + missile->m_soundKitID = visual->m_missileSound; + const SpellVisualRec* spellVisual = GetSpellVisual(&spell); + + if (spellVisual) { + float height = spellVisual->m_missileFollowGroundHeight * 0.001f; + + if (height <= 0.25f) { + height = 0.25f; + } + + missile->m_groundOffset = height; + float rate = spellVisual->m_missileFollowGroundDropSpeed * 0.001f; + + if (rate <= 0.01f) { + rate = 0.01f; + } + + missile->m_followGroundRate = rate; + float approach = 0.001f * spellVisual->m_missileFollowGroundApproach; + + if (approach < 0.0f) { + approach = 0.0f; + } else if (approach >= 1.0f) { + approach = 1.0f; + } + + missile->m_followGroundStart = approach; + missile->m_motionFlags = spellVisual->m_missileFollowGroundFlags; + + if (spellVisual->m_missileFollowGroundFlags & 1) { + missile->m_flags |= 0x7800; + } + } + + int32_t attachment = (visual->m_flags & 0x200) ? visual->m_missileDestinationAttachment : s_effectAttachmentIds[visual->m_missileDestinationAttachment]; + C3Vector offset(visual->m_missileImpactOffset[0], -visual->m_missileImpactOffset[1], visual->m_missileImpactOffset[2]); + bool hasOffset = 0.0f != offset.x || 0.0f != offset.y || offset.z != 0.0f; + + if (*target) { + missile->m_attachmentID = attachment; + missile->m_attachOffset = offset; + CGObject_C* object = ClntObjMgrObjectPtr(*target, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (object) { + missile->m_impactPos = object->GetPosition(); + } + } else { + if ((data->m_targetFlags & 0x60) == 0x60) { + missile->m_position = data->m_sourcePos; + missile->m_impactPos = data->m_destPos; + missile->m_transportGuid = data->m_destTarget; + } else if (data->m_targetFlags & 0x40) { + missile->m_impactPos = data->m_destPos; + missile->m_transportGuid = data->m_destTarget; + } else if (data->m_targetFlags & 0x20) { + missile->m_impactPos = data->m_sourcePos; + missile->m_transportGuid = data->m_sourceTarget; + } else { + if (!targets->m_count) { + missile->DeleteSelf(); + return; + } + + missile->m_targetGuid = targets->m_data[0]; + missile->m_attachmentID = attachment; + missile->m_attachOffset = offset; + CGObject_C* object = ClntObjMgrObjectPtr(targets->m_data[0], TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (object) { + missile->m_impactPos = object->GetPosition(); + } + + goto targetsDone; + } + + missile->m_flags |= 1; + missile->m_attachmentID = -1; + + if (hasOffset) { + C44Matrix matrix = this->m_vehiclePassenger ? this->GetModelMatrix() : this->GetMatrix(); + matrix.d0 = 0.0f; + matrix.d1 = 0.0f; + matrix.d2 = 0.0f; + C3Vector rotated = offset * matrix; + missile->m_impactPos.x = missile->m_impactPos.x + rotated.x; + missile->m_impactPos.y = rotated.y + missile->m_impactPos.y; + missile->m_impactPos.z = rotated.z + missile->m_impactPos.z; + } + } + +targetsDone: + uint32_t multiTarget = spell.m_attributesExD & 0x40000; + + if (!*target && targets->m_count) { + if (!multiTarget && !(data->m_targetFlags & 0x60)) { + missile->m_flags &= ~0x200u; + goto flagsDone; + } + + missile->m_targets.Set(targets->m_count, reinterpret_cast(targets->m_data)); + + if (missReasons && missReasons->m_count) { + missile->m_targetHitResults.Set(missReasons->m_count, missReasons->m_data); + } + + if (reflectResults && reflectResults->m_count) { + missile->m_targetMissReasons.Set(reflectResults->m_count, reflectResults->m_data); + } + } + + if (multiTarget) { + missile->m_flags |= 0x200; + } else { + missile->m_flags &= ~0x200u; + } + +flagsDone: + missile->m_currentTarget = 0; + int32_t missileCount = 1; + + if (spellVisual && spellVisual->m_missileMotion) { + missile->m_flags |= 0x3800; + missile->InstallMotionScriptFunction(spellVisual->m_missileMotion); + SpellMissileMotionRec* motion = g_spellMissileMotionDB.GetRecord(spellVisual->m_missileMotion); + + if (motion && motion->m_missileCount >= 1) { + missileCount = motion->m_missileCount; + } + } + + missile->m_castTime = OsGetAsyncTimeMs(); + missile->SetReadyToFire(&this->m_missiles); + this->m_lastMissileTime = missile->m_castTime; + + if (data->m_castFlags & 0x20000) { + missile->m_pitch = data->m_elevation; + missile->m_flags |= 0x10800; + missile->m_trajectorySpeed = data->unk_0120; + missile->m_arrivalTime = delay + missile->m_castTime; + } + + if ((this->m_clientFlags & 0x400) || (this->m_obj->m_guid == CGPetInfo::GetPet(0) && !this->m_unit->m_unitFieldCharmedby)) { + missile->m_flags |= 0x200000; + } + + missile->unk_0114 = missileCount; + + if (missileCount > 1) { + missile->unk_0110 = 0; + + for (int32_t i = 1; i < missileCount; i++) { + missile = CMissile::CopyMissile(missile); + missile->unk_0110 = i; + missile->SetReadyToFire(&this->m_missiles); + } + } + + if (visual->m_flags & 4) { + C3Vector position = this->GetMissileFirePosition(); + this->ReleaseMissiles(position); + } +} + +// VERIFY: 9a6a877b manual +// OFFSET: 0x00733820 +void CGUnit_C::CreateMissile(const SpellCastTargetPoint* point, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, const SpellVisualRec* visual, int32_t spellId, uint32_t delay) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + float scale = 1.0f; + CM2Model* model = nullptr; + + if (this->m_precastMissileModel && !(this->m_clientFlags & 0x1000000)) { + this->m_precastMissileModel->m_refCount++; + this->m_clientFlags |= 0x1000000; + model = this->m_precastMissileModel; + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + scale = effectName->m_scale; + } + } else if (visual->m_missileModel) { + switch (visual->m_missileModel) { + case -5: + case -4: + model = this->CreateItemModel(ammoDisplayId, ammoInventoryType, nullptr); + break; + + case -3: + model = this->CreateItemModel(2, &scale); + break; + + case -2: + model = this->CreateItemModel(1, &scale); + break; + + case -1: + model = this->CreateItemModel(0, &scale); + break; + + default: { + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + model = World::s_m2Scene->CreateModel(effectName->m_fileName, 0x40); + scale = effectName->m_scale; + } + + break; + } + } + } else if (ammoDisplayId) { + ItemDisplayInfoRec displayRec; + + if (g_itemDisplayInfoDB.GetRecord(ammoDisplayId, &displayRec)) { + model = CCharacterComponent::MakeAmmoModel(this->m_worldModel, &displayRec, ammoInventoryType); + } + } + + if (!model) { + model = World::s_m2Scene->CreateModel("Spells\\ErrorCube.mdx", 0); + } + + AnimationDataRec* animation = g_animationDataDB.GetRecord(this->GetCurrentTorsoAnimId()); + + if (animation && (animation->m_behaviorID == 49 || animation->m_behaviorID == 106 || animation->m_behaviorID == 110)) { + model->m_fadeAlpha = 0.0f; + } + + CMissile* missile = CMissile::NewMissile(); + missile->m_model = model; + missile->m_casterGuid = this->m_obj->m_guid; + missile->m_targetGuid = WOWGUID(); + missile->m_spellID = spell.m_id; + missile->m_castID = data->m_castCount; + missile->m_speed = spell.m_speed; + missile->m_baseSpeed = spell.m_speed; + missile->m_flags |= 1; + missile->m_hitResult = 0; + missile->m_missReason = 0; + + if (spell.m_attributes & 2) { + const CGUnitVirtualItem* item = this->GetVirtualItem(2, false); + + if (item && item->m_classID == 2 && (item->m_subclassID == 2 || item->m_subclassID == 18 || item->m_subclassID == 16)) { + missile->m_flags |= 4; + } + } + + missile->m_scale = scale; + missile->m_soundKitID = visual->m_missileSound; + const SpellVisualRec* spellVisual = GetSpellVisual(&spell); + + if (spellVisual) { + float height = spellVisual->m_missileFollowGroundHeight * 0.001f; + + if (height <= 0.25f) { + height = 0.25f; + } + + missile->m_groundOffset = height; + float rate = spellVisual->m_missileFollowGroundDropSpeed * 0.001f; + + if (rate <= 0.01f) { + rate = 0.01f; + } + + missile->m_followGroundRate = rate; + float approach = 0.001f * spellVisual->m_missileFollowGroundApproach; + + if (approach < 0.0f) { + approach = 0.0f; + } else if (approach >= 1.0f) { + approach = 1.0f; + } + + missile->m_followGroundStart = approach; + missile->m_motionFlags = spellVisual->m_missileFollowGroundFlags; + + if (spellVisual->m_missileFollowGroundFlags & 1) { + missile->m_flags |= 0x7800; + } + } + + C3Vector offset(visual->m_missileImpactOffset[0], -visual->m_missileImpactOffset[1], visual->m_missileImpactOffset[2]); + bool hasOffset = 0.0f != offset.x || 0.0f != offset.y || offset.z != 0.0f; + missile->m_impactPos = point->m_position; + missile->m_transportGuid = point->m_transport; + missile->m_flags |= 1; + missile->m_attachmentID = -1; + + if (hasOffset) { + C44Matrix matrix = this->m_vehiclePassenger ? this->GetModelMatrix() : this->GetMatrix(); + matrix.d0 = 0.0f; + matrix.d1 = 0.0f; + matrix.d2 = 0.0f; + C3Vector rotated = offset * matrix; + missile->m_impactPos.x = missile->m_impactPos.x + rotated.x; + missile->m_impactPos.y = rotated.y + missile->m_impactPos.y; + missile->m_impactPos.z = rotated.z + missile->m_impactPos.z; + } + + missile->m_flags &= ~0x200u; + missile->m_currentTarget = 0; + int32_t missileCount = 1; + + if (spellVisual && spellVisual->m_missileMotion) { + missile->m_flags |= 0x3800; + missile->InstallMotionScriptFunction(spellVisual->m_missileMotion); + SpellMissileMotionRec* motion = g_spellMissileMotionDB.GetRecord(spellVisual->m_missileMotion); + + if (motion && motion->m_missileCount >= 1) { + missileCount = motion->m_missileCount; + } + } + + missile->m_castTime = OsGetAsyncTimeMs(); + missile->SetReadyToFire(&this->m_missiles); + this->m_lastMissileTime = missile->m_castTime; + + if (data->m_castFlags & 0x20000) { + missile->m_pitch = data->m_elevation; + missile->m_flags |= 0x10800; + missile->m_trajectorySpeed = data->unk_0120; + missile->m_arrivalTime = delay + missile->m_castTime; + } + + if ((this->m_clientFlags & 0x400) || (this->m_obj->m_guid == CGPetInfo::GetPet(0) && !this->m_unit->m_unitFieldCharmedby)) { + missile->m_flags |= 0x200000; + } + + missile->unk_0114 = missileCount; + + if (missileCount > 1) { + missile->unk_0110 = 0; + + for (int32_t i = 1; i < missileCount; i++) { + missile = CMissile::CopyMissile(missile); + missile->unk_0110 = i; + missile->SetReadyToFire(&this->m_missiles); + } + } + + if (visual->m_flags & 4) { + C3Vector position = this->GetMissileFirePosition(); + this->ReleaseMissiles(position); + } +} + +// VERIFY: e1531680 manual +// OFFSET: 0x00733E20 +void CGUnit_C::CreateMissile(const TSStackArray* points, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, const SpellVisualRec* visual, int32_t spellId, uint32_t delay) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + float scale = 1.0f; + CM2Model* model = nullptr; + + if (this->m_precastMissileModel && !(this->m_clientFlags & 0x1000000)) { + this->m_precastMissileModel->m_refCount++; + this->m_clientFlags |= 0x1000000; + model = this->m_precastMissileModel; + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + scale = effectName->m_scale; + } + } else if (visual->m_missileModel) { + switch (visual->m_missileModel) { + case -5: + case -4: + model = this->CreateItemModel(ammoDisplayId, ammoInventoryType, nullptr); + break; + + case -3: + model = this->CreateItemModel(2, &scale); + break; + + case -2: + model = this->CreateItemModel(1, &scale); + break; + + case -1: + model = this->CreateItemModel(0, &scale); + break; + + default: { + SpellVisualEffectNameRec* effectName = g_spellVisualEffectNameDB.GetRecord(visual->m_missileModel); + + if (effectName && *effectName->m_fileName) { + model = World::s_m2Scene->CreateModel(effectName->m_fileName, 0x40); + scale = effectName->m_scale; + } + + break; + } + } + } else if (ammoDisplayId) { + ItemDisplayInfoRec displayRec; + + if (g_itemDisplayInfoDB.GetRecord(ammoDisplayId, &displayRec)) { + model = CCharacterComponent::MakeAmmoModel(this->m_worldModel, &displayRec, ammoInventoryType); + } + } + + if (!model) { + model = World::s_m2Scene->CreateModel("Spells\\ErrorCube.mdx", 0); + } + + AnimationDataRec* animation = g_animationDataDB.GetRecord(this->GetCurrentTorsoAnimId()); + + if (animation && (animation->m_behaviorID == 49 || animation->m_behaviorID == 106 || animation->m_behaviorID == 110)) { + model->m_fadeAlpha = 0.0f; + } + + CMissile* missile = CMissile::NewMissile(); + missile->m_model = model; + missile->m_casterGuid = this->m_obj->m_guid; + missile->m_targetGuid = WOWGUID(); + missile->m_spellID = spell.m_id; + missile->m_castID = data->m_castCount; + missile->m_speed = spell.m_speed; + missile->m_baseSpeed = spell.m_speed; + missile->m_flags |= 1; + missile->m_hitResult = 0; + missile->m_missReason = 0; + + if (spell.m_attributes & 2) { + const CGUnitVirtualItem* item = this->GetVirtualItem(2, false); + + if (item && item->m_classID == 2 && (item->m_subclassID == 2 || item->m_subclassID == 18 || item->m_subclassID == 16)) { + missile->m_flags |= 4; + } + } + + missile->m_scale = scale; + missile->m_soundKitID = visual->m_missileSound; + const SpellVisualRec* spellVisual = GetSpellVisual(&spell); + + if (spellVisual) { + float height = spellVisual->m_missileFollowGroundHeight * 0.001f; + + if (height <= 0.25f) { + height = 0.25f; + } + + missile->m_groundOffset = height; + float rate = spellVisual->m_missileFollowGroundDropSpeed * 0.001f; + + if (rate <= 0.01f) { + rate = 0.01f; + } + + missile->m_followGroundRate = rate; + float approach = 0.001f * spellVisual->m_missileFollowGroundApproach; + + if (approach < 0.0f) { + approach = 0.0f; + } else if (approach >= 1.0f) { + approach = 1.0f; + } + + missile->m_followGroundStart = approach; + missile->m_motionFlags = spellVisual->m_missileFollowGroundFlags; + + if (spellVisual->m_missileFollowGroundFlags & 1) { + missile->m_flags |= 0x7800; + } + } + + int32_t attachment = (visual->m_flags & 0x200) ? visual->m_missileDestinationAttachment : s_effectAttachmentIds[visual->m_missileDestinationAttachment]; + missile->m_impactPos = points->m_data[0].m_position; + missile->m_transportGuid = points->m_data[0].m_transport; + missile->m_flags |= 1; + missile->m_attachmentID = attachment; + missile->m_attachOffset = C3Vector(visual->m_missileImpactOffset[0], -visual->m_missileImpactOffset[1], visual->m_missileImpactOffset[2]); + missile->m_targetPoints.Set(points->m_count, points->m_data); + missile->m_flags |= 0x200; + missile->m_currentTarget = 0; + int32_t missileCount = 1; + + if (spellVisual && spellVisual->m_missileMotion) { + missile->m_flags |= 0x3800; + missile->InstallMotionScriptFunction(spellVisual->m_missileMotion); + SpellMissileMotionRec* motion = g_spellMissileMotionDB.GetRecord(spellVisual->m_missileMotion); + + if (motion && motion->m_missileCount >= 1) { + missileCount = motion->m_missileCount; + } + } + + missile->m_castTime = OsGetAsyncTimeMs(); + missile->SetReadyToFire(&this->m_missiles); + this->m_lastMissileTime = missile->m_castTime; + + if (data->m_castFlags & 0x20000) { + missile->m_pitch = data->m_elevation; + missile->m_flags |= 0x10800; + missile->m_trajectorySpeed = data->unk_0120; + missile->m_arrivalTime = delay + missile->m_castTime; + } + + if ((this->m_clientFlags & 0x400) || (this->m_obj->m_guid == CGPetInfo::GetPet(0) && !this->m_unit->m_unitFieldCharmedby)) { + missile->m_flags |= 0x200000; + } + + missile->unk_0114 = missileCount; + + if (missileCount > 1) { + missile->unk_0110 = 0; + + for (int32_t i = 1; i < missileCount; i++) { + missile = CMissile::CopyMissile(missile); + missile->unk_0110 = i; + missile->SetReadyToFire(&this->m_missiles); + } + } + + if (visual->m_flags & 4) { + C3Vector position = this->GetMissileFirePosition(); + this->ReleaseMissiles(position); + } +} + +// VERIFY: 79c14509 auto +// OFFSET: 0x007157E0 +void CGUnit_C::ChatBubbleRemove() { + if (this->m_chatBubble) { + CGChatBubbleFrame::Remove(this->m_chatBubble); + this->m_chatBubble = nullptr; + } +} + +// VERIFY: 82092375 auto +// OFFSET: 0x00720010 +void CGUnit_C::ChatBubbleShow(int32_t type, const char* text) { + if (this->m_namePlateFrame || !text || !*text || !this->m_worldObject) { + return; + } + + switch (type) { + case 1: + case 2: + case 6: + case 12: + case 14: + case 51: { + CVar* cvar = (type == 2 || type == 51) ? g_chatBubblesPartyCVar : g_chatBubblesCVar; + + if (!cvar->m_intValue) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + C3Vector delta = this->GetPosition() - player->GetPosition(); + + if (delta.y * delta.y + delta.z * delta.z + delta.x * delta.x <= 625.0f) { + CImVector color = CGChat::GetChatColor(type); + this->ChatBubbleRemove(); + this->m_chatBubble = CGChatBubbleFrame::GetNewChatBubble(CGWorldFrame::s_currentWorldFrame); + WOWGUID guid = this->m_obj->m_guid; + this->m_chatBubble->Initialize(guid, text, color); + } + + break; + } + + default: + break; + } +} diff --git a/WoW/Source/Object/ObjectClient/Unit_C.h b/WoW/Source/Object/ObjectClient/Unit_C.h index 4a024e9..e0f8d55 100644 --- a/WoW/Source/Object/ObjectClient/Unit_C.h +++ b/WoW/Source/Object/ObjectClient/Unit_C.h @@ -22,6 +22,7 @@ class CGPlayer_C; class CGWorldFrame; class CGPartyPetState; class CGChatBubbleFrame; +class CGGameObject_C; class CGNamePlateFrame; class CM2Model; class CMovementShared; @@ -42,6 +43,7 @@ class CVehiclePassenger_C; class ItemDisplayInfoRec; class MountTransitionObject; class SpellRec; +class PendingSpellCast; class CDataStore; class CMovementStatus; class C44Matrix; @@ -103,13 +105,24 @@ struct DelayedSpellVisualKit { /* 002C */ int32_t unk_002C; }; -struct UnitThreat : public TSLinkedNode, public TSHashObject { +struct UnitThreatHandle { + /* 0000 */ uint32_t m_memHandle; +}; + +struct UnitThreat : public UnitThreatHandle, public TSHashObject { /* 0028 */ uint8_t m_status; /* 0029 */ uint8_t m_percent; /* 002A */ uint8_t unk_002A[2]; /* 002C */ int32_t m_threat; }; +class UnitThreatHeap { + public: + /* 0000 */ uint32_t m_heapId; + + UnitThreat* New(); +}; + class CGUnitVirtualItem { public: /* 0000 */ uint8_t m_classID; @@ -249,13 +262,13 @@ class CGUnit_C : public CGObject_C, public CGUnit { /* 09D4 */ int32_t m_displayId; /* 09D8 */ C3Vector m_groundNormal; /* 09E4 */ uint32_t m_targetChangeTime; - /* 09E8 */ uint32_t unk_09E8; + /* 09E8 */ uint32_t m_lastMissileTime; /* 09EC */ CMissile* m_missiles; /* 09F0 */ CMissile* m_pendingMissiles; /* 09F4 */ uint8_t m_shapeshiftSuppressed; /* 09F8 */ uint32_t unk_09F8; /* 09FC */ QUESTGIVEREMOTENODE m_emoteQueue [4]; - /* 0A1C */ uint32_t unk_0A1C; + /* 0A1C */ uint32_t m_nextBloodPoolTime; /* 0A20 */ CCombatClient m_combat; /* 0A2C */ uint32_t m_stopAttackSent; /* 0A30 */ uint32_t m_clientFlags; @@ -354,9 +367,9 @@ class CGUnit_C : public CGObject_C, public CGUnit { /* 0FAC */ uint8_t m_precastCastCount; /* 0FB0 */ int32_t m_predictedHealth; /* 0FB4 */ int32_t m_predictedPower [7]; - /* 0FD0 */ uint32_t unk_0FD0; + /* 0FD0 */ uint32_t m_powerRegenRemainder; /* 0FD4 */ uint32_t m_manaRegenInterruptTime; - /* 0FD8 */ uint32_t unk_0FD8 [2]; + /* 0FD8 */ WOWGUID m_highestThreatGuid; /* 0FE0 */ TSHashTable m_threats; virtual void GetAFKText(char* buffer, uint32_t size) const; @@ -444,6 +457,8 @@ class CGUnit_C : public CGObject_C, public CGUnit { void StopUpdatingMissileTrajectory(int32_t spellId); int32_t IsUpdatingMissileTrajectory() const; int32_t IsMissileTrajectoryUpdateWaitingForMissileRelease() const; + void SendFinalMissileTrajectoryUpdate(); + int32_t OverrideMissileFirePos(C3Vector* position, const SpellRec* spell); bool IsLocalClientControlled() const; void FreeComponent(); uint32_t GetCombatReadyAnim() const; @@ -470,6 +485,8 @@ class CGUnit_C : public CGObject_C, public CGUnit { bool IsTreatAsRaidUnit() const; bool IsForceGossip() const; bool CanInteractWhileDead() const; + bool CanInteract(const CGGameObject_C* gameObject) const; + void OnFlagChangedActivePlayer(uint32_t oldFlags, uint32_t changed); uint32_t GetSkinningType() const; void GetCursorFile(int32_t unable, char* buffer, uint32_t size) const; bool MountedCombatAllowed() const; @@ -582,7 +599,6 @@ class CGUnit_C : public CGObject_C, public CGUnit { int32_t ChooseFallAnim(uint32_t* anim) const; void SaveChainSpellTargets(const TSStackArray& targets); bool HasAuraBySpellId(int32_t spellId); - bool AffectedByAura(int32_t auraType, const SpellRec* spell); bool HasAuraActive(int32_t spellId); int32_t GetAuraIndex(int32_t spellId); bool IsVehiclePreventingTurning() const; @@ -639,7 +655,6 @@ class CGUnit_C : public CGObject_C, public CGUnit { bool CanBeSpellClickedByLocalPlayer(const CGPlayer_C* player) const; bool CanInteractNow(const CGUnit_C* unit) const; bool CanAutoStand() const; - int32_t VerifyAttackIconPressed(const WOWGUID& target, int32_t a3, int32_t a4, int32_t a5, bool a6); void SetTrackingDirection(const C3Vector& direction); void MoveEventHappened(uint32_t msgId); void HandlePendingTrackEvents(); @@ -660,6 +675,13 @@ class CGUnit_C : public CGObject_C, public CGUnit { int32_t Unk71AE80() const; bool ShouldKneelForLoot() const; void SetVehicleExitVoluntary(int32_t enable); + void VehicleExit(); + bool HasDispellableAura(int32_t dispelType, int32_t harmful, bool mechanic, bool steal); + void CheckVehicleExitOnCast(); + uint8_t GetActivePlayerFieldBytes0(); + bool GetSpellRequiredLevel(int32_t spellId, int32_t* level); + bool CheckAndReportSpellInhibitFlags(PendingSpellCast* cast, const SpellRec* spell, const CGItem_C* item); + void CancelShapeshiftForMount(); void OnDismissControlledVehicleLocal(uint32_t eventTime); void SetEmoteQueue(const QUESTGIVEREMOTENODE* nodes, uint32_t count); void PlayEmotes(const QUESTGIVEREMOTEQUEUE& emotes); @@ -700,16 +722,24 @@ class CGUnit_C : public CGObject_C, public CGUnit { bool IgnoresAuraState(const SpellRec* spell) const; bool CheckStealthRules(const SpellRec* spell, int32_t* reason) const; bool CheckShapeshiftRules(const SpellRec* spell, int32_t* reason); - bool CanAutoCancelShapeshift() const; bool AffectedByAura(int32_t auraType, const SpellRec* spell) const; - bool HasAura(int32_t spellId) const; bool IsInMyPartyOrRaid(const CGUnit_C* unit) const; bool IsInMyParty(const CGUnit_C* unit) const; static uint8_t GetThreatSituation(const WOWGUID& guid); - bool CalculateThreat(const WOWGUID& guid, uint8_t* status, float* rawPercent, float* percent, int32_t* threat); + bool CalculateThreat(const WOWGUID& guid, uint8_t* status, uint8_t* rawPercent, float* percent, int32_t* threat); + UnitThreat* CreateThreatEntry(const WOWGUID& guid); + void UpdateThreat(CDataStore* msg, bool highest); + bool UpdateThreatEntry(UnitThreat* entry, int32_t highestThreat, bool activePlayer); + void UpdateThreatStatus(); + void RemoveThreat(const WOWGUID& guid); + void AddWorldThreatUpdateText(int32_t oldStatus, int32_t newStatus); + void OnAiReaction(int32_t reaction); + void DoPowerRegen(int32_t powerType, uint32_t elapsed); + void DoPowerRegen(uint32_t elapsed); char* GetUnitChosenTitle(char* buffer, uint32_t size, int32_t showTitle, int32_t* lines); void RequestTalkEmote(int32_t index); void ChatBubbleShow(int32_t type, const char* text); + void ChatBubbleRemove(); void PlayTextEmoteSound(uint32_t emote, uint32_t emoteNum); SkillLineAbilityRec* LookupAbility(int32_t spellId); void SignalPlayerGainsVehicleDataEvent(); @@ -728,7 +758,9 @@ class CGUnit_C : public CGObject_C, public CGUnit { void OnVehicleCameraPossiblyUnneeded(); void UpdateUnitCollisionBox(int32_t a2, int32_t a3); void CreateUnitMount(int32_t a2, int32_t a3); - void Unk717BA0(); + void ShowLootEffect(); + void CompleteMountTransition(); + void RefreshComponentItem(int32_t itemSlot); void UpdateReaction(bool a1); void ApplyModelFade(); void ComputeSmoothedSwimMatrix(C44Matrix* matrix, float elapsed, int32_t a3); @@ -757,6 +789,7 @@ class CGUnit_C : public CGObject_C, public CGUnit { void OnFlag2Changed(uint32_t oldFlags); void OnFlagChanged(uint32_t oldFlags); void OnLevelChange(); + void AddWorldXPGainText(int32_t amount); void OnLife(bool a1); void OnMountDisplayChanged(int32_t displayId); void OnPvPFlagChanged(uint8_t oldFlags); @@ -816,6 +849,8 @@ class CGUnit_C : public CGObject_C, public CGUnit { void UpdateObjectEffectMovementStates(); void DestroyUnitMount(int32_t a2); void OnDeathAnimate(); + void ReadLootList(CDataStore* msg); + void RemoveLootEffect(); void Unk71EE70(); void ClearTrackingTarget(bool a2, bool a3); void HandleTracking(float drunkness, float turnOffset); @@ -846,6 +881,7 @@ class CGUnit_C : public CGObject_C, public CGUnit { int32_t VehiclePassengerStartWaitingForVehicleTransitionAnim(uint64_t transport, uint8_t seat); void ClearAttackRound(); void SetUICastingSpell(int32_t spellId, const WOWGUID& target, int32_t castTime); + void SetUIChannelSpell(int32_t spellId, int32_t duration); bool SetTrackingTarget(const WOWGUID& target, int32_t type); void ClearCastingSpell(int32_t spellId, bool clearChannel, bool a4); void ApplySpellVisualTrail(const SpellVisualRec* visual, int32_t a3); @@ -853,7 +889,27 @@ class CGUnit_C : public CGObject_C, public CGUnit { void ResetUICastingSpell(); void OnKeyBoneAnimEnd(CM2Model* model, uint32_t boneId, uint32_t sequenceId); int32_t OnAttackIconPressed(WOWGUID target, int32_t a3); + int32_t VerifyAttackIconPressed(WOWGUID* target, int32_t useGiven, int32_t checkRange, bool autoTarget, bool showErrors); void AddAuraSlot(uint8_t slot); + void SortAuras(); + void ReleaseAurasBySpell(int32_t spellId); + void PlayParryAnimation(); + void HandleAnimEvent(uint32_t boneId, uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time); + void HandleCombatAnimEvent(uint32_t eventId, uint32_t data, const C3Vector* position, uint32_t time); + void FootstepAnimEventHit(const C3Vector* position, int32_t left); + void PlayEmoteSound(int32_t soundKitId, bool checkCVars, int32_t fileIndex); + void PlayRangedItemPull(); + void ShakeCameraOnHit(); + void TriggerDamageFeedback(); + void CreateProceduralEffect(const SpellRec* spell, const SpellVisualRec* visual, const SpellVisualKitRec* kit, int32_t a4, uint32_t flags, WOWGUID guid); + void PlaySpellVisualKit_PlayAnims(const SpellRec* spell, const SpellVisualKitRec* kit, SPELL_VISUAL_KIT_TYPE type, const C3Vector* position, int32_t a5, int32_t a6, WOWGUID guid, uint32_t a8, const SpellVisualRec* visual, uint32_t a10, int32_t a11) override; + void PlaySpellVisualKit_HandleWeapons(const SpellRec* spell, const SpellVisualKitRec* kit, const C3Vector* position, WOWGUID guid, uint32_t a5, uint32_t flags, void (*callback)(CM2Model*, uint32_t, uint32_t, int32_t, uint32_t, uint64_t), int32_t* hasEffect) override; + int32_t PlaySpellVisualKit_DelayLightningEffects(const SpellRec* spell, const SpellVisualKitRec* kit, SPELL_VISUAL_KIT_TYPE type, const C3Vector* position, WOWGUID guid, int32_t a6, int32_t a7, int32_t a8, int32_t a9, uint32_t a10, const SpellVisualRec* visual) override; + void HandleSpellEventSound(); + int32_t IsHostileCritter(); + float GetSpellChanceToCrit() const; + void InsertSortedAura(uint32_t list, uint32_t auraIndex, int32_t position); + uint32_t GetSortedAuraSlot(int32_t index, const char* name, const char* rank, uint32_t filter); void AddAuraEffect(uint32_t index, const SpellRec* spell); void RemoveAuraEffect(uint32_t index, const SpellRec* spell); void OnAuraAdded(uint32_t index, uint8_t a3, AuraData* aura, int32_t spellId); @@ -874,8 +930,13 @@ class CGUnit_C : public CGObject_C, public CGUnit { void ShowBloodSpurt(const WOWGUID& attacker, int32_t a3); void ModifyPredictedPower(int32_t powerType, int32_t delta); void AddWorldText(const WOWGUID& source, int32_t reason, const SpellRec* spell, bool periodic); + void AddWorldHealingText(const WOWGUID& source, int32_t amount, const SpellRec* spell, bool crit, int32_t a6); void PlayCombatSpellMissEffects(uint32_t reason, const WOWGUID& source); - void CreateMissile(const TSStackArray& points, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, const SpellVisualRec* visual, int32_t spellId, uint32_t delay); + void CreateMissile(const SpellCastTargetPoint* point, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, const SpellVisualRec* visual, int32_t spellId, uint32_t delay); + void CreateMissile(const TSStackArray* points, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, const SpellVisualRec* visual, int32_t spellId, uint32_t delay); + CM2Model* CreateItemModel(uint32_t displayId, uint32_t inventoryType, float* scale); + CM2Model* CreateItemModel(uint32_t hand, float* scale); + void CreateMissile(const WOWGUID* target, PendingSpellCastData* data, uint32_t ammoDisplayId, uint32_t ammoInventoryType, int32_t hit, uint32_t missReason, uint32_t reflectResult, const SpellVisualRec* visual, int32_t spellId, const TSStackArray* targets, const TSStackArray* missReasons, const TSStackArray* reflectResults, uint32_t delay); void OnAuraUpdate(CDataStore* msg, bool updateAll); void OnAttackStop(uint64_t target, int32_t faceTarget); void PlayAttackerRound(const ATTACKROUNDINFO& info); @@ -887,6 +948,10 @@ class CGUnit_C : public CGObject_C, public CGUnit { int32_t VehiclePassengerShouldWaitForVehicleTransitionAnim(uint64_t transport, uint8_t seat) const; void AddWorldDamageText(const WOWGUID& source, int32_t amount, const SpellRec* spell, bool crit, bool periodic, bool spellColor); void UpdateSpellCastBars(uint32_t time); + void DelayCast(int32_t delay); + void SetUICastingDirect(int32_t spellId, const WOWGUID& target, uint32_t start, uint32_t end); + void SetUIChannelDirect(int32_t spellId, uint32_t start, uint32_t end); + void UpdateChainTargets(const TSStackArray& targets, int32_t spellId); void FillPartyMemberPetState(CGPartyPetState* state); void Unk71AEE0(uint32_t time); }; @@ -1014,5 +1079,6 @@ void WeaponTrailsInitialize(); void WeaponTrailsShutdown(); const char* GetObjectNameFromGuid(const WOWGUID& guid); +void WriteMovementPacket(CGUnit_C* unit, uint32_t msgId, CDataStore* msg, int32_t include); #endif diff --git a/WoW/Source/Object/ObjectClient/VehiclePassenger_C.cpp b/WoW/Source/Object/ObjectClient/VehiclePassenger_C.cpp index 6b41382..9cafbcd 100644 --- a/WoW/Source/Object/ObjectClient/VehiclePassenger_C.cpp +++ b/WoW/Source/Object/ObjectClient/VehiclePassenger_C.cpp @@ -13,6 +13,7 @@ #include "Engine/Source/Tempest/C44Matrix.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/Types.h" +#include "WoW/Source/UIUtil/InputControl.h" // STATIC: 0x00CA135C uint32_t* CVehiclePassenger_C::s_passengerPool; @@ -835,3 +836,16 @@ void CVehiclePassenger_C::ExecuteAllDeferredVehicleTransitionAnimSplines() { delete spline; } } + +// VERIFY: 2c6b93a8 auto +// OFFSET: 0x00747FA0 +void CVehiclePassenger_C::StopMovement() { + if (this->m_state != 3 || this->m_unit->m_obj->m_guid != ClntObjMgrGetActivePlayer()) { + return; + } + + uint32_t time = FrameTime::s_curTimeMs; + CGInputControl::GetActive()->StopMovementAndTurning(time); + this->m_flags |= 0x8; + this->unk_004C[0] = time; +} diff --git a/WoW/Source/Object/ObjectClient/VehiclePassenger_C.h b/WoW/Source/Object/ObjectClient/VehiclePassenger_C.h index 6776c11..a2de52e 100644 --- a/WoW/Source/Object/ObjectClient/VehiclePassenger_C.h +++ b/WoW/Source/Object/ObjectClient/VehiclePassenger_C.h @@ -42,6 +42,8 @@ class CVehiclePassenger_C { static CVehiclePassenger_C* Alloc(CGUnit_C* unit); static void Init(CGUnit_C* unit); + void StopMovement(); + /* 0000 */ uint32_t m_memHandle; /* 0004 */ CVehiclePassenger_C* m_prev; /* 0008 */ CVehiclePassenger_C* m_next; diff --git a/WoW/Source/Object/ObjectClient/Vehicle_C.cpp b/WoW/Source/Object/ObjectClient/Vehicle_C.cpp index 8933701..545e5a1 100644 --- a/WoW/Source/Object/ObjectClient/Vehicle_C.cpp +++ b/WoW/Source/Object/ObjectClient/Vehicle_C.cpp @@ -571,3 +571,49 @@ int32_t CVehicle_C::CanPlayBoneAnim(uint32_t animId) const { return animId <= 0x1F9; } + +// VERIFY: 86ddcfee manual +// OFFSET: 0x00757060 +void CVehicle_C::HandleBoneAnimGrabEvent(uint32_t boneId, uint32_t eventId) { + if (boneId >= 35) { + boneId = 26; + } + + for (uint32_t i = 0; i < 16; i++) { + BoneAnimListener& listener = this->m_boneAnimListeners[i]; + + if (!listener.m_guid || listener.m_boneId != boneId) { + continue; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(listener.m_guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && unit->m_vehiclePassenger && unit->m_vehiclePassenger->IsWaitingForVehicleTransitionAnimGrabEvent(eventId)) { + unit->m_vehiclePassenger->StopWaitingForVehicleTransitionAnim(); + listener.m_guid = WOWGUID(); + } + } +} + +// VERIFY: b18617fe manual +// OFFSET: 0x007570F0 +void CVehicle_C::HandleBoneAnimThrowEvent(uint32_t boneId, uint32_t eventId) { + if (boneId >= 35) { + boneId = 26; + } + + for (uint32_t i = 0; i < 16; i++) { + BoneAnimListener& listener = this->m_boneAnimListeners[i]; + + if (!listener.m_guid || listener.m_boneId != boneId) { + continue; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(listener.m_guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && unit->m_vehiclePassenger && unit->m_vehiclePassenger->IsWaitingForVehicleTransitionAnimThrowEvent(eventId)) { + unit->m_vehiclePassenger->StopWaitingForVehicleTransitionAnim(); + listener.m_guid = WOWGUID(); + } + } +} diff --git a/WoW/Source/Object/ObjectClient/Vehicle_C.h b/WoW/Source/Object/ObjectClient/Vehicle_C.h index 8a73058..122b404 100644 --- a/WoW/Source/Object/ObjectClient/Vehicle_C.h +++ b/WoW/Source/Object/ObjectClient/Vehicle_C.h @@ -84,6 +84,8 @@ class CVehicle_C { CVehicle_C* FindVehicleToPlayBoneAnim(); void StartMirroringAnimsToPassengers(); int32_t PlayBoneAnim(uint32_t boneId, uint32_t animId); + void HandleBoneAnimGrabEvent(uint32_t boneId, uint32_t eventId); + void HandleBoneAnimThrowEvent(uint32_t boneId, uint32_t eventId); void RemoveAllPassengersLocally(); }; diff --git a/WoW/Source/Object/Player.cpp b/WoW/Source/Object/Player.cpp index 3eddc90..e17636b 100644 --- a/WoW/Source/Object/Player.cpp +++ b/WoW/Source/Object/Player.cpp @@ -161,6 +161,12 @@ bool CGPlayer::HasPvpMedal(uint8_t medal) { return (this->m_player->m_playerFieldPvpMedals & (1 << (medal - 1))) != 0; } +// VERIFY: 28e0d613 manual +// OFFSET: 0x004F72E0 +bool CGPlayer::HasAuraVision(uint8_t vision) { + return (reinterpret_cast(&this->m_player->m_playerFieldBytes2)[3] & (1 << (vision - 1))) != 0; +} + // VERIFY: d70d997f manual // OFFSET: 0x005E0870 PlayerQuestLogEntry* CGPlayer::GetQuestLogEntry(uint32_t slot) { diff --git a/WoW/Source/Object/Player.h b/WoW/Source/Object/Player.h index 7806e26..1347a68 100644 --- a/WoW/Source/Object/Player.h +++ b/WoW/Source/Object/Player.h @@ -29,6 +29,7 @@ class CGPlayer { PlayerQuestLogEntry* GetQuestLogEntry(uint32_t slot); uint32_t GetBuybackPrice(uint32_t slot); bool HasPvpMedal(uint8_t medal); + bool HasAuraVision(uint8_t vision); static const uint32_t s_mirrorFields[173]; static const uint32_t s_localMirrorFields[870]; diff --git a/WoW/Source/Object/Unit.cpp b/WoW/Source/Object/Unit.cpp index e53cc50..efbffe6 100644 --- a/WoW/Source/Object/Unit.cpp +++ b/WoW/Source/Object/Unit.cpp @@ -285,3 +285,10 @@ int32_t CGUnit::GetQuestGreenRange() const { uint32_t band = static_cast(this->m_unit->m_unitFieldLevel) / 5; return band < 20 ? s_questGreenRange[band] : 8; } + +// VERIFY: 467ea880 manual +// OFFSET: 0x00716190 +bool CGUnit::IsSitting() const { + uint8_t standState = this->m_unit->m_unitFieldBytes1[0]; + return standState == 1 || (standState >= 4 && standState <= 6); +} diff --git a/WoW/Source/Object/Unit.h b/WoW/Source/Object/Unit.h index 8efc686..7442b62 100644 --- a/WoW/Source/Object/Unit.h +++ b/WoW/Source/Object/Unit.h @@ -30,6 +30,7 @@ class CGUnit { bool HasSummoner() const; bool IsPossessedBy(const WOWGUID& guid) const; bool IsCharmed() const; + bool IsSitting() const; bool IsGuildMaster() const; int32_t GetSpellCostModifier(int32_t schoolMask) const; float GetSpellCostMultiplier(int32_t schoolMask) const; diff --git a/WoW/Source/SoundInterface/SoundInterface2.cpp b/WoW/Source/SoundInterface/SoundInterface2.cpp index b288b0b..e6991d4 100644 --- a/WoW/Source/SoundInterface/SoundInterface2.cpp +++ b/WoW/Source/SoundInterface/SoundInterface2.cpp @@ -19,6 +19,9 @@ #include "WoW/Source/SoundInterface/SoundInterface2ZoneSounds.h" #include "WoW/Source/Ui/ChatFrame.h" #include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/DB/Rec/ResistancesRec.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Object/ObjectClient/Object_C.h" // STATIC: 0x009F2010 const char SI2::s_channelGroupNames[18][32] = { @@ -1362,3 +1365,31 @@ int32_t SI2::Init(int32_t restart) { return 0; } + +// VERIFY: db4e7763 manual +// OFFSET: 0x004CFF30 +void SI2::PlaySpellFizzleSound(uint32_t spellId, const void* object) { + if (!object) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + for (int32_t i = 0; i < 7; i++) { + if (!((1 << i) & spell.m_schoolMask)) { + continue; + } + + ResistancesRec* resistance = g_resistancesDB.GetRecord(i); + + if (resistance) { + C3Vector position = static_cast(object)->GetPosition(); + SI2::PlaySoundKit(resistance->m_fizzleSoundID, &position, nullptr, nullptr, 0, nullptr, 1, 0); + return; + } + } +} diff --git a/WoW/Source/UIUtil/Camera.cpp b/WoW/Source/UIUtil/Camera.cpp index a6df5d9..3ec75d3 100644 --- a/WoW/Source/UIUtil/Camera.cpp +++ b/WoW/Source/UIUtil/Camera.cpp @@ -4150,3 +4150,14 @@ void CGCamera::CalcModelCamera(uint32_t time) { DataMgrGetCoord(reinterpret_cast(this->unk_0050), 8, &target); this->SetPositionAndTargetWithRoll(position, target, CameraGetFloat(reinterpret_cast(this->unk_0050), 5)); } + +// VERIFY: 399367f6 auto +// OFFSET: 0x006038A0 +void CGCamera::CommentatorSetViewAndPosition(const C3Vector& position, float facing, float pitch) { + this->m_views[6][0] = 0.0f; + this->m_views[6][2] = facing; + this->m_views[6][1] = pitch; + this->m_position = position; + this->m_position = position; + this->SetView(6, 2, 0); +} diff --git a/WoW/Source/UIUtil/Camera.h b/WoW/Source/UIUtil/Camera.h index 1501430..ae31672 100644 --- a/WoW/Source/UIUtil/Camera.h +++ b/WoW/Source/UIUtil/Camera.h @@ -76,6 +76,7 @@ class CGCamera : public CSimpleCamera { static float GetDefaultZoomMaxDistance(); static void __stdcall AddShakeOffset(C3Vector& offset, float facing, float amplitude, float time, float frequency, int32_t type, float damping, int32_t dir); void SetPositionAndTargetWithRoll(const C3Vector& position, const C3Vector& target, float roll); + void CommentatorSetViewAndPosition(const C3Vector& position, float facing, float pitch); int32_t FinishLoadingModel(); /* 0048 */ CM2Model* m_model; @@ -164,6 +165,7 @@ class CGCamera : public CSimpleCamera { CGCamera(); ~CGCamera(); void AddShake(const C3Vector& position, int32_t type, int32_t dir, float amplitude, float frequency, float duration, float timeOffset, float damping); + void AddShakeById(int32_t shakeId, const C3Vector* position); void BeginBobbingSmooth(); void CalcTerrainTilt(CGObject_C* target, uint32_t time); void CameraTeleported(float facing); diff --git a/WoW/Source/UIUtil/Cursor.cpp b/WoW/Source/UIUtil/Cursor.cpp index 8def6d4..14ae05b 100644 --- a/WoW/Source/UIUtil/Cursor.cpp +++ b/WoW/Source/UIUtil/Cursor.cpp @@ -278,3 +278,25 @@ void CursorResetMode() { FrameScript_SignalEvent(SCRIPT_EVENT_CURSOR_UPDATE, nullptr); } } + +// VERIFY: 27d3e602 manual +// OFFSET: 0x006164B0 +void CursorReleaseItemMips() { + MipBits* mips = s_cursorItemMips; + + if (!mips) { + return; + } + + if (s_cursorItemType) { + CopyCursorImage(s_cursorItem, mips, s_cursorItemMipsWidth, s_cursorItemMipsHeight); + TextureFreeMippedImg(mips); + } else { + TextureFreeMippedImg(s_cursorItemMips); + } + + s_cursorItemMipsHeight = 0; + s_cursorItemMipsWidth = 0; + s_cursorItemMips = nullptr; + UpdateCursor(); +} diff --git a/WoW/Source/UIUtil/PortraitButton.cpp b/WoW/Source/UIUtil/PortraitButton.cpp index 8a93f98..a59dcfa 100644 --- a/WoW/Source/UIUtil/PortraitButton.cpp +++ b/WoW/Source/UIUtil/PortraitButton.cpp @@ -6,6 +6,12 @@ #include "WoW/Source/Ui/ScriptEvents.h" #include "Engine/Source/Base/Status.h" #include "Engine/Source/Services/Texture.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/Types.h" +#include "Engine/Source/Model2/M2Model.h" +#include "WoW/Common/ComponentCore/CharacterComponent.h" // STATIC: 0x00C5CDF0 static CTexture* s_portraitMaskTexture; @@ -31,6 +37,12 @@ static TSHashTable unk_C5CE08; // STATIC: 0x00C5CE30 static TSHashTable unk_C5CE30; +// STATIC: 0x00AD28E4 +static TSList> s_pendingPortraits; + +// STATIC: 0x00AD28F0 +static TSList> s_freePortraits; + static void PortraitDepthTextureCallback(EGxTexCommand command, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevel, void* userArg, uint32_t& texelStrideInBytes, const void*& texels) { } @@ -103,3 +115,81 @@ void PortraitInitialize() { unk_C5CE00 = 0; unk_C5CE04 = 0; } + +// VERIFY: 59c574b9 auto +// OFFSET: 0x00616B40 +static int32_t IsPortraitDrawable(CGUnit_C* unit) { + if (unit->m_clientFlags & 0x400000) { + return 0; + } + + if (unit->m_characterComponent && (!unit->m_characterComponent->RenderPrep(0) || (unit->m_characterComponent->m_flags & 4))) { + return 0; + } + + if (!unit->m_worldModel) { + return 0; + } + + return unit->m_worldModel->IsDrawable(0, 1); +} + +// VERIFY: 66b97025 manual +// OFFSET: 0x00616E80 +void UpdatePendingPortraits() { + if (!g_theGxDevicePtr || !g_theGxDevicePtr->CapsIsWindowVisible(-1) || !g_theGxDevicePtr || !g_theGxDevicePtr->CapsHasContext(-1)) { + return; + } + + PORTRAITREQUEST* next; + + for (PORTRAITREQUEST* request = s_pendingPortraits.Head(); !s_pendingPortraits.IsEnd(request); request = next) { + next = s_pendingPortraits.RawNext(request); + WOWGUID guid = request->m_guid; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + s_freePortraits.LinkToTail(request); + continue; + } + + if ((unit->m_clientFlags & 0x400000) && !unit->InitializeComponent()) { + continue; + } + + if (!IsPortraitDrawable(unit)) { + continue; + } + + uint32_t flags = request->m_flags; + s_freePortraits.LinkToTail(request); + + if (flags & 2) { + Script_SendUnitSignal(guid, SCRIPT_EVENT_UNIT_PORTRAIT_UPDATE); + } + + if (flags & 1) { + Script_SendUnitSignal(guid, SCRIPT_EVENT_UNIT_MODEL_CHANGED); + } + } +} + +// VERIFY: 90c0e005 auto +// OFFSET: 0x00618110 +void UpdateModelForUI(const WOWGUID& guid, uint32_t flags) { + if (flags & 2) { + PLAYERPORTRAIT* portrait = unk_C5CE08.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (portrait) { + portrait->unk_0020 = 1; + } + } + + if (flags & 2) { + Script_SendUniqueSignal(guid, SCRIPT_EVENT_UNIT_PORTRAIT_UPDATE); + } + + if (flags & 1) { + Script_SendUniqueSignal(guid, SCRIPT_EVENT_UNIT_MODEL_CHANGED); + } +} diff --git a/WoW/Source/UIUtil/PortraitButton.h b/WoW/Source/UIUtil/PortraitButton.h index fb77962..1e91138 100644 --- a/WoW/Source/UIUtil/PortraitButton.h +++ b/WoW/Source/UIUtil/PortraitButton.h @@ -14,6 +14,11 @@ struct PLAYERPORTRAIT : public TSHashObject { /* 0024 */ CTexture* unk_0024; }; +struct PORTRAITREQUEST : public TSLinkedNode { + /* 0008 */ WOWGUID m_guid; + /* 0010 */ uint32_t m_flags; +}; + struct UNITPORTRAIT : public TSHashObject { /* 0018 */ uint8_t unk_0018; /* 0019 */ uint8_t unk_0019[3]; diff --git a/WoW/Source/UIUtil/Tooltip.cpp b/WoW/Source/UIUtil/Tooltip.cpp index 5725da7..89531db 100644 --- a/WoW/Source/UIUtil/Tooltip.cpp +++ b/WoW/Source/UIUtil/Tooltip.cpp @@ -96,10 +96,20 @@ #include "WoW/Source/Ui/ItemSocketInfo.h" #include "WoW/Source/Ui/LootFrame.h" #include "WoW/Source/UIUtil/Cursor.h" +#include "WoW/Source/DB/Rec/GlyphSlotRec.h" +#include "WoW/Source/Ui/UIMacros.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "Engine/Source/Os/TimeManager.h" // STATIC: 0x00AD2AAC static const char* s_spellLinkColorString = "|cff71d5ff"; +// STATIC: 0x00AD2AA4 +static const char* s_glyphLinkColorString = "|cff66bbff"; + +// STATIC: 0x00AD2AB0 +static const char* s_talentLinkColorString = "|cff4e96f7"; + // STATIC: 0x00C5CF4C int32_t CGTooltip::s_objectType; @@ -113,7 +123,7 @@ static const char* s_itemQualityColorStrings[8] = { "|cff9d9d9d", "|cffffffff", uint32_t s_tooltipTitleColor = 0xFFFFD200; // STATIC: 0x00AD2D30 -static uint32_t s_tooltipTextColor = 0xFFFFFFFF; +uint32_t s_tooltipTextColor = 0xFFFFFFFF; // STATIC: 0x00AD2D34 static uint32_t s_tooltipRedColor = 0xFFFF2020; @@ -568,7 +578,7 @@ void CGTooltip::OnLayerUpdate(float elapsedSec) { } } -// VERIFY: 85be993a manual +// VERIFY: e3ff3caf manual // OFFSET: 0x0061C620 void CGTooltip::ClearTooltip() { if (this->m_healthGuid != WOWGUID()) { @@ -593,7 +603,7 @@ void CGTooltip::ClearTooltip() { this->m_spellId = 0; this->unk_0368 = 0; this->unk_036C = 0; - this->unk_0370 = 0; + this->m_nextRankSpellId = 0; for (uint32_t i = 0; i < this->m_numTextures; i++) { uint32_t line = this->m_textureLines[i]; @@ -778,7 +788,7 @@ int32_t CGTooltip::ShowThis() { return CSimpleFrame::ShowThis(); } -// VERIFY: 306254b7 manual +// VERIFY: c76e7f35 manual // OFFSET: 0x0061DEE0 CGTooltip::CGTooltip(CSimpleFrame* parent) : CSimpleFrame(parent) { this->m_itemLinkInfo.Clear(); @@ -803,7 +813,7 @@ CGTooltip::CGTooltip(CSimpleFrame* parent) : CSimpleFrame(parent) { this->m_spellId = 0; this->unk_0368 = 0; this->unk_036C = 0; - this->unk_0370 = 0; + this->m_nextRankSpellId = 0; this->m_itemNameOnly = 0; this->m_itemSocketPreview = 0; this->m_itemCompare = 0; @@ -1816,7 +1826,7 @@ void TooltipSpellCallback(int32_t id, const WOWGUID& guid, void* param, bool suc } } -// VERIFY: cfbc31fa manual +// VERIFY: 73537865 manual // OFFSET: 0x006224F0 int32_t CGTooltip::AddTalentPrereqs(const TalentRec* talent, CGTalentGroup_C* group, int32_t isInspect, int32_t isPet, int32_t usePreview) { const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); @@ -1842,7 +1852,7 @@ int32_t CGTooltip::AddTalentPrereqs(const TalentRec* talent, CGTalentGroup_C* gr } int32_t rank = talent->m_prereqRank[i]; - CGTalentItem* item; + TalentGroupItem_C* item; if (group && (item = group->GetTalentItem(prereqId)) && (usePreview ? item->m_previewRank : item->m_rank) >= rank) { continue; @@ -1869,7 +1879,7 @@ int32_t CGTooltip::AddTalentPrereqs(const TalentRec* talent, CGTalentGroup_C* gr TalentTabRec* tab = g_talentTabDB.GetRecord(talent->m_tabID); if (tab) { - TalentGroupTab* groupTab = group->GetTabFromID(talent->m_tabID); + TalentGroupTab_C* groupTab = group->GetTabFromID(talent->m_tabID); uint32_t spent = groupTab ? groupTab->m_pointsSpent + groupTab->m_previewPointsSpent : 0; if (spent < static_cast(talent->m_tierID * (2 * (isPet == 0) + 3))) { @@ -5869,3 +5879,280 @@ const char* CGTooltip::GetSpellLink(int32_t spellId) { SStrPrintf(s_itemLink, sizeof(s_itemLink), "%s|Hspell:%d|h[%s]|h%s", s_spellLinkColorString, spellId, spell.m_name, *s_spellLinkColorString ? "|r" : ""); return s_itemLink; } + +// VERIFY: 83eb3194 auto +// OFFSET: 0x0061A550 +const char* CGTooltip::GetTalentHyperlinkString(const TalentRec* talent, const char* name, int32_t rank) { + if (!talent || !name) { + return ""; + } + + SStrPrintf(s_itemLink, sizeof(s_itemLink), "%s|Htalent:%d:%d|h[%s]|h%s", s_talentLinkColorString, talent->m_id, rank, name, *s_talentLinkColorString ? "|r" : ""); + return s_itemLink; +} + +// VERIFY: 884f5bd4 auto +// OFFSET: 0x0061E650 +const char* CGTooltip::GetGlyphLink(int32_t slotId, int32_t glyphId) { + GlyphSlotRec* slot = g_glyphSlotDB.GetRecord(slotId); + GlyphPropertiesRec* glyph = g_glyphPropertiesDB.GetRecord(glyphId); + + if (!slot || !glyph) { + return ""; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(glyph->m_spellID, &spell)) { + return ""; + } + + SStrPrintf(s_itemLink, sizeof(s_itemLink), "%s|Hglyph:%d:%d|h[%s]|h%s", s_glyphLinkColorString, slotId, glyphId, spell.m_name, *s_glyphLinkColorString ? "|r" : ""); + return s_itemLink; +} + +// VERIFY: ed6fe309 manual +// OFFSET: 0x00622BA0 +void CGTooltip::SetGlyph(int32_t slotId, int32_t glyphId, int32_t enabled, int32_t hideRemove, int32_t parseUnit) { + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& grayColor = *reinterpret_cast(&s_skillColors[0]); + const CImVector& redColor = *reinterpret_cast(&s_tooltipBrightRedColor); + const CImVector& glyphColor = *reinterpret_cast(&s_tooltipGlyphColor); + char text[1024]; + + this->ClearTooltip(); + GlyphSlotRec* slot = g_glyphSlotDB.GetRecord(slotId); + GlyphPropertiesRec* glyph = g_glyphPropertiesDB.GetRecord(glyphId); + SpellRec spell; + int32_t found = 0; + + if (glyph) { + found = g_spellDB.GetRecord(glyph->m_spellID, &spell); + + if (found) { + this->AddLine(spell.m_name, nullptr, textColor, textColor, 0); + } + } else if (enabled) { + this->AddLine(FrameScript_GetText("GLYPH_INACTIVE", -1, GENDER_NOT_APPLICABLE), nullptr, grayColor, grayColor, 0); + } else { + this->AddLine(FrameScript_GetText("GLYPH_LOCKED", -1, GENDER_NOT_APPLICABLE), nullptr, redColor, redColor, 0); + } + + if (slot && slot->m_type) { + this->AddLine(FrameScript_GetText("MINOR_GLYPH", -1, GENDER_NOT_APPLICABLE), nullptr, glyphColor, glyphColor, 0); + } else { + this->AddLine(FrameScript_GetText("MAJOR_GLYPH", -1, GENDER_NOT_APPLICABLE), nullptr, glyphColor, glyphColor, 0); + } + + if (!found) { + if (enabled) { + this->AddLine(FrameScript_GetText("GLYPH_EMPTY_DESC", -1, GENDER_NOT_APPLICABLE), nullptr, titleColor, titleColor, 1); + } else if (slot) { + SStrPrintf(text, sizeof(text), "GLYPH_SLOT_TOOLTIP%d", slot->m_tooltip); + this->AddLine(FrameScript_GetText(text, -1, GENDER_NOT_APPLICABLE), nullptr, titleColor, titleColor, 1); + } + } else if (spell.m_description && *spell.m_description) { + SpellParserParseText(&spell, text, sizeof(text), 0, parseUnit, 0, 0, 1, 0); + this->AddLine(text, nullptr, titleColor, titleColor, 1); + + if (!hideRemove) { + this->AddLine(FrameScript_GetText("GLYPH_SLOT_REMOVE_TOOLTIP", -1, GENDER_NOT_APPLICABLE), nullptr, grayColor, grayColor, 0); + } + } + + this->Show(); +} + +// VERIFY: a6d7c47a manual +// OFFSET: 0x00626E20 +void CGTooltip::SetTalent(const TalentRec* talent, CGTalentGroup_C* group, int32_t isInspect, int32_t useRank, int32_t rank, int32_t isPet, int32_t usePreview) { + if (!talent) { + this->Hide(); + return; + } + + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + int32_t displayRank = -1; + int32_t currentRank = -1; + int32_t maxRank = -1; + + for (int32_t i = 8; i >= 0; i--) { + if (talent->m_spellRank[i]) { + maxRank = i; + break; + } + } + + if (useRank && rank >= 0 && rank <= maxRank) { + currentRank = rank; + } else if (group) { + TalentGroupItem_C* item = group->GetTalentItem(talent->m_id); + + if (item) { + displayRank = item->m_previewRank; + currentRank = item->m_rank; + } + } + + if (!usePreview) { + displayRank = currentRank; + } + + if (talent->m_flags & 1) { + int32_t showNext = maxRank > 0 && displayRank >= 0 && displayRank < maxRank; + this->SetSpell(talent->m_spellRank[displayRank < 0 ? 0 : displayRank], 0, 0, isPet, 0, isInspect, useRank, talent, group, 0, usePreview, displayRank < 0 ? 0 : displayRank, displayRank, maxRank, !showNext); + + if (showNext) { + this->SetSpell(talent->m_spellRank[displayRank + 1], 0, 0, isPet, 0, isInspect, useRank, talent, group, 1, usePreview, displayRank + 1, displayRank, maxRank, 1); + } + + return; + } + + this->ClearTooltip(); + int32_t spellId = talent->m_spellRank[displayRank]; + int32_t nextSpellId = talent->m_spellRank[displayRank + 1]; + SpellRec spell; + SpellRec nextSpell; + int32_t hasSpell = displayRank < 0 ? 0 : g_spellDB.GetRecord(spellId, &spell); + int32_t hasNext = displayRank >= maxRank ? 0 : g_spellDB.GetRecord(nextSpellId, &nextSpell); + + if (!hasSpell && !hasNext) { + return; + } + + this->m_spellId = hasSpell ? spellId : 0; + this->m_nextRankSpellId = hasNext ? nextSpellId : 0; + + if (hasSpell) { + this->AddLine(spell.m_name, nullptr, textColor, textColor, 0); + } else if (hasNext) { + this->AddLine(nextSpell.m_name, nullptr, textColor, textColor, 0); + } + + char text[2048]; + + if (maxRank >= 0) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("TOOLTIP_TALENT_RANK", -1, GENDER_NOT_APPLICABLE), displayRank + 1, maxRank + 1); + this->AddLine(text, nullptr, textColor, textColor, 0); + } + + int32_t prereqsMet = hasSpell ? 1 : this->AddTalentPrereqs(talent, group, isInspect, isPet, usePreview); + int32_t described = 0; + + if (hasSpell && spell.m_description && *spell.m_description) { + SpellParserParseText(&spell, text, sizeof(text), isPet, isInspect, 0, 0, 1, 0); + this->AddLine(text, nullptr, titleColor, titleColor, 1); + described = 1; + } + + if (hasNext && nextSpell.m_description && *nextSpell.m_description) { + if (described) { + this->AddLine(" ", nullptr, titleColor, titleColor, 0); + this->AddLine(FrameScript_GetText("TOOLTIP_TALENT_NEXT_RANK", -1, GENDER_NOT_APPLICABLE), nullptr, textColor, textColor, 0); + } + + SpellParserParseText(&nextSpell, text, sizeof(text), isPet, isInspect, 0, 0, 1, 0); + this->AddLine(text, nullptr, titleColor, titleColor, 1); + } + + this->AddTalentLearnText(talent, group, prereqsMet, currentRank, maxRank, isInspect, useRank, isPet, usePreview); + + if (this->m_onTooltipSetSpell.m_luaRef) { + this->RunScript(this->m_onTooltipSetSpell, 0, nullptr); + } + + this->Show(); +} + +// VERIFY: 17b021d1 auto +// OFFSET: 0x006201C0 +void CGTooltip::AddLine(const char* left, const char* right, int32_t wrap) { + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + this->AddLine(left, right, titleColor, titleColor, wrap); +} + +// VERIFY: 751e6184 manual +// OFFSET: 0x00630D20 +int32_t CGTooltip::SetMacro(uint32_t macroId) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + this->ClearTooltip(); + MACRONODE* macro = CGUIMacros::GetMacroByID(macroId); + + if (!macro) { + this->Hide(); + return 0; + } + + uint32_t dynamic = macro->m_dynamic; + + if (macro->unk_0570) { + if (macro->m_itemID) { + uint32_t duration = 0; + uint32_t start = 0; + uint32_t enable = 0; + CGItem_C* enchantItem = CGActionBar::FindUseEnchantItemPtr(macro->m_itemID); + + if (enchantItem) { + Spell_C_GetItemCooldown(enchantItem, &duration, &start, &enable); + } else { + Spell_C_GetItemCooldown(macro->m_itemID, &duration, &start, &enable); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + CGItem_C* item; + + if (player && (item = player->m_bag.FindItemOfType(macro->m_itemID, 0))) { + this->m_itemLinkInfo.Clear(); + this->m_itemLinkInfo.m_cooldown = enable && start && duration ? duration + start - OsGetAsyncTimeMs() : 0; + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(macro->m_itemID, none, nullptr, nullptr, false); + + if (stats && stats->m_spellCharges[0] != -1 && stats->m_spellCharges[0]) { + this->m_itemLinkInfo.m_spellCharges = player->m_bag.GetItemTypeCharges(macro->m_itemID, 0); + } + + WOWGUID guid = item->m_obj->m_guid; + return this->SetItem(item->m_obj->m_entryID, &guid, &guid, 0, 0, 1, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0) | dynamic; + } + + WOWGUID none = { 0 }; + return this->SetItem(macro->m_itemID, &none, &none, 0, 0, 0, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0) | dynamic; + } + + if (macro->m_spellID) { + uint32_t duration = 0; + uint32_t start = 0; + uint32_t enable = 0; + Spell_C_GetSpellCooldown(macro->m_spellID, macro->m_spellFlags, &duration, &start, &enable); + int32_t brief = 1; + CVar* uber = CVar::Lookup("UberTooltips"); + + if (uber && uber->m_intValue) { + brief = 0; + } + + if (!enable || !start || !duration) { + return this->SetSpell(macro->m_spellID, brief, 0, 0, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0) | dynamic; + } + + return this->SetSpell(macro->m_spellID, brief, start + duration - OsGetAsyncTimeMs(), 0, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0) | dynamic; + } + } + + this->AddLine(macro->m_name, nullptr, textColor, textColor, 0); + this->Show(); + return 0; +} + +// VERIFY: a5127ade auto +// OFFSET: 0x0061A4F0 +const uint32_t* CGTooltip::GetThreatStateColor(uint32_t status) { + if (status >= 5) { + status = 1; + } + + return &s_threatStatusColors[status]; +} diff --git a/WoW/Source/UIUtil/Tooltip.h b/WoW/Source/UIUtil/Tooltip.h index fabbd0d..d8a6d12 100644 --- a/WoW/Source/UIUtil/Tooltip.h +++ b/WoW/Source/UIUtil/Tooltip.h @@ -100,10 +100,13 @@ class CGTooltip : public CSimpleFrame { static const char* GetItemQualityColorString(uint32_t quality); static const char* CreateItemLink(int32_t itemId, uint32_t quality, int32_t enchant, const int32_t* gems, int32_t randomPropertiesId, int32_t seed); static const char* GetItemHyperlinkString(CGItem_C* item); + static const uint32_t* GetThreatStateColor(uint32_t status); static const char* GetItemHyperlinkString(int32_t itemId, uint32_t quality, int32_t enchant, int32_t randomPropertiesId, int32_t seed); static const char* GetQuestDifficultyColorString(int32_t level); static const char* GetQuestLink(int32_t questId, int32_t level); static const char* GetSpellLink(int32_t spellId); + static const char* GetGlyphLink(int32_t slotId, int32_t glyphId); + static const char* GetTalentHyperlinkString(const TalentRec* talent, const char* name, int32_t rank); static const char* GetAchievementHyperlink(int32_t achievementId, WOWGUID guid, int32_t a3, WowTime time, int32_t a5, int32_t a6, int32_t a7, int32_t a8); static int32_t GetObjectType(); static void RegisterScriptMethods(lua_State* L); @@ -134,7 +137,7 @@ class CGTooltip : public CSimpleFrame { /* 0364 */ int32_t m_spellId; /* 0368 */ uint32_t unk_0368; /* 036C */ uint32_t unk_036C; - /* 0370 */ uint32_t unk_0370; + /* 0370 */ int32_t m_nextRankSpellId; /* 0374 */ uint32_t unk_0374 [4]; /* 0384 */ WowTime m_time; /* 03A4 */ uint32_t unk_03A4 [4]; @@ -193,6 +196,9 @@ class CGTooltip : public CSimpleFrame { void SetCorpse(const WOWGUID& guid); void AddFontStrings(CSimpleFontString* left, CSimpleFontString* right); void AddLine(const char* left, const char* right, const CImVector& leftColor, const CImVector& rightColor, int32_t wrap); + void AddLine(const char* left, const char* right, int32_t wrap); + int32_t SetMacro(uint32_t macroId); + int32_t SetEquipmentSet(uint32_t setId); void AddTexture(const char* texture, const CAaRect& coords, const CImVector& color); void AddEmpathyText(CGUnit_C* unit, char* buffer, uint32_t size); void AddSkinnableText(CGUnit_C* unit, char* buffer, uint32_t size); @@ -208,8 +214,8 @@ class CGTooltip : public CSimpleFrame { int32_t AddTalentPrereqs(const TalentRec* talent, CGTalentGroup_C* group, int32_t isInspect, int32_t isPet, int32_t usePreview); void AddTalentLearnText(const TalentRec* talent, CGTalentGroup_C* group, int32_t prereqsMet, int32_t rank, int32_t maxRank, int32_t a7, int32_t a8, int32_t isPet, int32_t usePreview); int32_t SetQuest(int32_t questId); - void SetGlyph(int32_t glyphId, int32_t spellId, int32_t a3, int32_t a4, int32_t a5); - void SetTalent(const TalentRec* talent, CGTalentGroup_C* group, int32_t a3, int32_t a4, int32_t rank, int32_t a6, int32_t a7); + void SetGlyph(int32_t slotId, int32_t glyphId, int32_t enabled, int32_t hideRemove, int32_t parseUnit); + void SetTalent(const TalentRec* talent, CGTalentGroup_C* group, int32_t isInspect, int32_t useRank, int32_t rank, int32_t isPet, int32_t usePreview); int32_t SetAchievement(int32_t achievementId, uint64_t guid, bool completed, WowTime time, uint32_t criteria1, uint32_t criteria2, uint32_t criteria3, uint32_t criteria4, int32_t a10); int32_t SetSpell(int32_t spellId, int32_t brief, uint32_t cooldown, int32_t isPet, int32_t showRank, int32_t isInspect, int32_t a8, const TalentRec* talent, CGTalentGroup_C* talentGroup, int32_t append, int32_t usePreview, int32_t a13, int32_t rank, int32_t maxRank, int32_t showLearn); int32_t SetItem(int32_t itemId, const WOWGUID* requester, const WOWGUID* itemGuid, int32_t nameOnly, int32_t compare, int32_t useLinkInfo, int32_t append, WOWGUID owner, int32_t socketPreview, FILE* stream, int32_t hideCharges, const ItemLinkInfo* link, int32_t minimumLevel, int32_t skipLock, int32_t skipSellPrice); @@ -244,5 +250,6 @@ class CSimpleUI { }; extern uint32_t s_tooltipTitleColor; +extern uint32_t s_tooltipTextColor; #endif diff --git a/WoW/Source/UIUtil/Tooltip_Scripts.cpp b/WoW/Source/UIUtil/Tooltip_Scripts.cpp index c876e63..232a52f 100644 --- a/WoW/Source/UIUtil/Tooltip_Scripts.cpp +++ b/WoW/Source/UIUtil/Tooltip_Scripts.cpp @@ -28,18 +28,23 @@ #include "WoW/Source/Object/ObjectClient/UnitCombatLog_C.h" #include "WoW/Source/Ui/DanceStudio.h" #include "WoW/Source/Ui/TradeSkillFrame.h" +#include "WoW/Source/Ui/TalentInfo.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "WoW/Source/Ui/PetInfo.h" +#include "WoW/Source/Object/ItemStats.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "WoW/Source/Ui/LootFrame.h" +#include "WoW/Source/Object/ObjectClient/LootRoll.h" int32_t Script_AddFontStrings(lua_State* L); int32_t Script_GetAnchorType(lua_State* L); int32_t Script_SetAnchorType(lua_State* L); int32_t Script_AddTexture(lua_State* L); -int32_t Script_SetAction(lua_State* L); int32_t Script_SetPetAction(lua_State* L); int32_t Script_SetShapeshift(lua_State* L); int32_t Script_SetPossession(lua_State* L); int32_t Script_TooltipSetTracking(lua_State* L); -int32_t Script_SetGlyph(lua_State* L); -int32_t Script_SetLootItem(lua_State* L); int32_t Script_SetQuestItem(lua_State* L); int32_t Script_SetQuestLogItem(lua_State* L); int32_t Script_SetTrainerService(lua_State* L); @@ -52,7 +57,6 @@ int32_t Script_SetUnit(lua_State* L); int32_t Script_SetUnitBuff(lua_State* L); int32_t Script_SetUnitDebuff(lua_State* L); int32_t Script_SetUnitAura(lua_State* L); -int32_t Script_SetTalent(lua_State* L); int32_t Script_SetSendMailItem(lua_State* L); int32_t Script_SetInboxItem(lua_State* L); int32_t Script_SetAuctionSellItem(lua_State* L); @@ -61,7 +65,6 @@ int32_t Script_SetQuestRewardSpell(lua_State* L); int32_t Script_SetQuestLogRewardSpell(lua_State* L); int32_t Script_SetHyperlinkCompareItem(lua_State* L); int32_t Script_SetBuybackItem(lua_State* L); -int32_t Script_SetLootRollItem(lua_State* L); int32_t Script_SetSocketedItem(lua_State* L); int32_t Script_SetSocketGem(lua_State* L); int32_t Script_SetExistingSocketGem(lua_State* L); @@ -882,7 +885,302 @@ static int32_t Script_SetBagItem(lua_State* L) { return 2; } +// VERIFY: 92d6cbe1 manual +// OFFSET: 0x00625D00 +static int32_t Script_SetGlyph(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isnumber(L, 2)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetGlyph(glyphSlot[, groupIndex])", name ? name : ""); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + CGTalentGroup_C* group = TalentInfoGetTalentGroup(TalentInfoGetScriptGroupIndex(L, 3), 0, 0); + + if (player && group) { + uint32_t index = static_cast(lua_tonumber(L, 2)) - 1; + tooltip->SetGlyph(player->m_player->m_playerFieldGlyphSlots1[index], group->GetGlyph(index), (player->m_player->m_playerGlyphsEnabled & (1 << index)) != 0, 0, 0); + } + + return 0; +} + +// VERIFY: bb661fe0 manual +// OFFSET: 0x0062F740 +static int32_t Script_SetTalent(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetTalent(tabIndex, talentIndex[, isInspect[, isPet[, groupIndex[, isPreview]]]])", name ? name : ""); + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return 0; + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t talentIndex = static_cast(lua_tonumber(L, 3)) - 1; + int32_t inspect = StringToBOOL(L, 4, 0); + int32_t pet = StringToBOOL(L, 5, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 6); + int32_t preview = StringToBOOL(L, 7, 0); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, inspect, pet); + + if (tab && talentIndex < tab->m_numTalents) { + tooltip->SetTalent(&tab->m_talents[talentIndex], TalentInfoGetTalentGroup(group, inspect, pet), inspect, 0, -1, pet, preview); + } + + return 0; +} + +// VERIFY: 0e3c1413 manual +// OFFSET: 0x00631000 +static int32_t Script_SetAction(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isnumber(L, 2)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetAction(slot)", name ? name : ""); + } + + uint32_t slot = static_cast(lua_tonumber(L, 2) - 1.0); + uint32_t start; + uint32_t duration; + uint32_t enable; + CGActionBar::GetCooldown(slot, start, duration, enable); + tooltip->ClearTooltip(); + + if (CGActionBar::IsAttackAction(slot)) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char text[32]; + SStrCopy(text, FrameScript_GetText("ATTACK", -1, GENDER_NOT_APPLICABLE), sizeof(text)); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + tooltip->Show(); + lua_pushnil(L); + return 1; + } + + uint32_t action = CGActionBar::m_slotActions[slot]; + int32_t result; + + if (action && (action & 0xF0000000) == 0x80000000) { + int32_t itemId = CGActionBar::GetItem(slot); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + int32_t charges = CGItem_C::NumBaseCharges(itemId); + + if (!charges) { + CGItem_C* enchantItem = CGActionBar::FindUseEnchantItemPtr(itemId); + + if (enchantItem) { + charges = enchantItem->GetUsableSpellCharges(); + } + } + + CGItem_C* item = nullptr; + + if (player && stats) { + uint32_t flags; + + if (stats->m_inventoryType) { + flags = charges != -1 && charges ? 161 : 129; + item = player->m_bag.FindItemOfType(itemId, flags); + + if (!item && (flags & 0x20)) { + item = player->m_bag.FindItemOfType(itemId, 32); + } + + if (!item) { + item = player->m_bag.FindItemOfType(itemId, 128); + } + } else { + flags = charges != -1 && charges ? 288 : 256; + item = player->m_bag.FindItemOfType(itemId, flags); + + if (!item && (flags & 0x20)) { + item = player->m_bag.FindItemOfType(itemId, flags & ~0x20); + } + } + } + + if (item) { + tooltip->m_itemLinkInfo.Clear(); + tooltip->m_itemLinkInfo.m_cooldown = enable && start && duration ? duration + start - OsGetAsyncTimeMs() : 0; + + if (charges != -1 && charges) { + tooltip->m_itemLinkInfo.m_spellCharges = item->GetCurrentSpellCharges(); + } + + WOWGUID guid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &guid, &guid, 0, 0, 1, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0); + } else { + WOWGUID empty = { 0 }; + result = tooltip->SetItem(itemId, &empty, &empty, 0, 0, 0, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0); + } + } else if (action && !(action & 0xF0000000)) { + int32_t brief = 1; + CVar* uber = CVar::Lookup("UberTooltips"); + + if (uber && uber->m_intValue) { + brief = 0; + } + + int32_t petSpell; + int32_t spellId = CGActionBar::GetSpell(slot, petSpell); + + if (enable && start && duration) { + result = tooltip->SetSpell(spellId, brief, duration + start - OsGetAsyncTimeMs(), 0, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + } else { + result = tooltip->SetSpell(spellId, brief, 0, 0, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + } + } else if (CGActionBar::IsMacro(slot)) { + result = tooltip->SetMacro(CGActionBar::GetMacroID(slot)); + } else if (CGActionBar::IsEquipmentSet(slot)) { + result = tooltip->SetEquipmentSet(CGActionBar::GetEquipmentSetID(slot)); + } else { + if (!CGActionBar::IsPetAction(slot)) { + lua_pushnil(L); + return 1; + } + + uint32_t* petAction = GetPetAction(CGActionBar::GetSlotSpellAction(slot)); + + if (!petAction || !*petAction) { + lua_pushnil(L); + return 1; + } + + uint32_t value = *petAction; + char token[64]; + const char* text; + + switch ((value >> 24) & 0x3F) { + case 1: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: { + uint32_t petStart = 0; + uint32_t petDuration = 0; + uint32_t petEnable = 0; + Spell_C_GetSpellCooldown(value & 0xFFFFFF, 1, &petDuration, &petStart, &petEnable); + + if (petEnable && petStart && petDuration) { + result = tooltip->SetSpell(*petAction & 0xFFFFFF, 0, petStart + petDuration - OsGetAsyncTimeMs(), 1, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + } else { + result = tooltip->SetSpell(*petAction & 0xFFFFFF, 0, 0, 1, 1, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + } + + goto done; + } + + case 6: { + SStrPrintf(token, sizeof(token), "PET_MODE_%s", CGPetInfo::GetModeToken(value & 0xFFFFFF)); + text = FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE); + break; + } + + case 7: { + SStrPrintf(token, sizeof(token), "PET_ACTION_%s", CGPetInfo::GetOrdersToken(value & 0xFFFFFF)); + text = FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE); + break; + } + + default: { + lua_pushnil(L); + return 1; + } + } + + tooltip->AddLine(text, nullptr, 0); + tooltip->Show(); + lua_pushnil(L); + return 1; + } + +done: + if (!result) { + lua_pushnil(L); + return 1; + } + + lua_pushnumber(L, 1.0); + return 1; +} + // STATIC: 0x00AD2AE0 +// VERIFY: da7bc442 manual +// OFFSET: 0x0062E520 +static int32_t Script_SetLootItem(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isnumber(L, 2)) { + luaL_error(L, "Invalid loot slot in SetInventoryItem"); + } + + uint32_t slot = static_cast(static_cast(lua_tonumber(L, 2) - 1.0)); + int32_t itemId = CGLootInfo::GetLootItem(slot); + + if (itemId <= 0) { + return 0; + } + + tooltip->m_itemLinkInfo.Clear(); + tooltip->m_itemLinkInfo.m_propertySeed = CGLootInfo::GetLootItemRandomSuffix(slot); + tooltip->m_itemLinkInfo.m_randomPropertiesId = CGLootInfo::GetLootItemRandomPropertyId(slot); + tooltip->m_itemLinkInfo.m_stackCount = CGLootInfo::GetLootItemCount(slot); + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, none, nullptr, nullptr, false); + + if (stats) { + for (uint32_t i = 0; i < 5; i++) { + if (stats->m_spellId[i] && !stats->m_spellTrigger[i]) { + tooltip->m_itemLinkInfo.m_spellCharges = stats->m_spellCharges[i]; + break; + } + } + } + + WOWGUID itemGuid = WOWGUID(); + tooltip->SetItem(itemId, &CGLootInfo::m_lootObj, &itemGuid, 0, 0, 1, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0); + return 0; +} + +// VERIFY: 4a9b0c14 manual +// OFFSET: 0x006300A0 +static int32_t Script_SetLootRollItem(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isnumber(L, 2)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetLootRollItem(id)", name ? name : ""); + } + + PendingLootRoll* roll = FindRoll(static_cast(lua_tonumber(L, 2))); + + if (!roll) { + return 0; + } + + tooltip->m_itemLinkInfo.Clear(); + tooltip->m_itemLinkInfo.m_propertySeed = roll->m_randomSuffix; + tooltip->m_itemLinkInfo.m_randomPropertiesId = roll->m_randomPropertyId; + tooltip->m_itemLinkInfo.m_stackCount = roll->m_count; + WOWGUID requester = WOWGUID(); + WOWGUID itemGuid = WOWGUID(); + tooltip->SetItem(roll->m_itemId, &requester, &itemGuid, 0, 0, 1, 0, WOWGUID(), 0, nullptr, 0, nullptr, 0, 0, 0); + return 0; +} + static FrameScript_Method s_ScriptMethods[] = { { "AddFontStrings", &Script_AddFontStrings }, { "SetMinimumWidth", &Script_SetMinimumWidth }, diff --git a/WoW/Source/Ui/AchievementInfo.cpp b/WoW/Source/Ui/AchievementInfo.cpp index bba0321..1726285 100644 --- a/WoW/Source/Ui/AchievementInfo.cpp +++ b/WoW/Source/Ui/AchievementInfo.cpp @@ -3,6 +3,10 @@ #include "WoW/Source/DB/Rec/AchievementRec.h" #include "WoW/Source/DB/Rec/Achievement_CriteriaRec.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/DB/Rec/Achievement_CategoryRec.h" +#include "WoW/Source/Ui/Types.h" // STATIC: 0x00ACFD98 static TSList> s_unkACFD98; @@ -96,3 +100,212 @@ void CGAchievementInfo::InitializeGame() { } } } + +// VERIFY: 1479ef2e auto +// OFFSET: 0x005B0DE0 +bool CGAchievementInfo::IsCriteriaStat(int32_t criteriaId) { + Achievement_CriteriaRec* criteria = g_achievement_CriteriaDB.GetRecord(criteriaId); + + if (!criteria) { + return false; + } + + AchievementRec* achievement = g_achievementDB.GetRecord(criteria->m_achievementID); + + if (!achievement) { + return false; + } + + Achievement_CategoryRec* category = g_achievement_CategoryDB.GetRecord(achievement->m_category); + + if (!category) { + return false; + } + + if (category->m_id == 1) { + return true; + } + + category = g_achievement_CategoryDB.GetRecord(category->m_parent); + + if (!category) { + return false; + } + + while (category->m_id != 1) { + category = g_achievement_CategoryDB.GetRecord(category->m_parent); + + if (!category) { + return false; + } + } + + return true; +} + +// VERIFY: 06c77f2b manual +// OFFSET: 0x005B2520 +void CGAchievementInfo::UpdateCriteria(int32_t id, uint64_t counter, uint32_t flags, WowTime date, WOWGUID player, uint32_t timer1, uint32_t timer2) { + CLIENT_ACHIEVEMENT_CRITERIA* criteria = nullptr; + + for (CLIENT_ACHIEVEMENT_CRITERIA* node = s_unkACFD98.Head(); node; node = s_unkACFD98.Next(node)) { + if (node->m_id == id) { + criteria = node; + break; + } + } + + if (!criteria) { + criteria = s_unkACFD98.NewNode(0, 0, 0); + CLIENT_ACHIEVEMENT_CRITERIA* position = s_unkACFD98.Head(); + + while (position && position->m_date > date) { + position = s_unkACFD98.Next(position); + } + + s_unkACFD98.LinkNode(criteria, 2, position); + } + + criteria->m_counter = counter; + criteria->m_id = id; + criteria->m_flags = flags; + criteria->m_date = date; + criteria->m_player = player; + criteria->m_timer1 = timer1; + criteria->m_timer2 = timer2; + + if (flags & 1) { + s_unkACFD98.UnlinkNode(criteria); + delete criteria; + return; + } + + if (!CGAchievementInfo::IsCriteriaStat(id)) { + return; + } + + CLIENT_ACHIEVEMENT_CRITERIA* recent = s_unkACFDA4.NewNode(0, 0, 0); + recent->m_id = criteria->m_id; + recent->m_counter = criteria->m_counter; + recent->m_flags = criteria->m_flags; + recent->m_date = criteria->m_date; + recent->m_player = criteria->m_player; + recent->m_timer1 = criteria->m_timer1; + + Achievement_CriteriaRec* rec = g_achievement_CriteriaDB.GetRecord(recent->m_id); + CLIENT_ACHIEVEMENT_CRITERIA* node = s_unkACFDA4.Head(); + s_unkACFDA4.LinkNode(recent, 2, node); + + for (int32_t count = 0; node; ) { + Achievement_CriteriaRec* nodeRec = g_achievement_CriteriaDB.GetRecord(node->m_id); + + if (nodeRec) { + if (node->m_id == recent->m_id || nodeRec->m_achievementID == rec->m_achievementID) { + s_unkACFDA4.UnlinkNode(node); + delete node; + node = nullptr; + } else { + node = s_unkACFDA4.Next(node); + } + } + + if (++count >= 5) { + if (node) { + s_unkACFDA4.UnlinkNode(node); + delete node; + } + + return; + } + } +} + +// VERIFY: b31d5df0 manual +// OFFSET: 0x005B28D0 +void CGAchievementInfo::UpdateAchievement(int32_t id, WowTime date) { + CLIENT_ACHIEVEMENTS* achievement = nullptr; + + for (CLIENT_ACHIEVEMENTS* node = s_completedAchievements.Head(); node; node = s_completedAchievements.Next(node)) { + if (node->m_id == id) { + achievement = node; + break; + } + } + + AchievementRec* rec = g_achievementDB.GetRecord(id); + + if (!rec) { + return; + } + + if (!achievement) { + achievement = s_completedAchievements.NewNode(0, 0, 0); + CLIENT_ACHIEVEMENTS* position = s_completedAchievements.Head(); + bool found = false; + + while (position && position->m_date >= date && !found) { + if (position->m_date == date) { + while (position && position->m_date >= date && !found) { + AchievementRec* other = g_achievementDB.GetRecord(position->m_id); + + if (other && rec->m_uiOrder > other->m_uiOrder) { + found = true; + } else { + position = s_completedAchievements.Next(position); + } + } + } else { + position = s_completedAchievements.Next(position); + } + } + + s_completedAchievements.LinkNode(achievement, 2, position); + } + + achievement->m_id = id; + achievement->m_date = date; +} + +// VERIFY: 27756e9f manual +// OFFSET: 0x005B32F0 +int32_t Packet_SMSG_ALL_ACHIEVEMENT_DATA(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + CGAchievementInfo::m_showAchievementUI = 1; + WowTime date; + int32_t now = static_cast(::time(nullptr)); + int32_t id; + msg->Get(reinterpret_cast(id)); + + while (id >= 0) { + *msg >> date; + CGAchievementInfo::UpdateAchievement(id, date); + msg->Get(reinterpret_cast(id)); + } + + msg->Get(reinterpret_cast(id)); + + while (id >= 0) { + SmartGUID counter; + SmartGUID player; + uint32_t flags; + uint32_t timer1; + uint32_t timer2; + *msg >> counter; + *msg >> player; + msg->Get(flags); + *msg >> date; + msg->Get(timer1); + msg->Get(timer2); + CGAchievementInfo::UpdateCriteria(id, counter.m_guid, flags, date, player, now - timer1, now - timer2); + Achievement_CriteriaRec* rec = g_achievement_CriteriaDB.GetRecord(id); + + if (rec && rec->m_timerTime) { + FrameScript_SignalEvent(SCRIPT_EVENT_TRACKED_ACHIEVEMENT_UPDATE, "%d%d%d%d", rec->m_achievementID, rec->m_id, timer1, rec->m_timerTime); + } + + msg->Get(reinterpret_cast(id)); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CRITERIA_UPDATE, nullptr); + FrameScript_SignalEvent(SCRIPT_EVENT_RECEIVED_ACHIEVEMENT_LIST, nullptr); + return 1; +} diff --git a/WoW/Source/Ui/AchievementInfo.h b/WoW/Source/Ui/AchievementInfo.h index a4a49e7..f6b568e 100644 --- a/WoW/Source/Ui/AchievementInfo.h +++ b/WoW/Source/Ui/AchievementInfo.h @@ -5,6 +5,7 @@ #include "WoW/Source/Object/WGUID.h" #include "Engine/Source/Storm/H/stpl.h" #include "WoW/Source/Net/Types.h" +#include "WoW/Common/WowTime.h" class AchievementRec; class Achievement_CriteriaRec; @@ -12,10 +13,20 @@ class CDataStore; struct lua_State; struct CLIENT_ACHIEVEMENT_CRITERIA : public TSLinkedNode { + /* 0008 */ int32_t m_id; + /* 000C */ uint32_t unk_000C; + /* 0010 */ uint64_t m_counter; + /* 0018 */ uint32_t m_flags; + /* 001C */ WowTime m_date; + /* 003C */ uint32_t unk_003C; + /* 0040 */ WOWGUID m_player; + /* 0048 */ uint32_t m_timer1; + /* 004C */ uint32_t m_timer2; }; struct CLIENT_ACHIEVEMENTS : public TSLinkedNode { /* 0008 */ int32_t m_id; + /* 000C */ WowTime m_date; }; struct COMPLETED_QUESTS : public TSLinkedNode { @@ -44,9 +55,13 @@ int32_t Packet_SMSG_QUERY_QUESTS_COMPLETED_RESPONSE(void* param, NETMESSAGE msgI class CGAchievementInfo { public: - static void InitializeGame(); static int32_t m_showAchievementUI; static WOWGUID m_inspect; + + static void InitializeGame(); + static bool IsCriteriaStat(int32_t criteriaId); + static void UpdateAchievement(int32_t id, WowTime date); + static void UpdateCriteria(int32_t id, uint64_t counter, uint32_t flags, WowTime date, WOWGUID player, uint32_t timer1, uint32_t timer2); }; int32_t Script_GetCategoryList(lua_State* L); diff --git a/WoW/Source/Ui/ActionBarFrame.cpp b/WoW/Source/Ui/ActionBarFrame.cpp index 9665043..0d18f2b 100644 --- a/WoW/Source/Ui/ActionBarFrame.cpp +++ b/WoW/Source/Ui/ActionBarFrame.cpp @@ -229,7 +229,7 @@ int32_t CGActionBar::IsRangedAttackAction(uint32_t slot) { return 0; } -// VERIFY: 8b6cbfa9 manual +// VERIFY: 22df6d59 manual // OFFSET: 0x005A9E20 int32_t CGActionBar::UpdateUsableAction(uint32_t slot, int32_t& noMana) { noMana = 0; @@ -343,7 +343,7 @@ int32_t CGActionBar::UpdateUsableAction(uint32_t slot, int32_t& noMana) { MACRONODE* macro = CGUIMacros::GetMacroByID(CGActionBar::GetMacroID(slot)); if (macro) { - target = *reinterpret_cast(¯o->unk_0578[0]); + target = macro->m_target; } } @@ -486,9 +486,9 @@ uint32_t CGPetInfo::GetPetMode() { return static_cast(CGPetInfo::m_petMode); } -// VERIFY: 0bd264de auto +// VERIFY: 332acd46 auto // OFFSET: 0x005A79A0 -static uint32_t* GetPetAction(uint32_t index) { +uint32_t* GetPetAction(uint32_t index) { if (CGPetInfo::GetPet(0) && index < sizeof(CGPetInfo::m_actions) / sizeof(CGPetInfo::m_actions[0])) { return &CGPetInfo::m_actions[index]; } @@ -1494,3 +1494,407 @@ int32_t CGActionBar::IsConsumableAction(uint32_t slot) { return 0; } + +// VERIFY: 167e06af auto +// OFFSET: 0x005A7CC0 +void CGActionBar::SignalUpdateCooldown() { + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_UPDATE_COOLDOWN, nullptr); +} + +// VERIFY: 243b49e9 manual +// OFFSET: 0x005AAB10 +void CGActionBar::OnAuraChanged(int32_t spellId) { + if (!spellId) { + return; + } + + for (uint32_t i = 0; i < 144; i++) { + int32_t petSpell; + + if (CGActionBar::GetSpell(i, petSpell) == spellId && !petSpell) { + CGActionBar::SlotChanged(i, 0, 0); + } + } +} + +// VERIFY: 8f9b1721 manual +// OFFSET: 0x005A7920 +uint32_t CGActionBar::GetSlotSpellAction(uint32_t slot) { + uint32_t action = CGActionBar::m_slotActions[slot]; + + if (action && (action & 0xF0000000) == 0x10000000) { + return action & 0xEFFFFFFF; + } + + return 0; +} + +// VERIFY: eaef0f5d auto +// OFFSET: 0x005A7C80 +static int32_t HasOverrideSpellData(const OverrideSpellDataRec* rec) { + if (!rec) { + return 0; + } + + for (uint32_t i = 0; i < 10; i++) { + if (rec->m_spells[i]) { + return 1; + } + } + + return 0; +} + +// VERIFY: 5c0eac99 auto +// OFFSET: 0x005A7CF0 +static int32_t GetOverrideSpell(uint32_t index, const void* data) { + if (data && index < 10) { + return static_cast(data)->m_spells[index]; + } + + return 0; +} + +// VERIFY: 4f453604 manual +// OFFSET: 0x005ABB40 +void CGActionBar::UpdateOverrideSpellBar() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + OverrideSpellDataRec* rec; + + if (player && (rec = g_overrideSpellDataDB.GetRecord(static_cast(player->m_player->m_playerFieldBytes2))) && HasOverrideSpellData(rec)) { + CGActionBar::UpdateTemporaryActionBar(&GetOverrideSpell, rec); + CGActionBar::m_tempPageActiveFlags |= 0x4; + } else { + CGActionBar::m_tempPageActiveFlags &= ~0x4; + } +} + +// VERIFY: a5c3e3b2 auto +// OFFSET: 0x005AAB90 +void CGActionBar::RemoveMacro(int32_t spellId) { + for (uint32_t i = 0; i < 144; i++) { + int32_t petSpell; + + if (CGActionBar::GetSpell(i, petSpell) != spellId) { + continue; + } + + uint32_t action = CGActionBar::m_slotActions[i]; + + if (action && (action & 0xF0000000) == 0x40000000) { + CGUIMacros::GetMacroByID(action & 0xBFFFFFFF)->FindSpellID(); + } + + CGActionBar::RemoveAction(i); + } +} + +// VERIFY: d191a5f1 manual +// OFFSET: 0x005AAA90 +void CGActionBar::RemoveAction(uint32_t slot) { + if (static_cast(slot) < 0 || slot >= 144) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || player->unk_1954) { + return; + } + + if (CGActionBar::IsMacro(slot)) { + MACRONODE* macro = CGUIMacros::GetMacroByID(CGActionBar::GetMacroID(slot)); + + if (macro) { + macro->DecrementActionBarCount(); + } + } + + CGActionBar::m_slotActions[slot] = 0; + CGActionBar::SlotChanged(slot, 1, 0); +} + +// VERIFY: 9df78218 auto +// OFFSET: 0x005AA920 +void CGActionBar::UpdateMacro(uint32_t macroId) { + if (!macroId) { + return; + } + + for (uint32_t i = 0; i < 144; i++) { + uint32_t action = CGActionBar::m_slotActions[i]; + uint32_t id = action && (action & 0xF0000000) == 0x40000000 ? action & 0xBFFFFFFF : 0; + + if (id != macroId) { + continue; + } + + int32_t count = 0; + + if (CGActionBar::GetItem(i)) { + count = CGActionBar::CalculateItemCount(CGActionBar::GetItem(i)); + } else { + int32_t petSpell; + int32_t spellId = CGActionBar::GetSpell(i, petSpell); + + if (spellId && !petSpell) { + count = Spell_C_GetSpellReagentUses(spellId); + } + } + + CGActionBar::m_slotItemCount[i] = count; + int32_t noMana; + CGActionBar::m_slotUsable[i] = CGActionBar::UpdateUsableAction(i, noMana); + CGActionBar::m_slotNoMana[i] = noMana; + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_SLOT_CHANGED, "%d", i + 1); + } +} + +// VERIFY: c1c240db auto +// OFFSET: 0x005A7C20 +void CGActionBar::SetTemporaryActionBarFlags(uint32_t flags, int32_t enable) { + if (enable) { + CGActionBar::m_tempPageActiveFlags |= flags; + } else { + CGActionBar::m_tempPageActiveFlags &= ~flags; + } +} + +// VERIFY: 990974c3 auto +// OFFSET: 0x005AB800 +void CGActionBar::UpdateTemporaryActionBar(int32_t (*getSpell)(uint32_t index, const void* data), const void* data) { + if (!getSpell) { + return; + } + + for (uint32_t i = 0; i < 12; i++) { + CGActionBar::SetAction(i + 120, getSpell(i, data), 0, 0); + } +} + +// VERIFY: c3611dc4 manual +// OFFSET: 0x005A8D30 +void CGActionBar::UpdateUsablePower() { + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + SpellRec spell; + int32_t changed = 0; + + for (uint32_t i = 0; i < 144; i++) { + if (!CGActionBar::m_slotUsable[i]) { + continue; + } + + int32_t noMana = 0; + int32_t petSpell; + int32_t spellId = CGActionBar::GetSpell(i, petSpell); + + if (spellId && g_spellDB.GetRecord(spellId, &spell)) { + CGUnit_C* caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : player; + + if (caster) { + noMana = !Spell_C_HaveSpellPower(caster, &spell); + } + } + + if (noMana != CGActionBar::m_slotNoMana[i]) { + CGActionBar::m_slotNoMana[i] = noMana; + changed = 1; + } + } + + if (changed) { + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_UPDATE_USABLE, nullptr); + } +} + +// VERIFY: 6a47ffb3 auto +// OFFSET: 0x005A7CD0 +static int32_t GetFormPresetSpell(uint32_t index, const void* data) { + const SpellShapeshiftFormRec* form = static_cast(data); + + if (form && index < 8) { + return form->m_presetSpellID[index]; + } + + return 0; +} + +// VERIFY: 82a1fae7 manual +// OFFSET: 0x005ABAC0 +void CGActionBar::UpdateShapeShiftBar() { + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + SpellShapeshiftFormRec* form; + + if (player && (form = g_spellShapeshiftFormDB.GetRecord(player->GetShapeshiftForm())) && FormHasActionBar(form)) { + CGActionBar::UpdateTemporaryActionBar(GetFormPresetSpell, form); + CGActionBar::m_tempPageActiveFlags |= 2; + } else { + CGActionBar::m_tempPageActiveFlags &= ~2u; + } +} + +// VERIFY: 3645420e manual +// OFFSET: 0x005A9470 +int32_t CGActionBar::IsAutoRepeatAction(uint32_t slot) { + if (slot > 143) { + return 0; + } + + int32_t petSpell; + int32_t spellId = CGActionBar::GetSpell(slot, petSpell); + + return spellId && !petSpell && (Spell_C_GetAutoRepeatingSpell() == spellId || Spell_C_GetAutoRangedCombatSpell() == spellId); +} + +// VERIFY: 7fa85525 manual +// OFFSET: 0x005A94C0 +int32_t CGActionBar::HasValidTarget(uint32_t slot, WOWGUID target, int32_t* inRange) { + if (slot > 143) { + return 0; + } + + SpellRec spell; + int32_t petSpell; + + if (!g_spellDB.GetRecord(CGActionBar::GetSpell(slot, petSpell), &spell)) { + return 0; + } + + if (!target && CGActionBar::IsMacro(slot)) { + MACRONODE* macro = CGUIMacros::GetMacroByID(CGActionBar::GetMacroID(slot)); + + if (macro) { + target = macro->m_target; + } + } + + CGUnit_C* caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : ClntObjMgrGetActivePlayerObj(); + uint8_t result; + + if (caster && Spell_C_RangeCheckSelected(caster, &spell, target, &result, false, nullptr)) { + *inRange = result; + return 1; + } + + return 0; +} + +// VERIFY: 5e49e6d0 manual +// OFFSET: 0x005AA5C0 +void CGActionBar::UpdateItem(int32_t itemId) { + if (!itemId) { + return; + } + + int32_t count = CGActionBar::CalculateItemCount(itemId); + + for (uint32_t i = 0; i < 144; i++) { + uint32_t action = CGActionBar::m_slotActions[i]; + + if (action && (action & 0xF0000000) == 0x40000000) { + MACRONODE* macro = CGUIMacros::GetMacroByID(action & 0xBFFFFFFF); + + if (macro && macro->m_spellID < 0) { + macro->FindSpellID(); + } + } + + int32_t item = CGActionBar::GetItem(i); + + if (!item) { + int32_t petSpell; + int32_t spellId = CGActionBar::GetSpell(i, petSpell); + + if (!spellId || petSpell) { + continue; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && Spell_C_SpellUsesReagent(&spell, itemId)) { + CGActionBar::m_slotItemCount[i] = Spell_C_GetSpellReagentUses(&spell); + int32_t noMana; + CGActionBar::m_slotUsable[i] = CGActionBar::UpdateUsableAction(i, noMana); + CGActionBar::m_slotNoMana[i] = noMana; + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_SLOT_CHANGED, "%d", i + 1); + } + + continue; + } + + if (item == itemId) { + if (!count) { + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(item, none, nullptr, nullptr, false); + + if (stats) { + uint32_t index = 0; + + while (stats->m_spellTrigger[index] != 6) { + if (++index >= 5) { + break; + } + } + + if (index < 5) { + uint32_t spellId = stats->m_spellId[index]; + + if (spellId && spellId <= static_cast(g_spellDB.m_maxID) && (s_knownSpellBits.m_bits.m_data[spellId >> 5] & (1 << (spellId & 0x1F)))) { + CGActionBar::SetAction(i, spellId, 1, 0); + continue; + } + } + } + } + + CGActionBar::m_slotItemCount[i] = count; + int32_t noMana; + CGActionBar::m_slotUsable[i] = CGActionBar::UpdateUsableAction(i, noMana); + CGActionBar::m_slotNoMana[i] = noMana; + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_SLOT_CHANGED, "%d", i + 1); + continue; + } + + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(item, none, nullptr, nullptr, false); + + if (!stats || stats->m_stackable > 1) { + continue; + } + + CGItem_C* enchantItem = CGActionBar::FindUseEnchantItemPtr(item); + int32_t charges = enchantItem ? enchantItem->GetUsableSpellCharges() : CGItem_C::NumBaseCharges(item); + + if (charges < 0) { + continue; + } + + int32_t spellId = enchantItem ? enchantItem->GetEnchantmentSpell(0) : CGItem_C::GetUseSpell(item); + + if (!spellId) { + continue; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + continue; + } + + uint32_t reagent = 0; + + while (!spell.m_reagent[reagent] || spell.m_reagentCount[reagent] <= 0) { + if (++reagent >= 8) { + break; + } + } + + if (reagent < 8 && Spell_C_SpellUsesReagent(&spell, itemId)) { + CGActionBar::m_slotItemCount[i] = Spell_C_GetSpellReagentUses(&spell); + int32_t noMana; + CGActionBar::m_slotUsable[i] = CGActionBar::UpdateUsableAction(i, noMana); + CGActionBar::m_slotNoMana[i] = noMana; + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIONBAR_SLOT_CHANGED, "%d", i + 1); + } + } +} diff --git a/WoW/Source/Ui/ActionBarFrame.h b/WoW/Source/Ui/ActionBarFrame.h index 76bd434..b6a1a0b 100644 --- a/WoW/Source/Ui/ActionBarFrame.h +++ b/WoW/Source/Ui/ActionBarFrame.h @@ -8,12 +8,17 @@ struct lua_State; class CGItem_C; +uint32_t* GetPetAction(uint32_t index); + class CGActionBar { public: + static void SignalUpdateCooldown(); static uint32_t m_tempPageActiveFlags; static uint32_t m_currentPage; static int32_t m_bonusBarOffset; static void UpdateOverrideSpellBar(); + static uint32_t GetSlotSpellAction(uint32_t slot); + static void UpdateTemporaryActionBar(int32_t (*getSpell)(uint32_t index, const void* data), const void* data); static void EnterWorld(); static int32_t m_slotNoMana[144]; static int32_t m_slotUsable[144]; @@ -38,10 +43,13 @@ class CGActionBar { static int32_t IsConsumableAction(uint32_t slot); static int32_t GetSpell(uint32_t slot, int32_t& petSpell); static int32_t IsAttackAction(uint32_t slot); + static int32_t IsAutoRepeatAction(uint32_t slot); + static int32_t HasValidTarget(uint32_t slot, WOWGUID target, int32_t* inRange); static int32_t IsRangedAttackAction(uint32_t slot); static int32_t UpdateUsableAction(uint32_t slot, int32_t& noMana); static void SetAction(int32_t slot, uint32_t action, int32_t sendToServer, int32_t silent); static void UpdateBonusBar(); + static void SetTemporaryActionBarFlags(uint32_t flags, int32_t enable); static void UpdateShapeShiftBar(); static void InitializeGame(); static void UpdateAttackAction(); @@ -49,11 +57,13 @@ class CGActionBar { static void UpdateRangedAttackAction(); static void HideGrid(); static void UpdateUsable(); + static void UpdateUsablePower(); static void RemoveAction(uint32_t slot); static void ReplaceSpell(int32_t oldSpell, int32_t newSpell); static int32_t HasAction(uint32_t slot); static void PutActionInSlot(int32_t slot); static void UpdateMultiCastBar(); + static void RemoveMacro(int32_t spellId); static uint32_t GetMultiCastSlotMaskForTotemCategory(int32_t category); static bool IsEquipmentSetValid(int32_t setId); static int32_t IsSpell(uint32_t slot); @@ -74,11 +84,8 @@ void ItemStatsCallback(int32_t id, const WOWGUID& guid, void* param, bool succes int32_t Script_GetActionAutocast(lua_State* L); int32_t Script_PickupAction(lua_State* L); -int32_t Script_IsAttackAction(lua_State* L); -int32_t Script_IsAutoRepeatAction(lua_State* L); int32_t IsStackableAucItem(uint32_t slot); int32_t Script_ActionHasRange(lua_State* L); -int32_t Script_IsActionInRange(lua_State* L); int32_t Script_GetMultiCastTotemSpells(lua_State* L); int32_t Script_SetMultiCastSpell(lua_State* L); void ActionBarRegisterScriptFunctions(); diff --git a/WoW/Source/Ui/ActionBarFrame_Scripts.cpp b/WoW/Source/Ui/ActionBarFrame_Scripts.cpp index 2184182..96db582 100644 --- a/WoW/Source/Ui/ActionBarFrame_Scripts.cpp +++ b/WoW/Source/Ui/ActionBarFrame_Scripts.cpp @@ -431,6 +431,61 @@ static int32_t Script_GetMultiCastBarOffset(lua_State* L) { } // STATIC: 0x00ACF9E0 +// VERIFY: c199b98c auto +// OFFSET: 0x005A9BA0 +static int32_t Script_IsAttackAction(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: IsAttackAction(slot)"); + } + + int32_t slot = static_cast(lua_tonumber(L, 1)); + + if (CGActionBar::IsAttackAction(slot - 1)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: 651b85d6 auto +// OFFSET: 0x005A9C10 +static int32_t Script_IsAutoRepeatAction(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: IsAutorepeatAction(slot)"); + } + + int32_t slot = static_cast(lua_tonumber(L, 1)); + + if (CGActionBar::IsAutoRepeatAction(slot - 1)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: a6dadaad manual +// OFFSET: 0x005A9D50 +static int32_t Script_IsActionInRange(lua_State* L) { + if (lua_isnumber(L, 1)) { + int32_t slot = static_cast(lua_tonumber(L, 1)); + int32_t inRange = 0; + WOWGUID target = WOWGUID(); + Script_GetGUIDFromToken(lua_tolstring(L, 2, nullptr), target, false); + + if (CGActionBar::HasValidTarget(slot - 1, target, &inRange)) { + lua_pushnumber(L, inRange ? 1.0 : 0.0); + return 1; + } + } + + lua_pushnil(L); + return 1; +} + static FrameScript_Method s_ScriptFunctions[] = { { "GetActionInfo", &Script_GetActionInfo }, { "GetActionTexture", &Script_GetActionTexture }, diff --git a/WoW/Source/Ui/ArenaTeamInfo.cpp b/WoW/Source/Ui/ArenaTeamInfo.cpp index b01a38d..b75f3d7 100644 --- a/WoW/Source/Ui/ArenaTeamInfo.cpp +++ b/WoW/Source/Ui/ArenaTeamInfo.cpp @@ -7,6 +7,8 @@ #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/Object/Player.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "Engine/Source/Os/TimeManager.h" // STATIC: 0x00A15ABC static const int32_t s_arenaBracketTypes[3] = { 2, 3, 5 }; @@ -132,3 +134,70 @@ bool CGArenaTeamInfo::CheckPersonalAndTeamRating(uint32_t rating, int32_t bracke return false; } + +// VERIFY: 3cf409c5 manual +// OFFSET: 0x005A3600 +void CGArenaTeamInfo::QueryRoster(uint32_t index) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || index >= 3) { + return; + } + + uint32_t* info = &player->m_player->m_playerFieldArenaTeamInfo11[index * 7]; + + if (!info || !*info) { + return; + } + + uint32_t now = OsGetAsyncTimeMs(); + + if (CGArenaTeamInfo::m_nextAllowedQuery[index] && static_cast(now - CGArenaTeamInfo::m_nextAllowedQuery[index]) < 0) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_ARENA_TEAM_ROSTER)); + msg.Put(*info); + msg.Finalize(); + ClientServices::Send2(&msg); + CGArenaTeamInfo::m_nextAllowedQuery[index] = now + 10000; +} + +// VERIFY: 45de7426 manual +// OFFSET: 0x005A3700 +void CGArenaTeamInfo::UpdateTeams(int32_t signal) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + for (uint32_t i = 0; i < 3; i++) { + uint32_t* info = i < 3 ? &player->m_player->m_playerFieldArenaTeamInfo11[i * 7] : nullptr; + + if (!info) { + continue; + } + + if (CGArenaTeamInfo::m_arenaTeams[i].m_teamId && !*info) { + g_arenaTeamCache.Invalidate(CGArenaTeamInfo::m_arenaTeams[i].m_teamId); + } + + CGArenaTeamInfo::m_arenaTeams[i].m_teamId = *info; + + if (*info) { + CGArenaTeamInfo::QueryRoster(i); + } + } + + if (signal) { + FrameScript_SignalEvent(SCRIPT_EVENT_ARENA_TEAM_UPDATE, nullptr); + } +} + +// VERIFY: de2c9b7d auto +// OFFSET: 0x005A3DC0 +void CGArenaTeamInfo::EnterWorld() { + CGArenaTeamInfo::UpdateTeams(0); +} diff --git a/WoW/Source/Ui/ArenaTeamInfo.h b/WoW/Source/Ui/ArenaTeamInfo.h index 161eaef..ad28259 100644 --- a/WoW/Source/Ui/ArenaTeamInfo.h +++ b/WoW/Source/Ui/ArenaTeamInfo.h @@ -56,6 +56,8 @@ class CGArenaTeamInfo { static WOWGUID m_selectedMember; static void EnterWorld(); static void InitializeGame(); + static void QueryRoster(uint32_t index); + static void UpdateTeams(int32_t signal); static bool CheckPersonalAndTeamRating(uint32_t rating, int32_t bracket); }; diff --git a/WoW/Source/Ui/AuctionHouse.h b/WoW/Source/Ui/AuctionHouse.h index 867b636..d28cf06 100644 --- a/WoW/Source/Ui/AuctionHouse.h +++ b/WoW/Source/Ui/AuctionHouse.h @@ -7,6 +7,7 @@ #include "WoW/Source/Net/Types.h" class CDataStore; +class CGItem_C; struct lua_State; struct AuctionSortCriteria { @@ -96,6 +97,9 @@ class CGAuctionHouse { static void EnterWorld(); static void InitializeGame(); static uint8_t m_auctionsTabShowing; + static bool IsSellItemValid(CGItem_C* item, int32_t showError); + static void GetSellItem(WOWGUID* item, uint8_t* bag, uint8_t* slot); + static void SetSellItem(WOWGUID item, WOWGUID container, uint32_t slot); static int32_t m_auctionHouseID; }; diff --git a/WoW/Source/Ui/BarberShop.cpp b/WoW/Source/Ui/BarberShop.cpp index d1a3684..08429b7 100644 --- a/WoW/Source/Ui/BarberShop.cpp +++ b/WoW/Source/Ui/BarberShop.cpp @@ -5,6 +5,10 @@ #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/GameUI.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" // STATIC: 0x00BD19B8 int32_t CGBarberShop::m_barberShopEnabled; @@ -18,8 +22,17 @@ uint8_t CGBarberShop::m_initialized; // STATIC: 0x00BD19BB uint8_t CGBarberShop::m_resetPortrait; +// STATIC: 0x00BD19AC +STYLEREC* CGBarberShop::m_currentHairStyle; + +// STATIC: 0x00BD19B0 +STYLEREC* CGBarberShop::m_currentFacialHair; + // STATIC: 0x00BD19B4 -int32_t CGBarberShop::m_currentSkinColor; +STYLEREC* CGBarberShop::m_currentSkinColor; + +// STATIC: 0x00BD19C4 +TSHashTable CGBarberShop::m_useableStyles; // VERIFY: 28b6e499 auto // OFFSET: 0x0052E480 @@ -65,3 +78,58 @@ void CGBarberShop::InitializeGame() { ClientServices::SetMessageHandler(SMSG_BARBER_SHOP_RESULT, Packet_SMSG_BARBER_SHOP_RESULT, nullptr); CGBarberShop::m_initialized = 0; } + +// VERIFY: d45ddf6d manual +// OFFSET: 0x0052F760 +STYLEREC* CGBarberShop::GetStyle(int32_t type, int32_t race, int32_t sex, int32_t data) { + HASHKEY_NONE key; + USEABLESTYLE* useable = CGBarberShop::m_useableStyles.Ptr(type, key); + + if (!useable) { + return nullptr; + } + + for (STYLEREC* style = useable->m_styles.Head(); !useable->m_styles.IsEnd(style); style = useable->m_styles.RawNext(style)) { + const BarberShopStyleRec* rec = style->m_rec; + + if (rec->m_race == race && (rec->m_sex == sex || rec->m_sex == -1) && rec->m_data == data) { + return style; + } + } + + return nullptr; +} + +// VERIFY: fdac6219 manual +// OFFSET: 0x0052FE90 +void CGBarberShop::EnterWorld() { + if (CGBarberShop::m_initialized) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + int32_t race = player->m_unit->m_unitFieldBytes0[0]; + int32_t sex = player->m_player->m_playerBytes3[0]; + + for (int32_t i = 0; i < g_barberShopStyleDB.m_numRecords; i++) { + BarberShopStyleRec* rec = g_barberShopStyleDB.GetRecordByIndex(i); + + if (!rec || rec->m_race != race || (rec->m_sex != sex && rec->m_sex != -1)) { + continue; + } + + HASHKEY_NONE key; + USEABLESTYLE* useable = CGBarberShop::m_useableStyles.Ptr(rec->m_type, key); + + if (!useable) { + useable = CGBarberShop::m_useableStyles.New(rec->m_type, key, 0, 0); + } + + STYLEREC* style = useable->m_styles.NewNode(2, 0, 0); + style->m_rec = rec; + } + + CGBarberShop::m_currentHairStyle = CGBarberShop::GetStyle(0, player->m_unit->m_unitFieldBytes0[0], player->m_player->m_playerBytes3[0], player->m_player->m_playerBytes[2]); + CGBarberShop::m_currentFacialHair = CGBarberShop::GetStyle(2, player->m_unit->m_unitFieldBytes0[0], player->m_player->m_playerBytes3[0], player->m_player->m_playerBytes2[0]); + CGBarberShop::m_currentSkinColor = CGBarberShop::GetStyle(3, player->m_unit->m_unitFieldBytes0[0], player->m_player->m_playerBytes3[0], player->m_player->m_playerBytes[0]); +} diff --git a/WoW/Source/Ui/BarberShop.h b/WoW/Source/Ui/BarberShop.h index 68eb460..c26a195 100644 --- a/WoW/Source/Ui/BarberShop.h +++ b/WoW/Source/Ui/BarberShop.h @@ -3,7 +3,9 @@ #include #include +#include "Engine/Source/Storm/H/stpl.h" #include "WoW/Source/Net/Types.h" +#include "WoW/Source/Ui/USEABLESTYLE.h" struct lua_State; @@ -15,11 +17,15 @@ int32_t Packet_SMSG_BARBER_SHOP_RESULT(void* param, NETMESSAGE msgId, uint32_t t class CGBarberShop { public: static void EnterWorld(); + static STYLEREC* GetStyle(int32_t type, int32_t race, int32_t sex, int32_t data); static float GetMinCameraDistance(); static int32_t m_barberShopEnabled; static float m_minCameraDistance; static uint8_t m_resetPortrait; - static int32_t m_currentSkinColor; + static STYLEREC* m_currentHairStyle; + static STYLEREC* m_currentFacialHair; + static STYLEREC* m_currentSkinColor; + static TSHashTable m_useableStyles; static uint8_t m_initialized; static void AppearanceApplied(); diff --git a/WoW/Source/Ui/BattlefieldInfo.cpp b/WoW/Source/Ui/BattlefieldInfo.cpp index 51d3650..76dfb7b 100644 --- a/WoW/Source/Ui/BattlefieldInfo.cpp +++ b/WoW/Source/Ui/BattlefieldInfo.cpp @@ -1,4 +1,8 @@ #include "BattlefieldInfo.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/BattlemasterListRec.h" +#include "WoW/Source/DB/Rec/PvpDifficultyRec.h" +#include "WoW/Source/Ui/PartyFrame.h" #include "WoW/Source/Object/ObjectClient/Unit_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include @@ -31,6 +35,9 @@ WOWGUID CGBattlefieldInfo::m_arenaOpponentPets[5][2]; // STATIC: 0x00BE9F48 WOWGUID CGBattlefieldInfo::m_arenaOpponents[5]; +// STATIC: 0x00BE8F90 +CGPartyMemberState CGBattlefieldInfo::m_arenaOpponentStats[5]; + // STATIC: 0x00BEA580 uint32_t CGBattlefieldInfo::m_numScores; @@ -460,3 +467,96 @@ void CGBattlefieldInfo::SetBattlemaster(WOWGUID battlemaster) { CGGameUI::ClearInteractTarget(CGBattlefieldInfo::m_battlemaster, 0); CGBattlefieldInfo::m_battlemaster = WOWGUID(); } + +// VERIFY: 3c940682 manual +// OFFSET: 0x005497C0 +CGPartyMemberState* CGBattlefieldInfo::GetRemoteStats(const WOWGUID& guid) { + if (!guid) { + return nullptr; + } + + for (uint32_t i = 0; i < 5; i++) { + if (CGBattlefieldInfo::m_arenaOpponents[i] == guid) { + return &CGBattlefieldInfo::m_arenaOpponentStats[i]; + } + } + + return nullptr; +} + +// VERIFY: f926b6be manual +// OFFSET: 0x00549860 +CGPartyPetState* CGBattlefieldInfo::GetRemotePetStats(const WOWGUID& guid) { + if (!guid) { + return nullptr; + } + + for (uint32_t i = 0; i < 5; i++) { + if (CGBattlefieldInfo::m_arenaOpponents[i] && CGBattlefieldInfo::m_arenaOpponentStats[i].m_pet.m_guid == guid) { + return &CGBattlefieldInfo::m_arenaOpponentStats[i].m_pet; + } + } + + return nullptr; +} + +// VERIFY: e2ac477e manual +// OFFSET: 0x0054A510 +int32_t CGBattlefieldInfo::GetBattlegroundType(int32_t index) { + if (index >= static_cast(CGBattlefieldInfo::m_battlegroundTypes.m_count)) { + return 0; + } + + return CGBattlefieldInfo::m_battlegroundTypes.m_data[index]; +} + +// VERIFY: 072dadd4 manual +// OFFSET: 0x0054BA00 +bool CGBattlefieldInfo::GetBracketForLevel(uint32_t level, const BattlemasterListRec* rec, int32_t* bracket) { + if (!rec || !bracket) { + return false; + } + + *bracket = 0; + + if (rec->m_id == 32) { + *bracket = 0; + return level == 80; + } + + bool foundMap = false; + + for (int32_t i = 0; i < g_pvpDifficultyDB.m_numRecords; i++) { + PvpDifficultyRec* difficulty = g_pvpDifficultyDB.GetRecordByIndex(i); + + if (!difficulty || difficulty->m_mapID != rec->m_mapID[0]) { + if (foundMap) { + return false; + } + + continue; + } + + if (level >= static_cast(difficulty->m_minLevel) && level <= static_cast(difficulty->m_maxLevel)) { + *bracket = difficulty->m_rangeIndex; + return true; + } + + foundMap = true; + } + + return false; +} + +// VERIFY: 1d516d84 manual +// OFFSET: 0x006CF670 +int32_t CGBattlefieldInfo::GetArenaOpponentIndex(const WOWGUID& guid, int32_t* index) { + for (int32_t i = 0; i < 5; i++) { + if (CGBattlefieldInfo::m_arenaOpponents[i] == guid) { + *index = i; + return 1; + } + } + + return 0; +} diff --git a/WoW/Source/Ui/BattlefieldInfo.h b/WoW/Source/Ui/BattlefieldInfo.h index f4ad4d6..94466b7 100644 --- a/WoW/Source/Ui/BattlefieldInfo.h +++ b/WoW/Source/Ui/BattlefieldInfo.h @@ -9,6 +9,7 @@ #include "Engine/Source/Tempest/C3Vector.h" #include "WoW/Source/Net/Types.h" +class BattlemasterListRec; class CGPartyMemberState; class CGPartyPetState; struct lua_State; @@ -75,6 +76,7 @@ class CGBattlefieldInfo { static void InitializeGame(); static WOWGUID m_arenaOpponentPets[5][2]; static WOWGUID m_arenaOpponents[5]; + static CGPartyMemberState m_arenaOpponentStats[5]; static int32_t m_instanceType; static int32_t m_activeIndex; static BattlefieldStatus m_status[2]; @@ -126,6 +128,8 @@ class CGBattlefieldInfo { static TSGrowableArray m_battlegroundTypes; static void AddArenaOpponent(const WOWGUID& guid); + static int32_t GetBattlegroundType(int32_t index); + static bool GetBracketForLevel(uint32_t level, const BattlemasterListRec* rec, int32_t* bracket); static void AddVehicle(const WOWGUID& guid); static void AddArenaOpponentPet(const WOWGUID& petGuid, const WOWGUID& ownerGuid); static WOWGUID GetArenaOpponent(uint32_t index); @@ -139,7 +143,6 @@ class CGBattlefieldInfo { uint32_t GetArenaPetGUIDCount(); -int32_t Script_GetBattlefieldInfo(lua_State* L); int32_t Script_JoinBattlefield(lua_State* L); int32_t Script_AcceptBattlefieldPort(lua_State* L); int32_t Script_CloseBattlefield(lua_State* L); @@ -151,7 +154,6 @@ int32_t Script_GetBattlefieldFlagPosition(lua_State* L); int32_t Script_GetBattlefieldVehicleInfo(lua_State* L); int32_t Script_SortBattlefieldScoreData(lua_State* L); int32_t Script_CanHearthAndResurrectFromArea(lua_State* L); -int32_t Script_GetBattlegroundInfo(lua_State* L); int32_t Script_RequestBattlegroundInstanceInfo(lua_State* L); int32_t Script_BattlefieldMgrEntryInviteResponse(lua_State* L); int32_t Script_BattlefieldMgrQueueRequest(lua_State* L); diff --git a/WoW/Source/Ui/BattlefieldInfo_Scripts.cpp b/WoW/Source/Ui/BattlefieldInfo_Scripts.cpp index 311ed2e..fe49316 100644 --- a/WoW/Source/Ui/BattlefieldInfo_Scripts.cpp +++ b/WoW/Source/Ui/BattlefieldInfo_Scripts.cpp @@ -1,4 +1,5 @@ #include "BattlefieldInfo.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" #include #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" @@ -582,6 +583,106 @@ static int32_t Script_RequestBattlefieldPositions(lua_State* L) { return 0; } +// VERIFY: 9f46881d manual +// OFFSET: 0x0054D770 +static int32_t Script_GetBattlefieldInfo(lua_State* L) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return 0; + } + + BattlemasterListRec* rec = g_battlemasterListDB.GetRecord(CGBattlefieldInfo::m_bgTypeID); + + if (!rec) { + return 0; + } + + MapRec* map = g_mapDB.GetRecord(rec->m_mapID[0]); + + if (!map) { + return 0; + } + + lua_checkstack(L, 10); + lua_pushstring(L, rec->m_name); + int32_t faction = player->GetPVPFactionIndex(); + + if (faction == 0) { + lua_pushstring(L, map->m_mapDescription0); + } else if (faction == 1) { + lua_pushstring(L, map->m_mapDescription1); + } + + lua_pushnumber(L, rec->m_maxGroupSize); + int32_t bracket; + + if (CGBattlefieldInfo::GetBracketForLevel(player->m_unit->m_unitFieldLevel, rec, &bracket)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (GetWorldState(rec->m_holidayWorldState)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (rec->m_id == 32) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 6; +} + +// VERIFY: b5c47118 manual +// OFFSET: 0x0054E010 +static int32_t Script_GetBattlegroundInfo(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetBattlegroundInfo(index)"); + } + + int32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || index < 0 || index >= static_cast(CGBattlefieldInfo::m_battlegroundTypes.m_count)) { + return 0; + } + + BattlemasterListRec* rec = g_battlemasterListDB.GetRecord(CGBattlefieldInfo::GetBattlegroundType(index)); + + if (!rec) { + return 0; + } + + lua_pushstring(L, rec->m_name); + int32_t bracket; + + if (CGBattlefieldInfo::GetBracketForLevel(player->m_unit->m_unitFieldLevel, rec, &bracket)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (GetWorldState(rec->m_holidayWorldState)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (rec->m_id == 32) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, rec->m_id); + return 5; +} + // STATIC: 0x00ACD178 static FrameScript_Method s_ScriptFunctions[] = { { "GetNumBattlefields", &Script_GetNumBattlefields }, diff --git a/WoW/Source/Ui/BattlenetUI.cpp b/WoW/Source/Ui/BattlenetUI.cpp index d2171c7..5a16096 100644 --- a/WoW/Source/Ui/BattlenetUI.cpp +++ b/WoW/Source/Ui/BattlenetUI.cpp @@ -1 +1,18 @@ #include "BattlenetUI.h" + +// STATIC: 0x00BD1B00 +int32_t BattlenetUI::unk_BD1B00; + +// STATIC: 0x00BD1B05 +uint8_t BattlenetUI::m_friendListLoaded; + +// STATIC: 0x00BD1B28 +uint32_t BattlenetUI::m_numFriends; + +// VERIFY: 79b13a59 auto +// OFFSET: 0x00532890 +void BattlenetUI_LeaveRealm() { + BattlenetUI::m_friendListLoaded = 0; + BattlenetUI::m_numFriends = 0; + BattlenetUI::unk_BD1B00 = 0; +} diff --git a/WoW/Source/Ui/BattlenetUI.h b/WoW/Source/Ui/BattlenetUI.h index f6b2ab7..94a3011 100644 --- a/WoW/Source/Ui/BattlenetUI.h +++ b/WoW/Source/Ui/BattlenetUI.h @@ -8,6 +8,10 @@ struct lua_State; class BattlenetUI { public: + static int32_t unk_BD1B00; + static uint8_t m_friendListLoaded; + static uint32_t m_numFriends; + /* 0000 */ uint8_t unk_0000 [4]; /* 0004 */ int32_t unk_0004; /* 0008 */ int32_t unk_0008; diff --git a/WoW/Source/Ui/CGAutoCompleteName.h b/WoW/Source/Ui/CGAutoCompleteName.h index 0a4daa7..1daa3ec 100644 --- a/WoW/Source/Ui/CGAutoCompleteName.h +++ b/WoW/Source/Ui/CGAutoCompleteName.h @@ -9,6 +9,7 @@ struct lua_State; class CGAutoCompleteName { public: static bool s_resortNamesOnRecency; + static void RemoveFlagsByName(const char* name, uint32_t flags, int32_t a3, int32_t a4); static bool s_whenEditingFromCenter; static bool s_useContext; diff --git a/WoW/Source/Ui/CGLookingForGroup.cpp b/WoW/Source/Ui/CGLookingForGroup.cpp index fe3f430..ffde2e2 100644 --- a/WoW/Source/Ui/CGLookingForGroup.cpp +++ b/WoW/Source/Ui/CGLookingForGroup.cpp @@ -1,4 +1,9 @@ #include "LFGInfo.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/lua-5.1/src/lauxlib.h" +#include "Engine/Source/lua-5.1/src/lua.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" // STATIC: 0x00A394B0 static const uint8_t s_classRoles[11] = { 0x0B, 0x0F, 0x09, 0x09, 0x0D, 0x0B, 0x0D, 0x09, 0x09, 0x00, 0x0F }; @@ -8,3 +13,56 @@ static const uint8_t s_classRoles[11] = { 0x0B, 0x0F, 0x09, 0x09, 0x0D, 0x0B, 0x uint8_t CGLookingForGroup::GetClassRoles(uint32_t classID) { return s_classRoles[classID - 1]; } + +// VERIFY: 29999d79 manual +// OFFSET: 0x00555920 +void CGLookingForGroup::RequestLFGStatus() { + CDataStore msg; + msg.Put(static_cast(CMSG_DF_GET_JOIN_STATUS)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 4918a5f7 manual +// OFFSET: 0x00555990 +void CGLookingForGroup::RequestLFGPlayerInfo() { + CDataStore msg; + msg.Put(static_cast(CMSG_LFG_PLAYER_LOCK_INFO_REQUEST)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 40d9d329 auto +// OFFSET: 0x00557240 +void CGLookingForGroup::EnterWorld() { + CGLookingForGroup::m_lastProposalID = 0; + CGLookingForGroup::RequestLFGStatus(); + CGLookingForGroup::RequestLFGPlayerInfo(); +} + +// VERIFY: 49ccd8f7 manual +// OFFSET: 0x00554610 +int32_t CGLookingForGroup::GetLFGRoleUpdate(lua_State* L) { + lua_pushboolean(L, CGLookingForGroup::m_roleCheckState == 2); + lua_pushnumber(L, CGLookingForGroup::m_roleCheckSlots.m_count); + lua_pushnumber(L, CGLookingForGroup::m_roleCheckMembers.m_count); + return 3; +} + +// VERIFY: b42e78a8 auto +// OFFSET: 0x00554690 +int32_t CGLookingForGroup::GetLFGRoleUpdateSlot(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetLFGRoleUpdateSlot(index)"); + } + + int32_t index = static_cast(lua_tonumber(L, 1)) - 1; + + if (index < 0 || index >= static_cast(CGLookingForGroup::m_roleCheckSlots.m_count)) { + return 0; + } + + lua_pushnumber(L, CGLookingForGroup::m_roleCheckSlots.m_data[index] >> 24); + lua_pushnumber(L, CGLookingForGroup::m_roleCheckSlots.m_data[index] & 0xFFFFFF); + return 2; +} diff --git a/WoW/Source/Ui/CGWorldStateInfo.cpp b/WoW/Source/Ui/CGWorldStateInfo.cpp index f2206f4..75ee74b 100644 --- a/WoW/Source/Ui/CGWorldStateInfo.cpp +++ b/WoW/Source/Ui/CGWorldStateInfo.cpp @@ -1,5 +1,10 @@ #include "CGWorldStateInfo.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/Os/TimeManager.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include // STATIC: 0x00BE8F40 @@ -20,6 +25,9 @@ int32_t CGWorldStateInfo::m_mapID; // STATIC: 0x00BE8F58 TSHashTable CGWorldStateInfo::m_worldStates; +// STATIC: 0x00BE8F80 +TSGrowableArray CGWorldStateInfo::m_worldStateUI; + // VERIFY: 50fb45a8 auto // OFFSET: 0x00548570 void CGWorldStateInfo::InitializeGame() { @@ -47,3 +55,36 @@ int32_t GetWorldState(int32_t id) { return 0; } + +// VERIFY: 8d223bd3 manual +// OFFSET: 0x00548760 +static void SendWorldStateUITimerUpdate() { + CDataStore msg; + msg.Put(static_cast(CMSG_UI_TIME_REQUEST)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: eeea7d70 auto +// OFFSET: 0x005488F0 +void CheckEventWorldStateUITimerUpdate() { + uint32_t now = OsGetAsyncTimeMs(); + + if (static_cast(now - CGWorldStateInfo::m_nextUITimeUpdate) >= 0) { + CGWorldStateInfo::m_nextUITimeUpdate = now + 20000; + SendWorldStateUITimerUpdate(); + } + + if (static_cast(now - CGWorldStateInfo::m_nextUpdateTime) < 0) { + return; + } + + CGWorldStateInfo::m_nextUpdateTime = now + 1000; + + for (uint32_t i = 0; i < CGWorldStateInfo::m_worldStateUI.m_count; i++) { + if (CGWorldStateInfo::m_worldStateUI.m_data[i].m_state == 3) { + FrameScript_SignalEvent(SCRIPT_EVENT_WORLD_STATE_UI_TIMER_UPDATE, nullptr); + return; + } + } +} diff --git a/WoW/Source/Ui/CGWorldStateInfo.h b/WoW/Source/Ui/CGWorldStateInfo.h index 3ccd4f5..899ddcd 100644 --- a/WoW/Source/Ui/CGWorldStateInfo.h +++ b/WoW/Source/Ui/CGWorldStateInfo.h @@ -11,6 +11,11 @@ struct WORLDSTATE : public TSHashObject { /* 0018 */ int32_t m_value; }; +struct WorldStateUIEntry { + /* 0000 */ int32_t m_id; + /* 0004 */ int32_t m_state; +}; + int32_t GetWorldState(int32_t id); class CGWorldStateInfo { @@ -21,12 +26,12 @@ class CGWorldStateInfo { static uint32_t m_UITimeOffset; static uint32_t m_nextUITimeUpdate; static TSHashTable m_worldStates; + static TSGrowableArray m_worldStateUI; static int32_t GetUITime(); static void InitializeGame(); }; -int32_t Script_GetNumWorldStateUI(lua_State* L); int32_t Script_GetWorldStateUIInfo(lua_State* L); void WorldStateInfoRegisterScriptFunctions(); diff --git a/WoW/Source/Ui/CGWorldStateInfo_Scripts.cpp b/WoW/Source/Ui/CGWorldStateInfo_Scripts.cpp index 59bc068..b8dfdd5 100644 --- a/WoW/Source/Ui/CGWorldStateInfo_Scripts.cpp +++ b/WoW/Source/Ui/CGWorldStateInfo_Scripts.cpp @@ -2,6 +2,14 @@ #include #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" +#include "Engine/Source/lua-5.1/src/lua.h" + +// VERIFY: f57c55c3 manual +// OFFSET: 0x00548720 +static int32_t Script_GetNumWorldStateUI(lua_State* L) { + lua_pushnumber(L, CGWorldStateInfo::m_worldStateUI.m_count); + return 1; +} // STATIC: 0x00ACD0D0 static FrameScript_Method s_ScriptFunctions[] = { diff --git a/WoW/Source/Ui/Calendar.cpp b/WoW/Source/Ui/Calendar.cpp index 700b575..5e67bfe 100644 --- a/WoW/Source/Ui/Calendar.cpp +++ b/WoW/Source/Ui/Calendar.cpp @@ -3,6 +3,24 @@ #include "WoW/Source/DB/Rec/HolidayNamesRec.h" #include "WoW/Source/DB/Rec/HolidaysRec.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include +#include +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/Rec/FactionTemplateRec.h" +#include "WoW/Source/DB/Rec/LfgDungeonsRec.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Object/Unit.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/Types.h" + +// STATIC: 0x00AD0350 +static CalendarEventClipboard s_eventClipboard; + +// STATIC: 0x00C20F60 +static TSFixedArray s_eventTextures[2]; // STATIC: 0x00C207EC CGCalendarEvent* CGCalendar::m_curEvent; @@ -65,3 +83,106 @@ const char* GetHolidayName(int32_t holidayId) { HolidayNamesRec* name = g_holidayNamesDB.GetRecord(holiday->m_holidayNameID); return name ? name->m_name : nullptr; } + +// VERIFY: 0d10e0e8 auto +// OFFSET: 0x005B8E50 +static int32_t QSortTextures(const void* a, const void* b) { + LfgDungeonsRec* recA = g_lfgDungeonsDB.GetRecord(*static_cast(a)); + LfgDungeonsRec* recB = g_lfgDungeonsDB.GetRecord(*static_cast(b)); + int32_t result = recB->m_expansionLevel - recA->m_expansionLevel; + + if (!result) { + return SStrSortUTF8I(recA->m_name, recB->m_name, STORM_MAX_STR); + } + + return result; +} + +// VERIFY: de197260 manual +// OFFSET: 0x005BBBB0 +void CGCalendar::QueryPendingInvites() { + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_GET_NUM_PENDING)); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 9ea81fd7 manual +// OFFSET: 0x005BE2A0 +void CGCalendar::EnterWorld() { + CGCalendar::m_actionPending = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 0); + + if (!CGCalendar::m_initialize) { + return; + } + + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + memset(&s_eventClipboard, 0, sizeof(s_eventClipboard)); + CGCalendar::QueryPendingInvites(); + + uint32_t counts[2] = { 0, 0 }; + int32_t numRecords = g_lfgDungeonsDB.m_numRecords; + + for (int32_t i = 0; i < numRecords; i++) { + LfgDungeonsRec* rec = g_lfgDungeonsDB.GetRecordByIndex(i); + + if (!rec) { + continue; + } + + if (rec->m_faction >= 0) { + FactionTemplateRec* faction = g_factionTemplateDB.GetRecord(player->m_unit->m_unitFieldFactiontemplate); + int32_t group = (faction->m_factionGroup & 0x4) ? 0 : ((faction->m_factionGroup & 0x2) ? 1 : -1); + + if (group != rec->m_faction) { + continue; + } + } + + if (rec->m_typeID == 1) { + counts[0]++; + } else if (rec->m_typeID == 2) { + counts[1]++; + } + } + + for (uint32_t i = 0; i < 2; i++) { + s_eventTextures[i].SetCount(counts[i]); + } + + counts[0] = 0; + counts[1] = 0; + + for (int32_t i = 0; i < numRecords; i++) { + LfgDungeonsRec* rec = g_lfgDungeonsDB.GetRecordByIndex(i); + + if (!rec) { + continue; + } + + if (rec->m_faction >= 0) { + FactionTemplateRec* faction = g_factionTemplateDB.GetRecord(player->m_unit->m_unitFieldFactiontemplate); + int32_t group = (faction->m_factionGroup & 0x4) ? 0 : ((faction->m_factionGroup & 0x2) ? 1 : -1); + + if (group != rec->m_faction) { + continue; + } + } + + if (rec->m_typeID == 1) { + s_eventTextures[0].m_data[counts[0]++] = rec->m_id; + } else if (rec->m_typeID == 2) { + s_eventTextures[1].m_data[counts[1]++] = rec->m_id; + } + } + + qsort(s_eventTextures[0].m_data, counts[0], sizeof(int32_t), QSortTextures); + qsort(s_eventTextures[1].m_data, counts[1], sizeof(int32_t), QSortTextures); + CGCalendar::m_initialize = 0; +} diff --git a/WoW/Source/Ui/Calendar.h b/WoW/Source/Ui/Calendar.h index 69da82c..2693d1f 100644 --- a/WoW/Source/Ui/Calendar.h +++ b/WoW/Source/Ui/Calendar.h @@ -9,18 +9,26 @@ class CGCalendarEvent; class CVar; struct lua_State; +struct CalendarEventClipboard { + /* 0000 */ uint64_t m_eventID; + /* 0008 */ uint8_t unk_0008[200]; +}; + int32_t PH_CALENDAR_GROUP(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); class CGCalendar { public: - static void EnterWorld(); static uint8_t m_actionPending; + static void CalendarError(const char* error, int32_t a2); static CGCalendarEvent* m_curEvent; static uint8_t m_initialize; static uint8_t m_openedCalendar; static uint8_t unk_C207F2; static int32_t m_numInitialPending; + + static void EnterWorld(); static void InitializeGame(); + static void QueryPendingInvites(); static void SetFilter(CVar* var, int32_t value); }; diff --git a/WoW/Source/Ui/ChatBubbleFrame.cpp b/WoW/Source/Ui/ChatBubbleFrame.cpp index b9bdbb6..1822dae 100644 --- a/WoW/Source/Ui/ChatBubbleFrame.cpp +++ b/WoW/Source/Ui/ChatBubbleFrame.cpp @@ -1,6 +1,445 @@ #include "ChatBubbleFrame.h" +#include +#include +#include +#include "Engine/Source/Frame/CBackdropGenerator.h" +#include "Engine/Source/Frame/CSimpleRender.h" +#include "Engine/Source/Frame/CSimpleTexture.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CImVector.h" +#include "WoW/Source/Client.h" +#include "WoW/Source/Game/ValidateName.h" +#include "Engine/Source/Base/Coordinate.h" +#include "Engine/Source/Frame/CLayoutFrame.h" +#include "Engine/Source/Frame/CScriptRegion.h" +#include "Engine/Source/Frame/CSimpleTop.h" +#include "Engine/Source/Model2/M2Model.h" +#include "Engine/Source/Os/TimeManager.h" +#include "WoW/Source/Object/ObjectClient/Object_C.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Object/ObjectClient/VehiclePassenger_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/UIUtil/Camera.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/WorldFrame.h" + +// STATIC: 0x00ACE5EC +static TSList s_freeChatBubbles; + +// STATIC: 0x00ACE5F8 +static TSList s_chatBubbles; + +// STATIC: 0x00BEAFBC +static uint8_t s_cameraPositionValid; + +// STATIC: 0x00BEAFC0 +static C3Vector s_cameraPosition; + +// STATIC: 0x00BEAFD4 +CDataAllocator CGChatBubbleFrame::s_chatBubbleHeap(sizeof(CGChatBubbleFrame), 10); + +// INLINED +void CGChatBubbleFrame::operator delete(void* ptr) { + CGChatBubbleFrame::s_chatBubbleHeap.PutData(ptr, nullptr, 0); +} // VERIFY: 20523c8e auto // OFFSET: 0x005EEB70 void CGChatBubbleFrame::InitializeGame() { } + +// VERIFY: 8d8d616f manual +// OFFSET: 0x0056C240 +void CGChatBubbleFrame::FadeIn() { + if (this->m_bubbleFlags & 0x5) { + return; + } + + uint8_t alpha = this->m_alpha; + this->m_bubbleFlags = (this->m_bubbleFlags & ~0x3) | 0x1; + this->m_fadeStart = OsGetAsyncTimeMs() - static_cast(alpha * (1.0f / 255.0f) * 250.0f); +} + +// VERIFY: 2c21f0ea manual +// OFFSET: 0x0056C2B0 +void CGChatBubbleFrame::FadeOut(bool remove) { + if (this->m_bubbleFlags & 0x4) { + return; + } + + if (remove) { + this->m_bubbleFlags |= 0x4; + } + + if (this->m_bubbleFlags & 0x2) { + return; + } + + uint8_t alpha = this->m_alpha; + this->m_bubbleFlags = (this->m_bubbleFlags & ~0x3) | 0x2; + this->m_fadeStart = OsGetAsyncTimeMs() - static_cast((255.0f - alpha) * (1.0f / 255.0f) * 250.0f); +} + +// VERIFY: 30574dc1 auto +// OFFSET: 0x0056C1C0 +static int32_t ComputeDuration(const char* text, bool self) { + int32_t perWord = self ? 500 : 750; + + if (!text || !*text) { + return 0; + } + + int32_t duration = perWord + (self ? 1000 : 2000); + bool lastWasSpace = true; + + for (const char* c = text; *c; c++) { + bool space = *c == ' ' || *c == '\t'; + + if (space && !lastWasSpace) { + duration += perWord; + } + + lastWasSpace = space; + } + + return duration; +} + +// VERIFY: 5706ad2a manual +// OFFSET: 0x0056C340 +void CGChatBubbleFrame::Render(CGWorldFrame* worldFrame) { + if (!ClntObjMgrObjectPtr(this->m_unit, TYPEMASK_UNIT, __FILE__, __LINE__) || !this->m_positionValid) { + return; + } + + C3Vector screen(0.0f, 0.0f, 0.0f); + float threshold = NDCToDDCWidth(1.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + uint32_t onScreen; + worldFrame->GetScreenCoordinates(this->m_worldPosition, &screen, &onScreen); + + if (!onScreen) { + return; + } + + screen.x = CSimpleTop::RoundToPixelWidth(screen.x); + screen.y = CSimpleTop::RoundToPixelHeight(screen.y); + screen.z -= worldFrame->m_layoutDepth; + bool moveX = threshold <= fabs(screen.x - this->m_screenX); + bool moveY = fabs(screen.y - this->m_screenY) >= threshold; + bool moveDepth = fabs(screen.z - this->m_screenDepth) >= threshold; + + if (moveX || moveY) { + if (moveX) { + this->m_screenX = screen.x; + } + + if (moveY) { + this->m_screenY = screen.y; + } + + this->m_fontString->SetPoint(FRAMEPOINT_BOTTOM, worldFrame, FRAMEPOINT_BOTTOMLEFT, this->m_screenX, this->m_screenY, 1); + } + + if (moveDepth) { + this->m_screenDepth = screen.z; + this->SetFrameDepth(screen.z, false); + } +} + +// VERIFY: aa475361 manual +// OFFSET: 0x0056C500 +bool CGChatBubbleFrame::Update(CGUnit_C* player, CGUnit_C* unit) { + if (!player) { + return false; + } + + CMapEntity* entity = unit->m_worldObject; + CM2Model* model = unit->m_worldModel; + + if (!entity || !model) { + return false; + } + + if (!model->IsLoaded(0, 0) || !(model->m_fFlags & 0x8000)) { + return true; + } + + if (CGGameUI::m_visible) { + this->Show(); + } else { + this->Hide(); + } + + C3Vector position = unit->IsInVehicle() ? unit->m_vehiclePassenger->ComputeInterpolatedUnitPosition() : unit->GetPosition(); + C3Vector delta = player->GetPosition() - position; + + if (World::QueryObjectVisible(entity) && delta.y * delta.y + delta.x * delta.x + delta.z * delta.z < 625.0f) { + if (this->GetEffectiveAlpha() != 255) { + this->FadeIn(); + } + } else if (this->GetEffectiveAlpha()) { + this->FadeOut(false); + } + + uint32_t now = OsGetAsyncTimeMs(); + + if (!(this->m_bubbleFlags & 0x2) && static_cast(now - this->m_showTime) > this->m_duration + 250) { + this->FadeOut(true); + } + + if (this->m_bubbleFlags & 0x1) { + uint32_t elapsed = now - this->m_fadeStart; + + if (elapsed >= 250) { + this->SetFrameAlpha(255); + this->m_bubbleFlags &= ~0x1; + } else { + uint32_t alpha = 255 * elapsed / 250; + this->SetFrameAlpha(static_cast(alpha > 255 ? 255 : alpha)); + } + } else if (this->m_bubbleFlags & 0x2) { + uint32_t elapsed = now - this->m_fadeStart; + + if (elapsed >= 250) { + if (this->m_bubbleFlags & 0x4) { + return false; + } + + this->m_bubbleFlags &= ~0x2; + this->SetFrameAlpha(0); + } else { + uint32_t alpha = 255 * elapsed / 250; + + if (alpha > 255) { + alpha = 255; + } + + this->SetFrameAlpha(static_cast(255 - alpha)); + } + } + + C3Vector attachment; + + if (unit->IsMounted()) { + attachment = unit->GetAttachmentPosition(29, nullptr); + } else { + attachment = unit->GetAttachmentPosition(18, nullptr); + } + + this->m_height = attachment.z - unit->GetModelPosition().z; + this->m_worldPosition.x = position.x; + this->m_worldPosition.y = position.y; + this->m_positionValid = 1; + this->m_worldPosition.z = position.z + this->m_height + 0.7f; + return true; +} + +// VERIFY: 1309b080 manual +// OFFSET: 0x0056C7F0 +void CGChatBubbleFrame::Initialize(const WOWGUID& unit, const char* text, const CImVector& color) { + char buffer[3000]; + StripHyperlinks(LanguageProcess(text), buffer, sizeof(buffer)); + this->m_fontString->SetVertexColor(color); + this->m_fontString->SetText(buffer, 1); + this->m_fontString->SetWidth(0.0f); + this->m_fontString->SetHeight(0.0f); + + if (s_locale == 1) { + this->m_fontString->SetJustifyH(1); + } + + float minWidth = NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + minWidth += minWidth; + float width = this->m_fontString->GetWidth(); + + if (0.2f < width) { + width = 0.2f; + } else if (minWidth > width) { + width = minWidth; + } + + this->m_fontString->SetWidth(width); + this->m_positionValid = 0; + this->m_height = 0.0f; + this->m_worldPosition = C3Vector(0.0f, 0.0f, 0.0f); + this->m_showTime = OsGetAsyncTimeMs(); + this->m_duration = ComputeDuration(buffer, unit == ClntObjMgrGetActivePlayer()); + this->m_bubbleFlags = 0x8; + this->m_unit = unit; + this->SetFrameAlpha(0); + this->FadeIn(); +} + +// VERIFY: 42eb0c6b auto +// OFFSET: 0x0056C7A0 +void CGChatBubbleFrame::OnWorldRender(CGWorldFrame* worldFrame) { + CGChatBubbleFrame* next; + + for (CGChatBubbleFrame* bubble = s_chatBubbles.Head(); bubble; bubble = next) { + next = s_chatBubbles.Next(bubble); + bubble->Render(worldFrame); + } + + CLayoutFrame::ResizePending(); +} + +// VERIFY: be3c560f manual +// OFFSET: 0x0056CAD0 +CGChatBubbleFrame::CGChatBubbleFrame(CSimpleFrame* parent) : CSimpleFrame(parent) { + this->m_screenX = 0.0f; + this->m_screenY = 0.0f; + this->m_screenDepth = 0.0f; + this->m_worldPosition.x = 0.0f; + this->m_worldPosition.y = 0.0f; + this->m_worldPosition.z = 0.0f; + this->SetFrameFlag(0x40000, 1); + + void* data = SMemAlloc(sizeof(CBackdropGenerator), __FILE__, __LINE__, 0); + CBackdropGenerator* backdrop = data ? new (data) CBackdropGenerator() : nullptr; + backdrop->m_bgFile.Copy("Interface\\Tooltips\\ChatBubble-Background"); + backdrop->m_pieces = 0xFF; + backdrop->m_tile = 1; + backdrop->m_edgeFile.Copy("Interface\\Tooltips\\ChatBubble-Backdrop"); + backdrop->m_alphaMode = GxBlend_Alpha; + float inset = NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + backdrop->m_insetLeft = inset; + backdrop->m_insetRight = inset; + backdrop->m_insetTop = inset; + backdrop->m_insetBottom = inset; + backdrop->m_edgeSize = NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + backdrop->m_tileSize = NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + this->SetBackdrop(backdrop); + + void* textureData = CSimpleTexture::s_allocator.GetData(0, typeid(CSimpleTexture).raw_name(), SLOG_OBJECT); + CSimpleTexture* tail = textureData ? new (textureData) CSimpleTexture(this, 2, 1) : nullptr; + tail->SetTexture("Interface\\Tooltips\\ChatBubble-Tail", 0, 0, CSimpleTexture::s_textureFilterMode, ImageMode_Normal); + tail->SetWidth(NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f))); + tail->SetHeight(NDCToDDCWidth(16.0f / (CoordinateGetAspectCompensation() * 1024.0f))); + tail->SetPoint(FRAMEPOINT_TOPRIGHT, this, FRAMEPOINT_BOTTOM, 0.0f, NDCToDDCWidth(4.0f / (CoordinateGetAspectCompensation() * 1024.0f)), 1); + + void* stringData = CSimpleFontString::s_allocator.GetData(0, typeid(CSimpleFontString).raw_name(), SLOG_OBJECT); + this->m_fontString = stringData ? new (stringData) CSimpleFontString(this, 2, 1) : nullptr; + this->m_fontString->SetFont(FrameScript_GetText("NAMEPLATE_FONT", -1, GENDER_NOT_APPLICABLE), 0.01f, 0, false); + this->m_fontString->SetNonSpaceWrap(1); + this->SetPoint(FRAMEPOINT_TOPLEFT, this->m_fontString, FRAMEPOINT_TOPLEFT, -0.01f, 0.01f, 1); + this->SetPoint(FRAMEPOINT_BOTTOMRIGHT, this->m_fontString, FRAMEPOINT_BOTTOMRIGHT, 0.01f, -0.01f, 1); +} + +// VERIFY: 4a39f013 auto +// OFFSET: 0x0056CDC0 +void CGChatBubbleFrame::ShutdownGame() { + s_freeChatBubbles.Clear(); + s_cameraPositionValid = 0; +} + +// OFFSET: 0x0056CDE0 +static void InsertSorted(CGChatBubbleFrame* bubble) { + for (CGChatBubbleFrame* node = s_chatBubbles.Head(); node; node = s_chatBubbles.Next(node)) { + if (static_cast(node->m_showTime - bubble->m_showTime) >= 0) { + s_chatBubbles.LinkNode(bubble, 2, node); + return; + } + } + + s_chatBubbles.LinkToTail(bubble); +} + +// VERIFY: d9dd76f6 auto +// OFFSET: 0x0056CEA0 +CGChatBubbleFrame* CGChatBubbleFrame::GetNewChatBubble(CSimpleFrame* parent) { + CGChatBubbleFrame* bubble = s_freeChatBubbles.Head(); + + if (!bubble) { + void* data = CGChatBubbleFrame::s_chatBubbleHeap.GetData(0, typeid(CGChatBubbleFrame).raw_name(), SLOG_OBJECT); + bubble = data ? new (data) CGChatBubbleFrame(parent) : nullptr; + } + + s_chatBubbles.LinkToTail(bubble); + return bubble; +} + +// VERIFY: ec937cd5 auto +// OFFSET: 0x0056CE80 +void CGChatBubbleFrame::Remove(CGChatBubbleFrame* bubble) { + bubble->Hide(); + s_freeChatBubbles.LinkToTail(bubble); +} + +// VERIFY: a296eb99 manual +// OFFSET: 0x0056CF80 +void CGChatBubbleFrame::ClearAll() { + CGChatBubbleFrame* next; + + for (CGChatBubbleFrame* bubble = s_chatBubbles.Head(); bubble; bubble = next) { + next = s_chatBubbles.Next(bubble); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(bubble->m_unit, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + unit->ChatBubbleRemove(); + } else { + CGChatBubbleFrame::Remove(bubble); + } + } +} + +// OFFSET: 0x0056D050 +void CGChatBubbleFrame::OnWorldLayerUpdate() { + if (!s_chatBubbles.Head()) { + return; + } + + C3Vector camera = CGWorldFrame::GetActiveCamera()->m_position; + bool cameraMoved = false; + + if (!s_cameraPositionValid || camera.x != s_cameraPosition.x || camera.y != s_cameraPosition.y || camera.z != s_cameraPosition.z) { + cameraMoved = true; + s_cameraPositionValid = 1; + s_cameraPosition = camera; + } + + TSList moved; + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + CGChatBubbleFrame* next; + + for (CGChatBubbleFrame* bubble = s_chatBubbles.Head(); bubble; bubble = next) { + next = s_chatBubbles.Next(bubble); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(bubble->m_unit, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + CGChatBubbleFrame::Remove(bubble); + continue; + } + + if (!bubble->Update(player, unit)) { + unit->ChatBubbleRemove(); + continue; + } + + if ((bubble->m_bubbleFlags & 0x8) || cameraMoved) { + moved.LinkToTail(bubble); + bubble->m_bubbleFlags &= ~0x8; + } + } + + if (!moved.Head()) { + return; + } + + for (CGChatBubbleFrame* bubble = moved.Head(); bubble; bubble = next) { + next = moved.Next(bubble); + InsertSorted(bubble); + } + + int32_t level = 2; + + for (CGChatBubbleFrame* bubble = s_chatBubbles.Head(); bubble; bubble = next) { + next = s_chatBubbles.Next(bubble); + bubble->SetFrameLevel(level++, 1); + } +} + +// VERIFY: 28f3deba manual +// OFFSET: 0x0098FFE0 +CGChatBubbleFrame::~CGChatBubbleFrame() { +} diff --git a/WoW/Source/Ui/ChatBubbleFrame.h b/WoW/Source/Ui/ChatBubbleFrame.h index 62d0cce..80e9b48 100644 --- a/WoW/Source/Ui/ChatBubbleFrame.h +++ b/WoW/Source/Ui/ChatBubbleFrame.h @@ -3,35 +3,51 @@ #include #include +#include "Engine/Source/Base/CDataAllocator.h" +#include "Engine/Source/Frame/CSimpleFrame.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "Engine/Source/Tempest/C3Vector.h" +#include "WoW/Source/Object/WGUID.h" +class CGUnit_C; class CGWorldFrame; +class CImVector; +class CSimpleFontString; -class CGChatBubbleFrame { +class CGChatBubbleFrame : public TSLinkedNode, public CSimpleFrame { public: + static CDataAllocator s_chatBubbleHeap; + + static void operator delete(void* ptr); + static void ClearAll(); + static CGChatBubbleFrame* GetNewChatBubble(CSimpleFrame* parent); static void OnWorldRender(CGWorldFrame* worldFrame); static void OnWorldLayerUpdate(); static void InitializeGame(); static void Remove(CGChatBubbleFrame* bubble); + static void ShutdownGame(); - /* 0000 */ uint32_t unk_0000; - /* 0004 */ uint8_t unk_0004[664]; - /* 029C */ uint32_t unk_029C[2]; - /* 02A4 */ uint32_t unk_02A4; - /* 02A8 */ uint32_t unk_02A8; - /* 02AC */ uint32_t unk_02AC; - /* 02B0 */ uint32_t unk_02B0; - /* 02B4 */ uint32_t unk_02B4; - /* 02B8 */ uint32_t unk_02B8; - /* 02BC */ uint32_t unk_02BC; - /* 02C0 */ uint32_t unk_02C0; - /* 02C4 */ uint32_t unk_02C4; - /* 02C8 */ uint32_t unk_02C8; - /* 02CC */ uint32_t unk_02CC; - /* 02D0 */ uint32_t unk_02D0; - /* 02D4 */ uint32_t unk_02D4; - /* 02D8 */ uint32_t unk_02D8; - /* 02DC */ uint8_t unk_02DC; - /* 02DD */ uint8_t unk_02DD[603]; + /* 02A4 */ CSimpleFontString* m_fontString; + /* 02A8 */ uint32_t m_bubbleFlags; + /* 02AC */ float m_screenX; + /* 02B0 */ float m_screenY; + /* 02B4 */ float m_screenDepth; + /* 02B8 */ C3Vector m_worldPosition; + /* 02C4 */ uint32_t m_showTime; + /* 02C8 */ uint32_t m_fadeStart; + /* 02CC */ int32_t m_duration; + /* 02D0 */ WOWGUID m_unit; + /* 02D8 */ float m_height; + /* 02DC */ uint8_t m_positionValid; + + ~CGChatBubbleFrame() override; + + CGChatBubbleFrame(CSimpleFrame* parent); + void FadeIn(); + void FadeOut(bool remove); + void Initialize(const WOWGUID& unit, const char* text, const CImVector& color); + void Render(CGWorldFrame* worldFrame); + bool Update(CGUnit_C* player, CGUnit_C* unit); }; #endif diff --git a/WoW/Source/Ui/ChatFrame.cpp b/WoW/Source/Ui/ChatFrame.cpp index bf5e4bb..46fcce4 100644 --- a/WoW/Source/Ui/ChatFrame.cpp +++ b/WoW/Source/Ui/ChatFrame.cpp @@ -8,6 +8,8 @@ #include "Engine/Source/ConsoleBase/ConsoleVar.h" #include "Engine/Source/Frame/CSimpleRender.h" #include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/FrameXML/LoadXML.h" +#include "Engine/Source/Os/OsFile.h" #include "Engine/Source/Os/TimeManager.h" #include "Engine/Source/Storm/H/storm.h" #include "Engine/Source/Tempest/CRandom.h" @@ -15,6 +17,7 @@ #include "WoW/Source/Client.h" #include "WoW/Source/DB/DBClient/DBCacheInstances.h" #include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/ChatChannelsRec.h" #include "WoW/Source/Game/GameClient/ComSatClient.h" #include "WoW/Source/Game/ValidateName.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" @@ -28,10 +31,13 @@ #include "WoW/Source/Ui/GameUI.h" #include "WoW/Source/Ui/RaidInfo.h" #include "WoW/Source/Ui/Tutorial.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Game/GameClient/NameCache.h" #include "WoW/Source/Ui/UILCD/LCD.h" #include "WoW/Source/WowServices/WDataStore.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/WowSvcs/WowSvcsClient/FriendList.h" +#include "Engine/Source/Tempest/CMath.h" // STATIC: 0x00BCEFEC int32_t CGChat::m_afk; @@ -319,7 +325,7 @@ static uint32_t s_activeDisplayChannelFlags; static int32_t s_displayChannelMemberCount; // STATIC: 0x00B743DC -static int32_t s_activeDisplayChannelType; +int32_t s_activeDisplayChannelType; // STATIC: 0x00B743E0 char CGChat::s_activeDisplayChannelName[128]; @@ -366,6 +372,39 @@ static TSFixedArray s_pendingUsers; // STATIC: 0x00AC7D48 TSExplicitList CGChat::s_pendingTextEmotes; +// STATIC: 0x00AC7A3C +int32_t CGChat::m_guildRecruitmentMode = 1; + +// STATIC: 0x00BCEFF0 +int32_t CGChat::m_areaID; + +// STATIC: 0x00AC7A54 +static const char* s_guildRecruitmentOption = "OPTION_GUILD_RECRUITMENT_CHANNEL"; + +// STATIC: 0x009FB9E8 +static const ZoneChannelDefault s_zoneChannelDefaults[1] = { { 26, 4 } }; + +// STATIC: 0x00B759E0 +static char s_recruitmentChannelName[128]; + +// STATIC: 0x00BCEFE0 +static int32_t s_chatSettingsDirty; + +// STATIC: 0x00BCF008 +static bool s_recruitmentChannelFound; + +// STATIC: 0x00BCF00C +static int32_t s_recruitmentChannelID; + +// STATIC: 0x00BCFAB0 +static TSGrowableArray s_pendingChannelNames; + +// STATIC: 0x00BCFAC0 +static TSGrowableArray s_pendingChannelFlags; + +// STATIC: 0x00BCFAD0 +static TSGrowableArray s_pendingChannelNumbers; + // VERIFY: 36ed0e4f auto // OFFSET: 0x004FBAF0 int32_t CGChat::IsVoiceChatAllowed() { @@ -1833,7 +1872,7 @@ int32_t CGChat::OnUpdateInstance(void* param, NETMESSAGE msgId, uint32_t time, C return 1; } -// VERIFY: 2d29df86 manual +// VERIFY: c0e57704 manual // OFFSET: 0x00501800 void ChatWindowInfo::Init() { CImVector color; @@ -1849,12 +1888,12 @@ void ChatWindowInfo::Init() { this->m_shown = 0; this->m_unkE4 = 0; this->m_color = color; - this->m_unkB0.SetCount(10); - this->m_unkC0.SetCount(10); + this->m_channels.SetCount(10); + this->m_channelIDs.SetCount(10); for (uint32_t i = 0; i < 10; i++) { - this->m_unkB0.m_data[i] = 0; - this->m_unkC0.m_data[i] = 0; + this->m_channels.m_data[i] = nullptr; + this->m_channelIDs.m_data[i] = 0; } this->m_unkE8 = 6; @@ -2729,7 +2768,7 @@ int32_t CGChat::OnChannelNotify(void* param, NETMESSAGE msgId, uint32_t time, CD return 1; } -// VERIFY: 50925462 manual +// VERIFY: 34edfdb5 manual // OFFSET: 0x0050EDD0 void CGChat::InitializeGame() { for (int32_t i = 0; i < g_languageWordsDB.m_numRecords; i++) { @@ -2840,7 +2879,7 @@ void CGChat::InitializeGame() { ClientServices::SetMessageHandler(SMSG_TITLE_EARNED, CGChat::OnTitleEarned, nullptr); ClientServices::SetMessageHandler(SMSG_RESET_FAILED_NOTIFY, CGChat::OnResetFailedNotify, nullptr); ClientServices::SetMessageHandler(SMSG_GM_MESSAGECHAT, CGChat::OnGMMessageChat, nullptr); - ClientServices::SetMessageHandler(SMSG_LOG_XP_GAIN, CGChat::OnLogXPGain, nullptr); + ClientServices::SetMessageHandler(SMSG_LOG_XP_GAIN, Packet_SMSG_LOG_XPGAIN, nullptr); ClientServices::SetMessageHandler(SMSG_DURABILITY_DAMAGE_DEATH, CGChat::OnDurabilityDamageDeath, nullptr); ClientServices::SetMessageHandler(SMSG_CHANNEL_MEMBER_COUNT, CGChat::OnChannelMemberCount, nullptr); ClientServices::SetMessageHandler(SMSG_COMSAT_RECONNECT_TRY, CGChat::OnComsatReconnectAttempt, nullptr); @@ -2854,6 +2893,140 @@ void CGChat::InitializeGame() { ClientServices::SetMessageHandler(SMSG_SERVER_FIRST_ACHIEVEMENT, CGChat::OnServerFirstAchievement, nullptr); } +// VERIFY: c17ad011 auto +// OFFSET: 0x0050B660 +void CGChat::OnLogXPGain(int32_t amount) { + char text[3000]; + SStrPrintf(text, sizeof(text), FrameScript_GetText("COMBATLOG_XPLOSS_FIRSTPERSON_UNNAMED", -1, GENDER_NOT_APPLICABLE), -amount); + CGChat::AddChatMessage(text, 33, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); +} + +// VERIFY: bb42bd2f manual +// OFFSET: 0x0050B1D0 +static void UnitCombatLogShowXPGained(CGUnit_C* unit, int32_t amount, float groupMult) { + char text[3000]; + int32_t base = static_cast(amount / groupMult); + + if (unit && (unit->m_obj->m_type & TYPEMASK_UNIT)) { + if (base == amount) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("COMBATLOG_XPGAIN_FIRSTPERSON", -1, GENDER_NOT_APPLICABLE), unit->GetUnitName(nullptr, 1), amount); + } else { + const char* token = base >= amount ? "COMBATLOG_XPGAIN_FIRSTPERSON_RAID" : "COMBATLOG_XPGAIN_FIRSTPERSON_GROUP"; + SStrPrintf(text, sizeof(text), FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), unit->GetUnitName(nullptr, 1), amount, abs(amount - base)); + } + } else if (base == amount) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED", -1, GENDER_NOT_APPLICABLE), amount); + } else { + const char* token = base >= amount ? "COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED_RAID" : "COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED_GROUP"; + SStrPrintf(text, sizeof(text), FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), amount, abs(amount - base)); + } + + CGChat::AddChatMessage(text, 33, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); +} + +// STATIC: 0x00AC7FB4 +static const char* s_exhaustionTokens[7] = { nullptr, "COMBATLOG_XPGAIN_EXHAUSTION1", "COMBATLOG_XPGAIN_EXHAUSTION2", "NULL", "COMBATLOG_XPGAIN_EXHAUSTION4", "COMBATLOG_XPGAIN_EXHAUSTION5", "COMBATLOG_XPGAIN_EXHAUSTION1" }; + +// VERIFY: 610143a3 manual +// OFFSET: 0x0050B300 +void CGChat::LogXPGain(CGUnit_C* unit, int32_t amount, int32_t type, int32_t bonus, float groupMult, bool referAFriend) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + player->AddWorldXPGainText(amount); + } + + if (unit && !type) { + if (!player) { + return; + } + + uint32_t restState = player->m_player->m_playerBytes2[3]; + + if (referAFriend) { + restState = 6; + } + + ExhaustionRec* exhaustion = g_exhaustionDB.GetRecord(restState); + + if (exhaustion && !fequal(exhaustion->m_factor, 0.0f) && !fequal(exhaustion->m_factor, 1.0f)) { + if (restState >= 7) { + SErrDisplayAppFatalMessage("", "", 0); + } + + char token[256]; + int32_t base = static_cast(bonus / groupMult); + + if (base == bonus) { + SStrCopy(token, s_exhaustionTokens[restState], sizeof(token)); + } else if (base < bonus) { + SStrPrintf(token, sizeof(token), "%s_GROUP", s_exhaustionTokens[restState]); + } else { + SStrPrintf(token, sizeof(token), "%s_RAID", s_exhaustionTokens[restState]); + } + + char bonusText[32]; + SStrPrintf(bonusText, sizeof(bonusText), "%s%d", amount - bonus >= 0 ? "+" : "", amount - bonus); + char text[3000]; + + if (base == bonus) { + SStrPrintf(text, sizeof(text), FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), unit->GetUnitName(nullptr, 1), amount, bonusText, exhaustion->m_name); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), unit->GetUnitName(nullptr, 1), amount, bonusText, exhaustion->m_name, abs(bonus - base)); + } + + CGChat::AddChatMessage(text, 33, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); + return; + } + + UnitCombatLogShowXPGained(unit, amount, groupMult); + return; + } + + if (!referAFriend || (type != 1 && type != 6)) { + UnitCombatLogShowXPGained(unit, amount, groupMult); + return; + } + + int32_t rafBonus = CMath::fint_(amount * 0.6666667f); + char bonusText[32]; + SStrPrintf(bonusText, sizeof(bonusText), "%s%d", rafBonus >= 0 ? "+" : "", rafBonus); + ExhaustionRec* exhaustion = g_exhaustionDB.GetRecord(6); + char text[3000]; + SStrPrintf(text, sizeof(text), FrameScript_GetText("COMBATLOG_XPGAIN_QUEST", -1, GENDER_NOT_APPLICABLE), amount, bonusText, exhaustion->m_name, rafBonus); + CGChat::AddChatMessage(text, 33, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID(), 0, WOWGUID(), 0, false, nullptr); +} + +// VERIFY: 294836e5 manual +// OFFSET: 0x0050C720 +int32_t Packet_SMSG_LOG_XPGAIN(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + WOWGUID guid = WOWGUID(); + msg->Get(guid.m_guid); + uint32_t amount = 0; + msg->Get(amount); + uint8_t type = 0; + msg->Get(type); + float groupMult = 1.0f; + uint32_t bonus = 0; + + if (!type) { + msg->Get(bonus); + msg->Get(groupMult); + } + + uint8_t referAFriend = 0; + msg->Get(referAFriend); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (guid == ClntObjMgrGetActivePlayer()) { + CGChat::OnLogXPGain(amount); + } else { + CGChat::LogXPGain(unit, amount, type, bonus, groupMult, referAFriend != 0); + } + + return 1; +} + // VERIFY: 743763ce manual // OFFSET: 0x00577F60 bool InebriatedParseText(const char* text, char* buffer, uint32_t size, float drunkness) { @@ -3758,3 +3931,946 @@ void CGChat::AddCombatMessage(const char* text) { SLogWrite(s_chatLog, "%s", text); } } + +// VERIFY: 4cc22e44 auto +// OFFSET: 0x0050BBF0 +void CGChat::LogPetHappinessDecrease(const WOWGUID& caster, const WOWGUID& target, int32_t amount) { + char text[3000]; + + if (caster == ClntObjMgrGetActivePlayer()) { + const char* targetName = GetObjectNameFromGuid(target); + SStrPrintf(text, sizeof(text), FrameScript_GetText("SPELLHAPPINESSDRAINSELF", -1, GENDER_NOT_APPLICABLE), targetName, amount); + } else { + const char* targetName = GetObjectNameFromGuid(target); + const char* casterName = GetObjectNameFromGuid(caster); + SStrPrintf(text, sizeof(text), FrameScript_GetText("SPELLHAPPINESSDRAINOTHER", -1, GENDER_NOT_APPLICABLE), casterName, targetName, amount); + } + + CGChat::AddChatMessage(text, CHAT_MSG_PET_INFO, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID{ 0 }, 0, WOWGUID{ 0 }, 0, false, nullptr); +} + +// VERIFY: 0afea745 auto +// OFFSET: 0x0050BCC0 +void CGChat::LogDismissPet(const WOWGUID& guid, const WOWGUID& pet) { + char text[3000]; + + if (guid == ClntObjMgrGetActivePlayer()) { + const char* petName = GetObjectNameFromGuid(pet); + SStrPrintf(text, sizeof(text), FrameScript_GetText("SPELLDISMISSPETSELF", -1, GENDER_NOT_APPLICABLE), petName); + } else { + const char* petName = GetObjectNameFromGuid(pet); + const char* name = GetObjectNameFromGuid(guid); + SStrPrintf(text, sizeof(text), FrameScript_GetText("SPELLDISMISSPETOTHER", -1, GENDER_NOT_APPLICABLE), name, petName); + } + + CGChat::AddChatMessage(text, CHAT_MSG_PET_INFO, nullptr, 0, nullptr, nullptr, nullptr, WOWGUID{ 0 }, 0, WOWGUID{ 0 }, 0, false, nullptr); +} + +// VERIFY: 5985c2bf manual +// OFFSET: 0x004FD260 +void ChatWindowInfo::RemoveChannel(const char* name) { + for (uint32_t i = 0; i < this->m_channels.m_count; i++) { + if (this->m_channels.m_data[i] && !SStrCmpUTF8I(this->m_channels.m_data[i], name, STORM_MAX_STR)) { + if (this->m_channels.m_data[i]) { + SMemFree(this->m_channels.m_data[i], __FILE__, __LINE__, 0); + } + + this->m_channels.m_data[i] = nullptr; + this->m_channelIDs.m_data[i] = 0; + return; + } + } +} + +// VERIFY: 107c4716 auto +// OFFSET: 0x004FE160 +const char* CGChat::GetChannelString(const char* name) { + if (!name || !*name) { + return nullptr; + } + + int32_t number = SStrToInt(name); + + if (!number) { + return name; + } + + if (number >= 1 && number <= static_cast(CGChat::s_channels.m_count)) { + ChatChannel* channel = &CGChat::s_channels.m_data[number - 1]; + + if (channel->m_channelNumber == number && !channel->m_unk9C) { + return channel->m_name; + } + } + + return nullptr; +} + +// VERIFY: c7274882 manual +// OFFSET: 0x004FE260 +static bool FindGuildRecruitmentChannel() { + bool found = s_recruitmentChannelFound; + + if (!found) { + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (rec && (rec->m_flags & 0x20000)) { + s_recruitmentChannelID = rec->m_id; + SStrCopy(s_recruitmentChannelName, rec->m_shortcut, sizeof(s_recruitmentChannelName)); + found = true; + s_recruitmentChannelFound = true; + } + } + } + + return found; +} + +// VERIFY: 48808181 manual +// OFFSET: 0x00501A70 +void ChatWindowInfo::AddChannel(const char* name, int32_t id) { + for (uint32_t i = 0; i < this->m_channels.m_count; i++) { + if (this->m_channels.m_data[i] && !SStrCmpUTF8I(this->m_channels.m_data[i], name, STORM_MAX_STR)) { + return; + } + } + + uint32_t index; + + for (index = 0; index < this->m_channels.m_count; index++) { + if (!this->m_channels.m_data[index]) { + this->m_channels.m_data[index] = SStrDupA(name, __FILE__, __LINE__); + this->m_channelIDs.m_data[index] = id; + return; + } + } + + this->m_channels.SetCount(this->m_channels.m_count * 2); + this->m_channelIDs.SetCount(this->m_channelIDs.m_count * 2); + this->m_channels.m_data[index] = SStrDupA(name, __FILE__, __LINE__); + this->m_channelIDs.m_data[index] = id; + + for (uint32_t i = index + 1; i < this->m_channels.m_count; i++) { + this->m_channels.m_data[i] = nullptr; + this->m_channelIDs.m_data[i] = 0; + } +} + +// VERIFY: f2e39696 manual +// OFFSET: 0x005076B0 +int32_t CGChat::AddChatChannel(const char* name, uint32_t id, bool silent, bool a4, bool a5, uint32_t number) { + if (GetChannelByName(name)) { + return 0; + } + + if (id && CGChat::GetChannelByChatChannelID(id)) { + return 0; + } + + uint32_t slot; + + if (number && number <= 10) { + if (number > CGChat::s_channels.m_count) { + CGChat::s_channels.SetCount(number); + slot = number - 1; + } else if (!CGChat::s_channels.m_data[number - 1].m_channelNumber) { + slot = number - 1; + } else { + slot = CGChat::s_channels.m_count; + } + } else { + slot = CGChat::s_channels.m_count; + } + + if (slot == CGChat::s_channels.m_count) { + for (slot = 0; slot < CGChat::s_channels.m_count; slot++) { + if (!CGChat::s_channels.m_data[slot].m_channelNumber) { + break; + } + } + + if (slot == CGChat::s_channels.m_count) { + if (CGChat::s_channels.m_count == 10) { + if (!silent) { + CGGameUI::DisplayError(ERR_TOO_MANY_CHAT_CHANNELS); + } + + return 0; + } + + CGChat::s_channels.SetCount(CGChat::s_channels.m_count + 1); + } + } + + ChatChannel* channel = &CGChat::s_channels.m_data[slot]; + channel->m_channelNumber = slot + 1; + SStrCopy(channel->m_name, name, sizeof(channel->m_name)); + channel->m_zoneChannelID = id; + channel->m_unk9C = 1; + channel->m_unkA0 = 0; + channel->m_unkA4 = a4; + channel->m_unkA5 = a5; + return 1; +} + +// VERIFY: 8b7bb244 manual +// OFFSET: 0x00507A80 +bool InternalJoinChannel(const char* channelName, const char* password, uint32_t window, bool checkRecruitment, const char** zoneChannelName, int32_t* zoneChannelID, bool silent, int32_t a8, int32_t a9, uint32_t number) { + *zoneChannelName = nullptr; + *zoneChannelID = 0; + + char name[256]; + SStrCopy(name, channelName, sizeof(name)); + const char* zoneText = CGGameUI::m_zoneText; + AreaTableRec* area = g_areaTableDB.GetRecord(CGGameUI::m_areaID); + + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (SStrCmpUTF8I(rec->m_shortcut, channelName, STORM_MAX_STR)) { + continue; + } + + const char* text = area && (rec->m_flags & 0x20) && (area->m_flags & 0x100) && s_cityArea ? s_cityArea->m_areaName : zoneText; + + if (!text || !*text) { + return false; + } + + *zoneChannelName = rec->m_shortcut; + *zoneChannelID = rec->m_id; + SStrPrintf(name, sizeof(name), rec->m_name, text); + password = ""; + + if (checkRecruitment && (rec->m_flags & 0x20000)) { + CGChat::SetGuildRecruitmentMode(0, true); + } + + break; + } + + ChatChannel* channel = *zoneChannelID ? CGChat::GetChannelByChatChannelID(*zoneChannelID) : GetChannelByName(name); + + if (!channel) { + if (!CGChat::AddChatChannel(name, *zoneChannelID, silent, a8 != 0, a9 != 0, number)) { + return false; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CHAT_JOIN_CHANNEL)); + msg.Put(static_cast(*zoneChannelID)); + msg.Put(static_cast(silent)); + msg.Put(static_cast(a8)); + msg.PutString(name); + msg.PutString(password); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + if (window < 10) { + s_chatWindows[window].AddChannel(*zoneChannelName ? *zoneChannelName : name, *zoneChannelID); + s_chatSettingsDirty = 1; + } + + return true; +} + +// VERIFY: 3d422a41 manual +// OFFSET: 0x00507D30 +void CGChat::UpdateGuildStatus() { + if (CGChat::m_guildRecruitmentMode != 1 || !CGChat::m_registered) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || !FindGuildRecruitmentChannel()) { + return; + } + + ChatChannel* channel = CGChat::GetChannelByChatChannelID(s_recruitmentChannelID); + + if (player->m_player->m_playerGuildid) { + if (channel) { + InternalLeaveChannel(s_recruitmentChannelName, false, true); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_WINDOWS, nullptr); + } + } else if (!channel) { + const char* zoneChannelName = nullptr; + int32_t zoneChannelID = 0; + InternalJoinChannel(s_recruitmentChannelName, "", 0, false, &zoneChannelName, &zoneChannelID, true, 0, 1, 0); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_WINDOWS, nullptr); + } +} + +// VERIFY: 3583052f manual +// OFFSET: 0x00508090 +void CGChat::ZoneUpdate() { + if (!CGChat::m_loaded) { + return; + } + + if (CGGameUI::m_zoneText && *CGGameUI::m_zoneText) { + CGChat::m_areaID = CGGameUI::m_areaID; + + if (!CGChat::m_registered) { + if (!g_areaTableDB.GetRecord(CGGameUI::m_areaID)) { + return; + } + + const char* zoneChannelName; + int32_t zoneChannelID; + + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if ((1 << (rec->m_id - 1)) & s_joinedZoneChannels) { + InternalJoinChannel(rec->m_shortcut, "", 10, false, &zoneChannelName, &zoneChannelID, true, 0, 1, 0); + } + } + + if (s_pendingChannelNames.m_count) { + for (uint32_t i = 0; i < s_pendingChannelNames.m_count; i++) { + InternalJoinChannel(s_pendingChannelNames.m_data[i], "", 10, false, &zoneChannelName, &zoneChannelID, true, s_pendingChannelFlags.m_data[i], 1, s_pendingChannelNumbers.m_data[i]); + + if (s_pendingChannelNames.m_data[i]) { + SMemFree(s_pendingChannelNames.m_data[i], __FILE__, __LINE__, 0); + } + } + + s_pendingChannelNames.Clear(); + s_pendingChannelFlags.Clear(); + s_pendingChannelNumbers.Clear(); + } + + CGChat::m_registered = 1; + } + } + + CGChat::UpdateGuildStatus(); +} + +// VERIFY: ce71b96d auto +// OFFSET: 0x00508260 +void CGChat::SetGuildRecruitmentMode(int32_t mode, bool fromJoin) { + if (CGChat::m_guildRecruitmentMode == mode) { + return; + } + + CGChat::m_guildRecruitmentMode = mode; + + if (!CGChat::m_registered) { + return; + } + + if (mode == 1) { + CGChat::UpdateGuildStatus(); + } else if (!fromJoin && FindGuildRecruitmentChannel()) { + InternalLeaveChannel(s_recruitmentChannelName, false, true); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_WINDOWS, nullptr); + } +} + +// VERIFY: a08ae344 manual +// OFFSET: 0x00508320 +void CGChat::LoadChatSettingsCallback(HOSFILE localFile, HOSFILE file, void* param) { + int32_t version = 0; + int32_t addedVersion = 0; + uint32_t allChannels = 0; + + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (rec->m_id > 32) { + SErrDisplayAppFatalMessage("", "", 0); + } + + allChannels |= 1 << (rec->m_id - 1); + } + + char* buffer = nullptr; + uint32_t size = 0; + + if (file != OS_INVALID_FILE) { + size = static_cast(OsGetFileSize(file)); + + if (size) { + buffer = static_cast(alloca(size + 1)); + uint32_t bytesRead; + + if (!OsReadFile(file, buffer, size, &bytesRead)) { + buffer = nullptr; + } else if (bytesRead != size) { + SErrDisplayAppFatalMessage("", "", 0); + buffer = nullptr; + } + } + } + + if (buffer) { + buffer[size] = '\0'; + + for (uint32_t i = 0; i < s_pendingChannelNames.m_count; i++) { + if (s_pendingChannelNames.m_data[i]) { + SMemFree(s_pendingChannelNames.m_data[i], __FILE__, __LINE__, 0); + } + } + + s_pendingChannelNames.Clear(); + s_pendingChannelFlags.Clear(); + s_pendingChannelNumbers.Clear(); + + int32_t state = 0; + uint32_t window = 0; + const char* cursor = buffer; + char line[128]; + char token[256]; + char word[256]; + char value[256]; + SStrTokenize(&cursor, line, sizeof(line), "\r\n", nullptr); + + if (!SStrCmpI(line, "VERSION", SStrLen("VERSION"))) { + const char* rest = &line[SStrLen("VERSION")]; + SStrTokenize(&rest, value, sizeof(value), " \r\n", nullptr); + version = SStrToInt(value); + + if (version >= 2) { + SStrTokenize(&cursor, line, sizeof(line), "\r\n", nullptr); + + if (!SStrCmpI(line, "ADDEDVERSION", SStrLen("ADDEDVERSION"))) { + const char* added = &line[SStrLen("ADDEDVERSION")]; + SStrTokenize(&added, value, sizeof(value), " \r\n", nullptr); + addedVersion = SStrToInt(value); + } + } + } else { + cursor = buffer; + } + + for (uint32_t i = 0; i < 10; i++) { + memset(s_chatWindows[i].m_messageGroups, 0, sizeof(s_chatWindows[i].m_messageGroups)); + } + + do { + SStrTokenize(&cursor, line, sizeof(line), "\r\n", nullptr); + + if (!line[0]) { + continue; + } + + if (!state) { + if (!SStrCmpI(line, "CHANNELS", STORM_MAX_STR)) { + state = 1; + continue; + } + + if (!SStrCmpI(line, "COLORS", STORM_MAX_STR)) { + state = 2; + continue; + } + + if (!SStrCmpI(line, "WINDOW", SStrLen("WINDOW"))) { + if (SStrLen(line) < SStrLen("WINDOW") + 2) { + continue; + } + + uint32_t index = SStrToInt(&line[SStrLen("WINDOW") + 1]) - 1; + + if (index > 10) { + continue; + } + + window = index; + state = 3; + } + + if (!SStrCmpI(line, "ZONECHANNELS", SStrLen("ZONECHANNELS"))) { + const char* rest = &line[SStrLen("ZONECHANNELS")]; + SStrTokenize(&rest, value, sizeof(value), " \r\n", nullptr); + s_joinedZoneChannels = SStrToInt(value) & allChannels; + continue; + } + + if (SStrCmpI(line, s_guildRecruitmentOption, SStrLen(s_guildRecruitmentOption))) { + continue; + } + + const char* rest = &line[SStrLen(s_guildRecruitmentOption)]; + SStrTokenize(&rest, token, sizeof(token), " \r\n", nullptr); + int32_t mode = 1; + + if (!SStrCmpI(token, "STANDARD", STORM_MAX_STR)) { + mode = 0; + } else { + SStrCmpI(token, "AUTO", STORM_MAX_STR); + } + + if (CGChat::m_guildRecruitmentMode == mode) { + continue; + } + + CGChat::m_guildRecruitmentMode = mode; + + if (CGChat::m_registered && mode == 1) { + CGChat::UpdateGuildStatus(); + } + + continue; + } + + if (state == 3) { + if (!SStrCmpI(line, "CHANNELS", STORM_MAX_STR)) { + state = 4; + continue; + } + + if (!SStrCmpI(line, "MESSAGES", STORM_MAX_STR)) { + state = 5; + continue; + } + } + + if (!SStrCmpI(line, "END", STORM_MAX_STR)) { + state = state == 4 || state == 5 ? 3 : 0; + continue; + } + + const char* rest = line; + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + + if (!word[0]) { + continue; + } + + switch (state) { + case 1: { + if (version < 3) { + break; + } + + token[0] = '\0'; + SStrTokenize(&rest, token, sizeof(token), " \r\n", nullptr); + value[0] = '\0'; + SStrTokenize(&rest, value, sizeof(value), " \r\n", nullptr); + s_pendingChannelNames.SetCount(s_pendingChannelNames.m_count + 1); + s_pendingChannelNames.m_data[s_pendingChannelNames.m_count - 1] = SStrDupA(word, __FILE__, __LINE__); + s_pendingChannelFlags.SetCount(s_pendingChannelFlags.m_count + 1); + s_pendingChannelFlags.m_data[s_pendingChannelFlags.m_count - 1] = atol(token); + s_pendingChannelNumbers.SetCount(s_pendingChannelNumbers.m_count + 1); + s_pendingChannelNumbers.m_data[s_pendingChannelNumbers.m_count - 1] = atol(value); + break; + } + + case 2: { + ChatColorInfo* color = nullptr; + + for (uint32_t i = 0; i < CHAT_MSG_MAX; i++) { + if (!SStrCmpI(word, s_chatColors[i].m_name, STORM_MAX_STR)) { + color = &s_chatColors[i]; + break; + } + } + + if (!color) { + if (SStrCmpI(word, "CHANNEL", SStrLen("CHANNEL"))) { + break; + } + + uint32_t index = SStrToInt(&word[SStrLen("CHANNEL")]); + + if (!index || index > s_channelColors.m_count) { + break; + } + + color = &s_channelColors.m_data[index - 1]; + + if (!color) { + break; + } + } + + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + color->m_color[0] = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + color->m_color[1] = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + color->m_color[2] = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + + if (word[0] == 'Y' || word[0] == 'N') { + color->m_unk48 = word[0] == 'Y'; + } + + break; + } + + case 3: { + ChatWindowInfo* info = &s_chatWindows[window]; + + if (!SStrCmpI(word, "NAME", STORM_MAX_STR)) { + SStrTokenize(&rest, info->m_name, sizeof(info->m_name), "\r\n", nullptr); + break; + } + + if (!SStrCmpI(word, "SIZE", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_unkD0 = SStrToInt(word); + break; + } + + if (!SStrCmpI(word, "COLOR", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_color.r = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_color.g = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_color.b = SStrToInt(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_color.a = SStrToInt(word); + } + + if (!SStrCmpI(word, "LOCKED", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_unkD8 = SStrToInt(word); + } + + if (!SStrCmpI(word, "UNINTERACTABLE", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), "\r\n", nullptr); + info->m_unkE4 = SStrToInt(word); + } + + if (!SStrCmpI(word, "DOCKED", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_docked = SStrToInt(word); + } + + if (!SStrCmpI(word, "SHOWN", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + info->m_shown = SStrToInt(word); + } + + if (!SStrCmpI(word, "POSITION", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + StringToFramePoint(word, reinterpret_cast(info->m_unkE8)); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + float x = SStrToFloat(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + float y = SStrToFloat(word); + info->m_unkEC = x; + info->m_unkF0 = y; + info->m_unkF4 = 1; + } + + if (!SStrCmpI(word, "DIMENSIONS", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + float width = SStrToFloat(word); + SStrTokenize(&rest, word, sizeof(word), " \r\n", nullptr); + float height = SStrToFloat(word); + info->m_width = width; + info->m_height = height; + info->m_unkF4 = 1; + } + + if (!SStrCmpI(word, "ZONECHANNELS", STORM_MAX_STR)) { + SStrTokenize(&rest, word, sizeof(word), "\r\n", nullptr); + uint32_t channels = SStrToInt(word) & allChannels; + + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (channels & (1 << (rec->m_id - 1))) { + info->AddChannel(rec->m_shortcut, rec->m_id); + } + } + } + + break; + } + + case 4: { + s_chatWindows[window].AddChannel(word, 0); + break; + } + + case 5: { + for (uint32_t i = 0; i < sizeof(s_chatMessageGroups) / sizeof(s_chatMessageGroups[0]); i++) { + if (!SStrCmpI(word, s_chatMessageGroups[i].m_name, STORM_MAX_STR)) { + s_chatWindows[window].m_messageGroups[i] = 1; + break; + } + } + + break; + } + + default: { + break; + } + } + } while (cursor && *cursor); + + if (addedVersion < 13) { + for (uint32_t i = 0; i < sizeof(s_zoneChannelDefaults) / sizeof(s_zoneChannelDefaults[0]); i++) { + if (s_zoneChannelDefaults[i].m_addedVersion <= addedVersion) { + continue; + } + + ChatChannelsRec* rec = g_chatChannelsDB.GetRecord(s_zoneChannelDefaults[i].m_channelID); + + if (!rec || !(rec->m_flags & 1)) { + continue; + } + + if (rec->m_id > 32) { + SErrDisplayAppFatalMessage("", "", 0); + } + + uint32_t bit = 1 << (rec->m_id - 1); + + if (!(bit & s_joinedZoneChannels)) { + s_joinedZoneChannels |= bit; + s_chatWindows[0].AddChannel(rec->m_shortcut, rec->m_id); + } + } + + for (uint32_t i = 0; i < sizeof(s_chatMessageGroups) / sizeof(s_chatMessageGroups[0]); i++) { + if (s_chatMessageGroups[i].m_default && s_chatMessageGroups[i].m_type > addedVersion) { + s_chatWindows[i < 40 ? 0 : 1].m_messageGroups[i] = 1; + } + } + + for (uint32_t i = 0; i < CHAT_MSG_MAX; i++) { + if (s_chatTypeInfo[i].m_unk44 > addedVersion) { + s_chatColors[i].m_color[0] = s_chatTypeInfo[i].m_color[0]; + s_chatColors[i].m_color[1] = s_chatTypeInfo[i].m_color[1]; + s_chatColors[i].m_color[2] = s_chatTypeInfo[i].m_color[2]; + s_chatColors[i].m_unk48 = s_chatTypeInfo[i].m_unk48; + } + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_WINDOWS, nullptr); + + for (uint32_t i = 0; i < CHAT_MSG_MAX; i++) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR, "%s%f%f%f", s_chatColors[i].m_name, s_chatColors[i].m_color[0] * (1.0f / 255.0f), s_chatColors[i].m_color[1] * (1.0f / 255.0f), s_chatColors[i].m_color[2] * (1.0f / 255.0f)); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR_NAME_BY_CLASS, "%s%b", s_chatColors[i].m_name, s_chatColors[i].m_unk48); + } + + for (uint32_t i = 0; i < s_channelColors.m_count; i++) { + ChatColorInfo* color = &s_channelColors.m_data[i]; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR, "%s%f%f%f", color->m_name, color->m_color[0] * (1.0f / 255.0f), color->m_color[1] * (1.0f / 255.0f), color->m_color[2] * (1.0f / 255.0f)); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR_NAME_BY_CLASS, "%s%b", color->m_name, color->m_unk48); + } + } else { + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (!(rec->m_flags & 1)) { + continue; + } + + if (rec->m_id >= 32) { + SErrDisplayAppFatalMessage("", "", 0); + } + + s_joinedZoneChannels |= 1 << (rec->m_id - 1); + s_chatWindows[0].AddChannel(rec->m_shortcut, rec->m_id); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_WINDOWS, nullptr); + + for (uint32_t i = 0; i < CHAT_MSG_MAX; i++) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR, "%s%f%f%f", s_chatColors[i].m_name, s_chatColors[i].m_color[0] * (1.0f / 255.0f), s_chatColors[i].m_color[1] * (1.0f / 255.0f), s_chatColors[i].m_color[2] * (1.0f / 255.0f)); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR_NAME_BY_CLASS, "%s%b", s_chatColors[i].m_name, s_chatColors[i].m_unk48); + } + + for (uint32_t i = 0; i < s_channelColors.m_count; i++) { + ChatColorInfo* color = &s_channelColors.m_data[i]; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR, "%s%f%f%f", color->m_name, color->m_color[0] * (1.0f / 255.0f), color->m_color[1] * (1.0f / 255.0f), color->m_color[2] * (1.0f / 255.0f)); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_CHAT_COLOR_NAME_BY_CLASS, "%s%b", color->m_name, color->m_unk48); + } + } + + CGChat::m_loaded = 1; + CGChat::ZoneUpdate(); +} + +// VERIFY: 77a9b802 manual +// OFFSET: 0x005093F0 +int32_t InternalLeaveChannel(const char* channelName, bool clearRecruitment, bool force) { + const char* channelString = force ? channelName : CGChat::GetChannelString(channelName); + + if (!channelString) { + return 0; + } + + const char* zoneChannelName = nullptr; + char name[256]; + SStrCopy(name, channelString, sizeof(name)); + const char* zoneText = CGGameUI::m_zoneText; + int32_t zoneChannelID = 0; + AreaTableRec* area = g_areaTableDB.GetRecord(CGGameUI::m_areaID); + + for (int32_t i = 0; i < g_chatChannelsDB.m_numRecords; i++) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecordByIndex(i); + + if (SStrCmpUTF8I(rec->m_shortcut, channelName, STORM_MAX_STR)) { + continue; + } + + const char* text = area && (rec->m_flags & 0x20) && (area->m_flags & 0x100) && s_cityArea ? s_cityArea->m_areaName : zoneText; + + if (!text || !*text) { + return 0; + } + + zoneChannelName = rec->m_shortcut; + zoneChannelID = rec->m_id; + SStrPrintf(name, sizeof(name), rec->m_name, text); + + if (clearRecruitment && (rec->m_flags & 0x20000) && CGChat::m_guildRecruitmentMode) { + CGChat::m_guildRecruitmentMode = 0; + } + + break; + } + + for (uint32_t i = 0; i < 10; i++) { + s_chatWindows[i].RemoveChannel(zoneChannelName ? zoneChannelName : name); + } + + ChatChannel* channel = zoneChannelID ? CGChat::GetChannelByChatChannelID(zoneChannelID) : GetChannelByName(name); + + if (channel && (!channel->m_unk9C || force)) { + CDataStore msg; + msg.Put(static_cast(CMSG_CHAT_LEAVE_CHANNEL)); + msg.Put(static_cast(channel->m_zoneChannelID)); + msg.PutString(channel->m_name); + msg.Finalize(); + ClientServices::Send2(&msg); + + uint32_t id = channel->m_zoneChannelID; + channel->m_unkA0 = 1; + + if (id) { + s_joinedZoneChannels &= ~(1 << (id - 1)); + } + + if (channel->m_unk9C == 1) { + ChatChannel* entry = id ? CGChat::GetChannelByChatChannelID(id) : GetChannelByName(channel->m_name); + + if (entry) { + entry->m_channelNumber = 0; + entry->m_name[0] = '\0'; + entry->m_zoneChannelID = 0; + entry->m_unk9C = 1; + entry->m_unkA0 = 1; + } + + CGChat::OnChannelsUpdated(); + } + } + + s_chatSettingsDirty = 1; + return 0; +} + +// VERIFY: 2a2301d1 auto +// OFFSET: 0x00509780 +void CGChat::LoadChatSettings() { + LoadAccountData(7, CGChat::LoadChatSettingsCallback, nullptr); +} + +// VERIFY: 024941a0 auto +// OFFSET: 0x004FDF50 +const char* CGChat::GetChannelShortName(int32_t number, bool includeInactive) { + if (number < 1 || number > static_cast(CGChat::s_channels.m_count)) { + return nullptr; + } + + ChatChannel* channel = &CGChat::s_channels.m_data[number - 1]; + + if (channel->m_channelNumber != number || (!includeInactive && channel->m_unk9C)) { + return nullptr; + } + + if (channel->m_zoneChannelID) { + ChatChannelsRec* rec = g_chatChannelsDB.GetRecord(channel->m_zoneChannelID); + + if (rec) { + return rec->m_shortcut; + } + } + + return channel->m_name; +} + +// VERIFY: 6aa5aad3 auto +// OFFSET: 0x004FF4F0 +uint32_t CGChat::FindDisplayChannelIndex(const char* name, int32_t type) { + for (uint32_t i = 0; i < s_numDisplayChannels; i++) { + if (static_cast(CGChat::s_displayChannels[i].m_channelIndex) > CGChat::s_channels.m_count || CGChat::s_displayChannels[i].m_headerIndex >= 0) { + continue; + } + + int32_t displayType; + const char* channel = CGChat::GetChannelStringForDisplay(i, &displayType); + + if (!channel || displayType == 4 || displayType != type) { + continue; + } + + if (displayType) { + return i + 1; + } + + if (name && !SStrCmpUTF8I(channel, name, STORM_MAX_STR)) { + return i + 1; + } + } + + return 0; +} + +// VERIFY: ab2de665 manual +// OFFSET: 0x004FB580 +bool CGChat::ChatTokenToGUID(const char* token, WOWGUID& guid) { + NameCache* rec = g_nameDBCache.GetRecordByName(token); + + if (!rec) { + return Script_GetGUIDFromToken(token, guid, false); + } + + guid = rec->m_guid; + return true; +} + +// VERIFY: 8d38700f auto +// OFFSET: 0x004FB9C0 +CImVector CGChat::GetChatColor(int32_t type) { + CImVector color; + + if (type < CHAT_MSG_MAX) { + color.b = s_chatColors[type].m_color[2]; + color.g = s_chatColors[type].m_color[1]; + color.a = 0xFF; + color.r = s_chatColors[type].m_color[0]; + } else { + color.b = 0xFF; + color.g = 0xFF; + color.a = 0xFF; + color.r = 0xFF; + } + + return color; +} + +// VERIFY: 50e36d6f manual +// OFFSET: 0x004FBA10 +int32_t FormatTime(char* buffer, uint32_t size, int32_t seconds) { + int32_t days = seconds / 86400; + int32_t hours = seconds % 86400 / 3600; + int32_t minutes = (seconds - 3600 * (hours + 24 * days)) / 60; + return SStrPrintf(buffer, size, "%dd %dh %dm %ds", days, hours, minutes, seconds % 60); +} diff --git a/WoW/Source/Ui/ChatFrame.h b/WoW/Source/Ui/ChatFrame.h index f5af194..0c8e69e 100644 --- a/WoW/Source/Ui/ChatFrame.h +++ b/WoW/Source/Ui/ChatFrame.h @@ -7,10 +7,12 @@ #include "Engine/Source/Tempest/CImVector.h" #include "WoW/Source/Net/Types.h" #include "WoW/Source/Object/WGUID.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/AccountData.h" struct lua_State; class CDataStore; class CGPlayer_C; +class CGUnit_C; enum SLASH_COMMAND_ID { CHAT_MSG_SYSTEM = 0, @@ -199,6 +201,11 @@ struct WORDLIST : public TSHashObject { /* 001C */ TSGrowableArray m_words; }; +struct ZoneChannelDefault { + /* 0000 */ int32_t m_channelID; + /* 0004 */ int32_t m_addedVersion; +}; + struct ChatMessageGroup { /* 0000 */ const char* m_name; /* 0004 */ bool m_default; @@ -209,8 +216,8 @@ class ChatWindowInfo { public: /* 0000 */ char m_name[128]; /* 0080 */ uint8_t m_messageGroups[46]; - /* 00B0 */ TSGrowableArray m_unkB0; - /* 00C0 */ TSGrowableArray m_unkC0; + /* 00B0 */ TSGrowableArray m_channels; + /* 00C0 */ TSGrowableArray m_channelIDs; /* 00D0 */ int32_t m_unkD0; /* 00D4 */ CImVector m_color; /* 00D8 */ uint32_t m_unkD8; @@ -224,7 +231,9 @@ class ChatWindowInfo { /* 00F8 */ float m_width; /* 00FC */ float m_height; + void AddChannel(const char* name, int32_t id); void Init(); + void RemoveChannel(const char* name); }; struct ChatRecord { @@ -247,6 +256,8 @@ struct ChatColorInfo { /* 0048 */ uint8_t m_unk48; }; +int32_t Packet_SMSG_LOG_XPGAIN(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); + class CGChat { public: static void ZoneUpdate(); @@ -256,9 +267,18 @@ class CGChat { static void EnterWorld(); static void InitializeGame(); static void LoadChatSettings(); + static void LoadChatSettingsCallback(HOSFILE localFile, HOSFILE file, void* param); + static const char* GetChannelString(const char* name); + static bool ChatTokenToGUID(const char* token, WOWGUID& guid); + static CImVector GetChatColor(int32_t type); + static const char* GetChannelShortName(int32_t number, bool includeInactive); + static uint32_t FindDisplayChannelIndex(const char* name, int32_t type); + static int32_t AddChatChannel(const char* name, uint32_t id, bool silent, bool a4, bool a5, uint32_t number); static int32_t IsChatLogging(int32_t type); static void AddCombatMessage(const char* text); static int32_t m_afk; + static int32_t m_guildRecruitmentMode; + static int32_t m_areaID; static int32_t m_paused; static int32_t m_voiceChatSystemStatus; static ChatRecord m_chatHistory[60]; @@ -269,6 +289,10 @@ class CGChat { static TSExplicitList s_pendingChat; static TSExplicitList s_pendingTextEmotes; + static void LogFeedPet(const WOWGUID& guid, int32_t itemId); + static void LogPetHappinessDecrease(const WOWGUID& caster, const WOWGUID& target, int32_t amount); + static void LogDismissPet(const WOWGUID& guid, const WOWGUID& pet); + static void LogTradeSkillCreate(const WOWGUID& guid, int32_t itemId); static void AddChatMessage(const char* text, int32_t type, const char* senderName, uint32_t language, const char* channelName, const char* targetName, const char* flags, WOWGUID senderGuid, uint32_t senderUnk, WOWGUID targetGuid, int32_t achievementID, bool isGM, const ChatConversation* conversation); static int32_t OnMessageChat(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); static int32_t OnGMMessageChat(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); @@ -299,7 +323,8 @@ class CGChat { static int32_t OnCheckReloadSpamFilter(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); static int32_t OnTitleEarned(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); static int32_t OnResetFailedNotify(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); - static int32_t OnLogXPGain(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); + static void OnLogXPGain(int32_t amount); + static void LogXPGain(CGUnit_C* unit, int32_t amount, int32_t type, int32_t bonus, float groupMult, bool referAFriend); static int32_t OnDurabilityDamageDeath(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); static int32_t OnChannelMemberCount(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); static int32_t OnComsatReconnectAttempt(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); @@ -336,7 +361,7 @@ class CGChat { static void AddChannelThrottled(const char* channel, uint32_t time); static void AddThrottledChat(int32_t type, uint32_t language, const char* target, const char* text); static int32_t GetActiveVoiceSession(); - static void SetGuildRecruitmentMode(int32_t mode, int32_t a2); + static void SetGuildRecruitmentMode(int32_t mode, bool fromJoin); static const char* GetChannelStringForDisplay(int32_t session, int32_t* type); static int32_t IsPaused(); static int32_t IsVoiceChatAllowed(); @@ -350,6 +375,9 @@ class CGChat { int32_t StringToChatType(const char* string, int32_t* type); int32_t StringToLanguage(const char* string, uint32_t* language); ChatChannel* GetChannelByName(const char* name); +int32_t FormatTime(char* buffer, uint32_t size, int32_t seconds); +bool InternalJoinChannel(const char* channelName, const char* password, uint32_t window, bool checkRecruitment, const char** zoneChannelName, int32_t* zoneChannelID, bool silent, int32_t a8, int32_t a9, uint32_t number); +int32_t InternalLeaveChannel(const char* channelName, bool clearRecruitment, bool force); bool ProfanityFilter(char* text, bool cache, bool force); void SetCurrentActiveDisplayChannel(const char* name, int32_t type); uint32_t BuildPartyDisplayList(); @@ -395,8 +423,6 @@ int32_t Script_SetSavedInstanceExtend(lua_State* L); int32_t Script_ResetChatWindows(lua_State* L); int32_t Script_CanComplainChat(lua_State* L); int32_t Script_ComplainChat(lua_State* L); -int32_t Script_GetChannelDisplayInfo(lua_State* L); -int32_t Script_GetSelectedDisplayChannel(lua_State* L); int32_t Script_SetSelectedDisplayChannel(lua_State* L); int32_t Script_GetChannelRosterInfo(lua_State* L); int32_t Script_GetNumChannelMembers(lua_State* L); @@ -416,6 +442,8 @@ void ChatRegisterScriptFunctions(); extern uint32_t s_numDisplayChannels; +extern int32_t s_activeDisplayChannelType; + extern int32_t s_activeVoiceChannel; extern uint8_t s_collapsedHeaders[3]; diff --git a/WoW/Source/Ui/ChatFrame_Scripts.cpp b/WoW/Source/Ui/ChatFrame_Scripts.cpp index 98d9b23..7d3e0d7 100644 --- a/WoW/Source/Ui/ChatFrame_Scripts.cpp +++ b/WoW/Source/Ui/ChatFrame_Scripts.cpp @@ -1,5 +1,6 @@ #include "ChatFrame.h" #include +#include "Engine/Source/lua-5.1/src/lua.h" #include "Engine/Source/Base/CDataStore.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" @@ -24,6 +25,9 @@ #include "WoW/Source/Game/GameClient/ComSatClient.h" #include "Engine/Source/ConsoleBase/ConsoleVar.h" +// STATIC: 0x00AC7A48 +static const char* s_channelCategories[3] = { "CHANNEL_CATEGORY_GROUP", "CHANNEL_CATEGORY_WORLD", "CHANNEL_CATEGORY_CUSTOM" }; + // VERIFY: 3ea62573 manual // OFFSET: 0x0050D170 static int32_t Script_SendChatMessage(lua_State* L) { @@ -1062,6 +1066,141 @@ static int32_t Script_RemoveChatWindowMessages(lua_State* L) { return 0; } +// VERIFY: 93fcf20f manual +// OFFSET: 0x004FF580 +static int32_t Script_GetChannelDisplayInfo(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetChannelDisplayInfo(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + + if (index >= s_numDisplayChannels) { + return 0; + } + + DisplayChannel* display = &CGChat::s_displayChannels[index]; + + if (display->m_headerIndex >= 0) { + lua_pushstring(L, FrameScript_GetText(s_channelCategories[display->m_headerIndex], -1, GENDER_NOT_APPLICABLE)); + lua_pushnumber(L, 1.0); + + if (display->m_collapsed) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnil(L); + + if (display->m_count) { + lua_pushnumber(L, display->m_count); + } else { + lua_pushnil(L); + } + + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + return 9; + } + + int32_t channelIndex = display->m_channelIndex; + + if (channelIndex < 0) { + const char* token; + + switch (channelIndex) { + case -1: + token = "CHAT_MSG_PARTY"; + break; + + case -2: + token = "CHAT_MSG_RAID"; + break; + + case -3: + token = "CHAT_MSG_BATTLEGROUND"; + break; + + default: + for (int32_t i = 0; i < 9; i++) { + lua_pushnil(L); + } + + return 9; + } + + lua_pushstring(L, FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE)); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + + if (display->m_count) { + lua_pushnumber(L, display->m_count); + } else { + lua_pushnil(L); + } + + if (display->m_enabled) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushstring(L, s_channelCategories[0]); + } else { + const char* name = CGChat::GetChannelShortName(channelIndex + 1, true); + lua_pushstring(L, name ? name : ""); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnumber(L, CGChat::s_channels.m_data[display->m_channelIndex].m_channelNumber); + + if (display->m_count) { + lua_pushnumber(L, display->m_count); + } else { + lua_pushnil(L); + } + + if (display->m_enabled) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushstring(L, display->m_flags & 1 ? s_channelCategories[1] : s_channelCategories[2]); + } + + if (display->m_voiceEnabled) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (static_cast(s_activeVoiceChannel) == index) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 9; +} + +// VERIFY: 4af53a4c auto +// OFFSET: 0x004FFA10 +static int32_t Script_GetSelectedDisplayChannel(lua_State* L) { + uint32_t index = CGChat::FindDisplayChannelIndex(CGChat::s_activeDisplayChannelName, s_activeDisplayChannelType); + + if (index) { + lua_pushnumber(L, index); + } else { + lua_pushnil(L); + } + + return 1; +} + // STATIC: 0x00AC7A58 static FrameScript_Method s_ScriptFunctions[] = { { "SendChatMessage", &Script_SendChatMessage }, diff --git a/WoW/Source/Ui/ClassTrainerFrame.cpp b/WoW/Source/Ui/ClassTrainerFrame.cpp index 5632803..f8e4891 100644 --- a/WoW/Source/Ui/ClassTrainerFrame.cpp +++ b/WoW/Source/Ui/ClassTrainerFrame.cpp @@ -3,6 +3,16 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/GameUI.h" #include "WoW/Source/Ui/Types.h" +#include +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/Object/Unit.h" +#include "WoW/Source/Ui/SpellBookFrame.h" // STATIC: 0x00C0E490 WOWGUID CGClassTrainer::m_trainer; @@ -65,3 +75,384 @@ void CGClassTrainer::SetTrainer(const WOWGUID& trainer, int32_t type) { CGClassTrainer::m_trainer = trainer; CGClassTrainer::m_trainerType = type; } + +// VERIFY: d723d8b2 auto +// OFFSET: 0x00593CC0 +void CGClassTrainer::EnterWorld() { + CGClassTrainer::m_trainer = WOWGUID{ 0 }; + CGClassTrainer::m_currentSelection = 0; + CGClassTrainer::m_numServices = 0; + CGClassTrainer::m_greetingText[0] = '\0'; +} + +// VERIFY: 53d4c1b1 manual +// OFFSET: 0x005947D0 +static int32_t QSortServices_General(const void* a, const void* b) { + const TrainerServiceInfo* serviceA = *static_cast(a); + const TrainerServiceInfo* serviceB = *static_cast(b); + + if (!serviceA->m_visible || !serviceB->m_visible) { + if (!serviceA->m_visible && !serviceB->m_visible) { + return 0; + } + + return 2 * (serviceB->m_visible != 0) - 1; + } + + if (CGClassTrainer::m_numSkillLines) { + int32_t lineA = 0; + int32_t lineB = 0; + + for (uint32_t i = 0; i < static_cast(CGClassTrainer::m_numSkillLines); i++) { + if (CGClassTrainer::m_skillLines.m_data[i]->m_skillLine == serviceA->m_skillLine) { + lineA = i; + } + + if (CGClassTrainer::m_skillLines.m_data[i]->m_skillLine == serviceB->m_skillLine) { + lineB = i; + } + } + + if (lineA != lineB) { + return 2 * (lineA > lineB) - 1; + } + } + + if (serviceA->m_spellID < 0 || serviceB->m_spellID < 0) { + return 2 * (serviceA->m_spellID >= 0) - 1; + } + + SpellRec spellA; + SpellRec spellB; + + if (!g_spellDB.GetRecord(serviceA->m_spellID, &spellA) || !g_spellDB.GetRecord(serviceB->m_spellID, &spellB)) { + return 0; + } + + if (serviceB->m_levelReq != serviceA->m_levelReq) { + return serviceB->m_levelReq < serviceA->m_levelReq ? 1 : -1; + } + + if (static_cast(serviceB->m_skillRankReq) != static_cast(serviceA->m_skillRankReq)) { + return static_cast(serviceB->m_skillRankReq) < static_cast(serviceA->m_skillRankReq) ? 1 : -1; + } + + int32_t result = SStrSortUTF8I(spellA.m_name, spellB.m_name, STORM_MAX_STR); + + if (!result) { + result = SStrSortUTF8I(spellA.m_nameSubtext, spellB.m_nameSubtext, STORM_MAX_STR); + } + + return result; +} + +// VERIFY: 5cc286cb manual +// OFFSET: 0x005949A0 +static int32_t QSortServices_Tradeskill(const void* a, const void* b) { + const TrainerServiceInfo* serviceA = *static_cast(a); + const TrainerServiceInfo* serviceB = *static_cast(b); + + if (!serviceA->m_visible || !serviceB->m_visible) { + if (!serviceA->m_visible && !serviceB->m_visible) { + return 0; + } + + return 2 * (serviceB->m_visible != 0) - 1; + } + + if (serviceA->m_skillLine != serviceB->m_skillLine) { + return 2 * (serviceA->m_skillLine > serviceB->m_skillLine) - 1; + } + + if (serviceA->m_spellID < 0 || serviceB->m_spellID < 0) { + return 2 * (serviceA->m_spellID >= 0) - 1; + } + + SpellRec spellA; + SpellRec spellB; + + if (!g_spellDB.GetRecord(serviceA->m_spellID, &spellA) || !g_spellDB.GetRecord(serviceB->m_spellID, &spellB)) { + return 0; + } + + if (static_cast(serviceB->m_skillRankReq) != static_cast(serviceA->m_skillRankReq)) { + return static_cast(serviceB->m_skillRankReq) < static_cast(serviceA->m_skillRankReq) ? 1 : -1; + } + + return SStrSortUTF8I(spellA.m_name, spellB.m_name, STORM_MAX_STR); +} + +// VERIFY: f786a100 manual +// OFFSET: 0x00594BA0 +void CGClassTrainer::FilterAndSortServices() { + CGClassTrainer::m_filteredServices = CGClassTrainer::m_numServices; + int32_t filter = g_serviceTypeFilterCVar->m_intValue; + + for (uint32_t i = 0; i < static_cast(CGClassTrainer::m_numSkillLines); i++) { + int32_t visible = 0; + + for (uint32_t state = 0; state < 6; state++) { + if (((1 << state) & filter) && CGClassTrainer::m_skillLines.m_data[i]->m_stateCounts[state]) { + visible = ((1 << i) & CGClassTrainer::m_skillLineFilter) != 0; + break; + } + } + + CGClassTrainer::m_skillLines.m_data[i]->m_visible = visible; + CGClassTrainer::m_skillLines.m_data[i]->m_collapsed = (CGClassTrainer::m_expandedSkillLines & (1 << i)) == 0; + } + + for (uint32_t i = 0; i < CGClassTrainer::m_numServices; i++) { + TrainerServiceInfo* service = CGClassTrainer::m_services.m_data[i]; + + if (service->m_spellID >= 0 && !((1 << service->m_state) & filter)) { + service->m_visible = 0; + CGClassTrainer::m_filteredServices--; + continue; + } + + service->m_visible = 1; + + if (!CGClassTrainer::m_numSkillLines) { + continue; + } + + uint32_t index = 0; + + for (uint32_t j = 0; j < static_cast(CGClassTrainer::m_numSkillLines); j++) { + if (CGClassTrainer::m_skillLines.m_data[j]->m_skillLine == service->m_skillLine) { + index = j; + break; + } + } + + TrainerSkillLineInfo* line = CGClassTrainer::m_skillLines.m_data[index]; + + if (!line->m_visible || (service->m_spellID >= 0 && line->m_collapsed)) { + service->m_visible = 0; + CGClassTrainer::m_filteredServices--; + } + } + + if (CGClassTrainer::m_trainerType == 2) { + qsort(CGClassTrainer::m_services.m_data, CGClassTrainer::m_numServices, sizeof(TrainerServiceInfo*), QSortServices_Tradeskill); + } else { + qsort(CGClassTrainer::m_services.m_data, CGClassTrainer::m_numServices, sizeof(TrainerServiceInfo*), QSortServices_General); + } + + uint32_t i; + + for (i = 0; i < CGClassTrainer::m_numServices; i++) { + TrainerServiceInfo* service = CGClassTrainer::m_services.m_data[i]; + + if (service && service->m_spellID > 0 && !service->m_state && service->m_visible) { + break; + } + } + + if (i < CGClassTrainer::m_numServices) { + CGClassTrainer::m_currentSelection = CGClassTrainer::m_services.m_data[i]->m_spellID; + + if (CGClassTrainer::m_currentSelection < 0) { + CGClassTrainer::m_currentSelection = 0; + } + } + + if (i == CGClassTrainer::m_numServices) { + CGClassTrainer::m_currentSelection = CGClassTrainer::m_numServices > 1 ? CGClassTrainer::m_services.m_data[1]->m_spellID : 0; + + if (CGClassTrainer::m_currentSelection < 0) { + CGClassTrainer::m_currentSelection = 0; + } + } +} + +// VERIFY: c9bb5ec3 manual +// OFFSET: 0x00596B00 +void CGClassTrainer::RefreshList() { + if (!CGClassTrainer::m_trainer) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + for (uint32_t s = 0; s < CGClassTrainer::m_numServices; s++) { + if (CGClassTrainer::m_services.m_data[s]->m_spellID == -1) { + continue; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(CGClassTrainer::m_services.m_data[s]->m_spellID, &spell)) { + continue; + } + + CGClassTrainer::m_services.m_data[s]->m_state = 0; + bool teaches = false; + int32_t total = 0; + int32_t known = 0; + + for (uint32_t e = 0; e < 3; e++) { + int32_t effect = spell.m_effect[e]; + + if (!effect) { + continue; + } + + if (effect == 44) { + int32_t minPoints; + int32_t maxPoints; + Spell_C_GetMinMaxPoints(&spell, e, &minPoints, &maxPoints, 0, 0, 0, 0); + total++; + + for (int32_t i = 0; i < 128; i++) { + uint16_t skillId = player->m_obj->m_guid == ClntObjMgrGetActivePlayer() ? player->m_player->m_playerSkillInfo[i].m_skillId : 0; + + if (skillId == spell.m_effectMiscValue[e]) { + uint16_t step = player->m_obj->m_guid == ClntObjMgrGetActivePlayer() ? player->m_player->m_playerSkillInfo[i].m_step : 0; + + if (step >= maxPoints) { + known++; + } + + break; + } + } + + continue; + } + + int32_t spellId; + + if (effect == 36 && spell.m_implicitTargetA[e] != 5) { + spellId = spell.m_effectTriggerSpell[e]; + teaches = true; + } else { + if (teaches) { + continue; + } + + spellId = spell.m_id; + } + + total++; + + if (player->IsSpellKnown(spellId) || player->IsSpellSuperceded(spellId)) { + known++; + } + + if (spellId == spell.m_id) { + break; + } + } + + if (total > 0 && known == total) { + CGClassTrainer::m_services.m_data[s]->m_state = 2; + } + + if (CGClassTrainer::m_services.m_data[s]->m_state) { + continue; + } + + if (CGClassTrainer::m_services.m_data[s]->m_skillReq) { + int32_t maxRank = 0; + + for (int32_t i = 0; i < 128; i++) { + uint16_t skillId = player->m_obj->m_guid == ClntObjMgrGetActivePlayer() ? player->m_player->m_playerSkillInfo[i].m_skillId : 0; + + if (skillId == CGClassTrainer::m_services.m_data[s]->m_skillReq) { + if (player->m_obj->m_guid == ClntObjMgrGetActivePlayer()) { + maxRank = player->m_player->m_playerSkillInfo[i].m_maxRank; + + if (maxRank > 0) { + maxRank += player->m_player->m_playerSkillInfo[i].m_permBonus; + } + } else { + maxRank = 0; + } + + if (static_cast(player->GetSkillValue(i)) < CGClassTrainer::m_services.m_data[s]->m_skillRankReq) { + CGClassTrainer::m_services.m_data[s]->m_state = 1; + } + + break; + } + } + + SpellRec stepSpell; + + if (g_spellDB.GetRecord(CGClassTrainer::m_services.m_data[s]->m_stepSpellID, &stepSpell)) { + for (uint32_t e = 0; e < 3; e++) { + if (stepSpell.m_effect[e] == 44 && stepSpell.m_effectMiscValue[e] == CGClassTrainer::m_services.m_data[s]->m_skillReq) { + int32_t minPoints; + int32_t maxPoints; + Spell_C_GetMinMaxPoints(&stepSpell, e, &minPoints, &maxPoints, 0, 0, 0, 0); + + if (maxRank < 5 * maxPoints) { + CGClassTrainer::m_services.m_data[s]->m_state = 1; + } + + break; + } + } + } + } + + if (CGClassTrainer::m_services.m_data[s]->m_state) { + continue; + } + + bool abilitiesKnown = true; + + for (uint32_t i = 0; i < 3; i++) { + int32_t ability = CGClassTrainer::m_services.m_data[s]->m_abilityReq[i]; + + if (ability && !player->IsSpellKnown(ability) && !player->IsSpellSuperceded(ability)) { + abilitiesKnown = false; + break; + } + } + + TrainerServiceInfo* service = CGClassTrainer::m_services.m_data[s]; + + if (CGSpellBook::IsUnlearnedSpell(service->m_spellID)) { + service->m_state = 2; + } else if (!abilitiesKnown) { + service->m_state = 1; + } else if (service->m_levelReq > 1 && static_cast(player->m_unit->m_unitFieldLevel) < service->m_levelReq) { + service->m_state = 1; + } + } + + for (uint32_t i = 0; i < static_cast(CGClassTrainer::m_numSkillLines); i++) { + TrainerSkillLineInfo* line = CGClassTrainer::m_skillLines.m_data[i]; + + for (uint32_t state = 0; state < 6; state++) { + line->m_stateCounts[state] = 0; + } + + line->unk_0024 = 1; + } + + for (uint32_t s = 0; s < CGClassTrainer::m_numServices; s++) { + TrainerServiceInfo* service = CGClassTrainer::m_services.m_data[s]; + + if (service->m_spellID == -1) { + continue; + } + + for (uint32_t i = 0; i < static_cast(CGClassTrainer::m_numSkillLines); i++) { + if (CGClassTrainer::m_skillLines.m_data[i]->m_skillLine == service->m_skillLine) { + CGClassTrainer::m_skillLines.m_data[i]->m_stateCounts[service->m_state]++; + break; + } + } + } + + CGClassTrainer::FilterAndSortServices(); + FrameScript_SignalEvent(SCRIPT_EVENT_TRAINER_UPDATE, nullptr); +} diff --git a/WoW/Source/Ui/ClassTrainerFrame.h b/WoW/Source/Ui/ClassTrainerFrame.h index 7ddfd4f..542b3a0 100644 --- a/WoW/Source/Ui/ClassTrainerFrame.h +++ b/WoW/Source/Ui/ClassTrainerFrame.h @@ -14,12 +14,14 @@ struct TrainerServiceInfo { /* 0008 */ int32_t m_moneyCost; /* 000C */ int32_t m_talentCost; /* 0010 */ int32_t m_professionCost; - /* 0014 */ int32_t m_levelReq; + /* 0014 */ uint8_t m_levelReq; + /* 0015 */ uint8_t unk_0015[3]; /* 0018 */ int32_t m_skillReq; /* 001C */ int32_t m_skillRankReq; - /* 0020 */ int32_t unk_0020; + /* 0020 */ int32_t m_stepSpellID; /* 0024 */ int32_t m_abilityReq[3]; - /* 0030 */ uint32_t m_state; + /* 0030 */ uint8_t m_state; + /* 0031 */ uint8_t unk_0031[3]; /* 0034 */ int32_t m_visible; }; @@ -34,10 +36,6 @@ struct TrainerSkillLineInfo { class CGClassTrainer { public: static WOWGUID m_trainer; - static void SetTrainer(const WOWGUID& trainer, int32_t type); - static void EnterWorld(); - static void RefreshList(); - static void InitializeGame(); static char m_greetingText[2048]; static int32_t m_trainerType; static uint32_t m_filteredServices; @@ -48,6 +46,12 @@ class CGClassTrainer { static uint32_t m_expandedSkillLines; static TSGrowableArray m_services; static TSGrowableArray m_skillLines; + + static void SetTrainer(const WOWGUID& trainer, int32_t type); + static void EnterWorld(); + static void FilterAndSortServices(); + static void RefreshList(); + static void InitializeGame(); }; int32_t Script_OpenTrainer(lua_State* L); diff --git a/WoW/Source/Ui/CommentatorFrame.cpp b/WoW/Source/Ui/CommentatorFrame.cpp index f8744bd..01ee645 100644 --- a/WoW/Source/Ui/CommentatorFrame.cpp +++ b/WoW/Source/Ui/CommentatorFrame.cpp @@ -3,6 +3,11 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/WorldFrame.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/UIUtil/Camera.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/WorldClient/World.h" // STATIC: 0x00ACE4A8 CGCommentator CGCommentator::s_Commentator; @@ -131,3 +136,44 @@ void CGCommentator::InitializeGame() { ClientServices::SetMessageHandler(SMSG_COMMENTATOR_SKIRMISH_QUEUE_RESULT1, CGCommentator::OnSkirmishPlayersInQueue, nullptr); ClientServices::SetMessageHandler(SMSG_COMMENTATOR_SKIRMISH_QUEUE_RESULT2, CGCommentator::OnSkirmishPlayersModeState, nullptr); } + +// VERIFY: 4126a5f5 manual +// OFFSET: 0x0056B510 +void CGCommentator::SnapCameraToPlayer() { + if (!CGWorldFrame::s_currentWorldFrame) { + return; + } + + CGCamera* camera = CGWorldFrame::GetActiveCamera(); + + if (!camera) { + return; + } + + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + this->m_pitch = player->GetPitch(); + this->m_facing = player->GetFacing(); + this->m_position = player->GetPosition(); + this->m_position.z += 1.5f; + camera->CommentatorSetViewAndPosition(this->m_position, this->m_facing, this->m_pitch); +} + +// VERIFY: a88d79fe auto +// OFFSET: 0x0056B830 +void CGCommentator::PostInit(CGPlayer_C* player) { + if (player && player->IsCommentatorUberOrInArena()) { + World::ObjectSetShadow(player->m_worldObject, 2, 2); + + if (CGWorldFrame::s_currentWorldFrame) { + CGWorldFrame::GetActiveCamera()->SetView(6, 2, 0); + CGCommentator::s_Commentator.SnapCameraToPlayer(); + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_COMMENTATOR_ENTER_WORLD, nullptr); +} diff --git a/WoW/Source/Ui/CommentatorFrame.h b/WoW/Source/Ui/CommentatorFrame.h index 7f33c1d..7132918 100644 --- a/WoW/Source/Ui/CommentatorFrame.h +++ b/WoW/Source/Ui/CommentatorFrame.h @@ -75,6 +75,7 @@ class CGCommentator { WOWGUID GetArenaMember(uint32_t index); void Init(); void OnUpdate(float elapsed); + void SnapCameraToPlayer(); void UpdateCameraVelocity(uint32_t controlFlags, int32_t canControl); }; diff --git a/WoW/Source/Ui/ContainerFrame.cpp b/WoW/Source/Ui/ContainerFrame.cpp index 3278e29..600d2ee 100644 --- a/WoW/Source/Ui/ContainerFrame.cpp +++ b/WoW/Source/Ui/ContainerFrame.cpp @@ -7,6 +7,18 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/CGBankInfo.h" #include "WoW/Source/Ui/Types.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ItemStats.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/Ui/CurrencyTypes.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/SpellBookFrame.h" +#include "WoW/Source/Ui/TradeSkillFrame.h" +#include "WoW/Source/Ui/Tutorial.h" +#include // STATIC: 0x00C23540 WOWGUID CGContainerInfo::m_containers[11]; @@ -126,3 +138,262 @@ bool CGContainerInfo::GetLuaBagAndSlot(lua_State* L, CGBag_C** bag, int32_t* slo return *slot >= 0 && *slot < (*bag)->m_numSlots; } + +// VERIFY: 15a3090a manual +// OFFSET: 0x005D7070 +void CGContainerInfo::UpdateContents(WOWGUID guid) { + CGActionBar::UpdateUsable(); + + if (guid == ClntObjMgrGetActivePlayer()) { + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_UPDATE, "%d", 0); + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_UPDATE, "%d", -2); + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_UPDATE, "%d", -4); + return; + } + + for (uint32_t i = 0; i < 11; i++) { + if (CGContainerInfo::m_containers[i] == guid) { + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_UPDATE, "%d", i + 1); + return; + } + } +} + +// VERIFY: 86768ce2 manual +// OFFSET: 0x005D7320 +void CGContainerInfo::UpdateItem(WOWGUID guid) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (item && item->m_item->m_itemFieldOwner == ClntObjMgrGetActivePlayer()) { + CGContainerInfo::UpdateContents(item->m_item->m_itemFieldContained); + } +} + +// VERIFY: dcc6ac8d manual +// OFFSET: 0x005D9540 +static void TriggerMultiCastBarUpdate(const ItemStats_C* stats) { + if (!stats) { + return; + } + + uint32_t mask = CGActionBar::GetMultiCastSlotMaskForTotemCategory(stats->m_totemCategory); + + if (!mask) { + return; + } + + if (CGTutorial::m_tutorialShown.m_count && !(CGTutorial::m_tutorialShown.m_bits.m_data[1] & 0x4000)) { + for (uint32_t i = 0; i < 4; i++) { + if (((1 << i) & mask) && CGSpellBook::m_totemSpells[i].Count()) { + CGTutorial::TriggerTutorial(46); + break; + } + } + } + + CGActionBar::UpdateMultiCastBar(); +} + +// VERIFY: d0cc9bd0 auto +// OFFSET: 0x005D95C0 +static void MultiCastBarItemStatsCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (success) { + WOWGUID none = WOWGUID(); + TriggerMultiCastBarUpdate(g_itemDBCache.GetRecord(id, none, nullptr, nullptr, false)); + } +} + +// VERIFY: 5cd3b92a manual +// OFFSET: 0x005D9600 +int32_t UpdateContainerContents(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param) { + CGContainer_C* container = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_CONTAINER, __FILE__, __LINE__)); + + if (!container) { + return 1; + } + + uint32_t slot = (fieldOffset - offsetof(CGContainerData, m_containerFieldSlot1)) / sizeof(WOWGUID); + CGBag_C* bag = container->GetBag(); + WOWGUID newGuid = slot < static_cast(bag->m_numSlots) ? bag->m_slots[slot] : WOWGUID(); + const WOWGUID& oldGuid = *static_cast(oldValue); + CGItem_C* oldItem = static_cast(ClntObjMgrObjectPtr(oldGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + CGItem_C* newItem = static_cast(ClntObjMgrObjectPtr(newGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (oldGuid != newGuid) { + if (oldItem) { + CGActionBar::UpdateItem(oldItem->m_obj->m_entryID); + } + + if (newItem) { + CGActionBar::UpdateItem(newItem->m_obj->m_entryID); + } + + CGTradeSkillInfo::RefreshList(0); + } + + CGGameUI::UnlockItem(newGuid); + + if (CGGameUI::unk_BD08B0 == oldGuid || CGGameUI::unk_BD08B0 == newGuid || (!CGGameUI::unk_BD08B0 && CGGameUI::unk_BD08A4)) { + ItemRec* item = g_itemDB.GetRecord(CGGameUI::unk_BD08A4); + + if (item) { + SI2::PlayItemSound(1, item->m_displayInfoID); + } + } + + CGGameUI::unk_BD08B0 = WOWGUID(); + CGGameUI::unk_BD08A4 = 0; + CGContainerInfo::UpdateContents(guid); + + if (newItem) { + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(newItem->m_obj->m_entryID, none, MultiCastBarItemStatsCallback, nullptr, false); + + if (stats) { + TriggerMultiCastBarUpdate(stats); + } + } + + return 1; +} + +// VERIFY: df5fd68c manual +// OFFSET: 0x005D9790 +int32_t UpdateInvContents(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return 1; + } + + uint32_t slot = (fieldOffset - offsetof(CGPlayerLocalData, m_playerFieldInvSlotHead)) / sizeof(WOWGUID); + WOWGUID newGuid = slot < static_cast(player->m_bag.m_numSlots) ? player->m_bag.m_slots[slot] : WOWGUID(); + const WOWGUID& oldGuid = *static_cast(oldValue); + CGItem_C* oldItem = static_cast(ClntObjMgrObjectPtr(oldGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + CGItem_C* newItem = static_cast(ClntObjMgrObjectPtr(newGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (oldGuid != newGuid) { + if (oldItem) { + CGActionBar::UpdateItem(oldItem->m_obj->m_entryID); + } + + if (newItem) { + CGActionBar::UpdateItem(newItem->m_obj->m_entryID); + } + + CGTradeSkillInfo::RefreshList(0); + } + + CGGameUI::UnlockItem(newGuid); + + if (CGGameUI::unk_BD08B0 == oldGuid || CGGameUI::unk_BD08B0 == newGuid || (!CGGameUI::unk_BD08B0 && CGGameUI::unk_BD08A4)) { + ItemRec* item = g_itemDB.GetRecord(CGGameUI::unk_BD08A4); + + if (item) { + SI2::PlayItemSound(1, item->m_displayInfoID); + } + } + + CGGameUI::unk_BD08B0 = WOWGUID(); + CGGameUI::unk_BD08A4 = 0; + CGContainerInfo::UpdateContents(guid); + + if ((oldItem && oldItem->GetClassID() == 10) || (newItem && newItem->GetClassID() == 10) || slot - 118 <= 31) { + CGCurrencyTypes::EnterWorld(); + } + + if (newItem) { + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(newItem->m_obj->m_entryID, none, MultiCastBarItemStatsCallback, nullptr, false); + + if (stats) { + TriggerMultiCastBarUpdate(stats); + } + } + + return 1; +} + +// VERIFY: 6dd08087 manual +// OFFSET: 0x005D9960 +void CGContainerInfo::UpdateContainers() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + for (uint32_t i = 0; i < 11; i++) { + uint32_t slot = i < 4 ? i + 19 : i + 63; + WOWGUID guid = slot < static_cast(player->m_bag.m_numSlots) ? player->m_bag.m_slots[slot] : WOWGUID(); + + if (guid == CGContainerInfo::m_containers[i]) { + continue; + } + + if (CGContainerInfo::m_containers[i]) { + CGContainer_C* old = static_cast(ClntObjMgrObjectPtr(CGContainerInfo::m_containers[i], TYPEMASK_CONTAINER, __FILE__, __LINE__)); + + if (old && old->GetBag()) { + int32_t count = old->GetBag()->m_numSlots; + + for (int32_t j = 0; j < count; j++) { + ClntObjMgrUnsetObjMirrorHandler(CGContainerInfo::m_containers[i], ID_CONTAINER, offsetof(CGContainerData, m_containerFieldSlot1) + j * sizeof(WOWGUID), UpdateContainerContents, nullptr); + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_CLOSED, "%d", i + 1); + } + + CGContainerInfo::m_containers[i] = guid; + + if (guid) { + CGContainer_C* container = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_CONTAINER, __FILE__, __LINE__)); + + if (container && container->GetBag()) { + int32_t count = container->GetBag()->m_numSlots; + + for (int32_t j = 0; j < count; j++) { + ClntObjMgrSetObjMirrorHandler(guid, ID_CONTAINER, offsetof(CGContainerData, m_containerFieldSlot1) + j * sizeof(WOWGUID), sizeof(WOWGUID), UpdateContainerContents, nullptr, static_cast(0), 1); + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_BAG_UPDATE, "%d", i + 1); + } + } +} + +// VERIFY: 4c8ee089 manual +// OFFSET: 0x005D9B40 +int32_t InvUpdateHandler(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return 1; + } + + uint32_t slot = (fieldOffset - offsetof(CGPlayerLocalData, m_playerFieldInvSlotHead)) / sizeof(WOWGUID); + + if (slot < static_cast(player->m_bag.m_numSlots) && player->m_bag.m_slots[slot]) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(player->m_bag.m_slots[slot], TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (item && (item->m_obj->m_type & TYPEMASK_CONTAINER)) { + CGBag_C* bag = item->GetBag(); + + if (bag) { + for (uint32_t i = 0; i < static_cast(bag->m_numSlots); i++) { + CGItem_C* contained = bag->GetItemPointer(i); + + if (contained) { + CGActionBar::UpdateItem(contained->m_obj->m_entryID); + } + } + } + } + } + + CGContainerInfo::UpdateContents(guid); + CGContainerInfo::UpdateContainers(); + CGTradeSkillInfo::RefreshList(0); + return 1; +} diff --git a/WoW/Source/Ui/ContainerFrame.h b/WoW/Source/Ui/ContainerFrame.h index 121b074..b036def 100644 --- a/WoW/Source/Ui/ContainerFrame.h +++ b/WoW/Source/Ui/ContainerFrame.h @@ -12,20 +12,19 @@ class CGContainerInfo { public: static WOWGUID m_containers[11]; static void UpdateContainers(); + static void OpenContainer(WOWGUID guid); static void EnterWorld(); static void UpdateCooldowns(); static void UpdateItem(WOWGUID guid); + static void UpdateContents(WOWGUID guid); static bool GetLuaBagAndSlot(lua_State* L, CGBag_C** bag, int32_t* slot, int32_t* bank); }; int32_t Script_GetContainerItemID(lua_State* L); int32_t Script_GetContainerItemLink(lua_State* L); -int32_t Script_GetContainerItemCooldown(lua_State* L); int32_t Script_PickupContainerItem(lua_State* L); int32_t Script_SplitContainerItem(lua_State* L); -int32_t Script_UseContainerItem(lua_State* L); int32_t Script_SocketContainerItem(lua_State* L); -int32_t Script_ShowContainerSellCursor(lua_State* L); int32_t Script_SetBagPortraitTexture(lua_State* L); int32_t Script_GetContainerItemDurability(lua_State* L); int32_t Script_GetContainerFreeSlots(lua_State* L); @@ -38,6 +37,7 @@ void ContainerRegisterScriptFunctions(); int32_t InvUpdateHandler(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param); int32_t UpdateInvContents(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param); +int32_t UpdateContainerContents(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param); WOWGUID GetBagAtIndex(uint32_t index); diff --git a/WoW/Source/Ui/ContainerFrame_Scripts.cpp b/WoW/Source/Ui/ContainerFrame_Scripts.cpp index 1d63104..679f604 100644 --- a/WoW/Source/Ui/ContainerFrame_Scripts.cpp +++ b/WoW/Source/Ui/ContainerFrame_Scripts.cpp @@ -13,6 +13,18 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/UIUtil/Tooltip.h" #include "WoW/Source/Ui/CGBankInfo.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/UIUtil/Cursor.h" +#include "WoW/Source/Ui/AuctionHouse.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/GuildBankFrame.h" +#include "WoW/Source/Ui/MailInfo.h" +#include "WoW/Source/Ui/MerchantFrame.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Ui/TradeFrame.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/Base/CDataStore.h" // VERIFY: ebcdce34 auto // OFFSET: 0x005D6FF0 @@ -208,7 +220,213 @@ static int32_t Script_GetContainerItemInfo(lua_State* L) { return 7; } +// VERIFY: 2cd3f9c3 manual +// OFFSET: 0x005D7D90 +static int32_t Script_GetContainerItemCooldown(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: GetContainerItemCooldown(index, slot)"); + return 0; + } + + CGBag_C* bag; + int32_t slot; + int32_t bank; + CGItem_C* item; + + if (CGContainerInfo::GetLuaBagAndSlot(L, &bag, &slot, &bank) && (item = bag->GetItemPointer(slot)) && (!item->GetUsableSpellCharges() || item->GetCurrentSpellCharges() || (item->GetUsableSpellCharges() < 0 && !item->GetCurrentSpellCharges()))) { + uint32_t start = 0; + uint32_t duration = 0; + uint32_t enable = 0; + Spell_C_GetItemCooldown(item, &duration, &start, &enable); + lua_pushnumber(L, start * 0.001); + lua_pushnumber(L, duration * 0.001); + lua_pushnumber(L, enable); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + } + + return 3; +} + // STATIC: 0x00AD0D50 +// VERIFY: 0745872b manual +// OFFSET: 0x005D8650 +static int32_t Script_UseContainerItem(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: UseContainerItem(index, slot[, target])"); + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return 0; + } + + CGBag_C* bag; + int32_t slot; + int32_t bank; + + if (!CGContainerInfo::GetLuaBagAndSlot(L, &bag, &slot, &bank)) { + return 0; + } + + WOWGUID target; + + if (!Script_GetGUIDFromToken(lua_tolstring(L, 3, nullptr), target, true)) { + return 0; + } + + CGGameUI::ClearCursor(1, 1); + CGItem_C* item = bag->GetItemPointer(slot); + + if (!item || (item->m_itemFlags & 1)) { + return 0; + } + + WOWGUID guid = item->m_obj->m_guid; + int32_t itemId = item->m_obj->m_entryID; + + if (Spell_C_IsTargeting() && !Spell_C_CanTargetItems()) { + Spell_C_StopTargeting(); + } + + if (Spell_C_IsTargeting()) { + CGGameUI::CastItemSpell(guid, 0); + return 0; + } + + if (CursorGetResetMode() == 17 && CGMerchantInfo::CanRepair()) { + uint32_t cost = CGMerchantInfo::GetRepairCost(item); + + if (cost <= player->GetCoinage()) { + SI2::PlaySoundKit("ITEM_REPAIR", nullptr, nullptr, nullptr); + CDataStore msg; + msg.Put(static_cast(CMSG_REPAIR_ITEM)); + msg.Put(CGMerchantInfo::m_merchant.m_guid); + msg.Put(guid.m_guid); + msg.Put(static_cast(0)); + msg.Finalize(); + ClientServices::Send2(&msg); + } else { + CGGameUI::DisplayError(ERR_NOT_ENOUGH_MONEY); + } + + return 0; + } + + if (bank) { + player->AutoStoreBankItem(bag->m_guid, slot); + CGGameUI::SetPendingItemSound(guid, itemId); + CGGameUI::LockItem(guid); + return 0; + } + + if (CGBankInfo::m_banker) { + player->AutoBankItem(bag->m_guid, slot); + CGGameUI::SetPendingItemSound(guid, itemId); + CGGameUI::LockItem(guid); + return 0; + } + + if (CGMerchantInfo::m_merchant) { + player->SellItem(CGMerchantInfo::m_merchant, guid, 0); + CGGameUI::LockItem(guid); + return 0; + } + + if (CGMailInfo::m_sendMailShowing && CGMailInfo::m_object) { + CGMailInfo::AddItemToOutgoingMail(-1, guid, bag->m_guid, slot); + return 0; + } + + if (CGAuctionHouse::m_auctionsTabShowing && CGAuctionHouse::m_auctioneer) { + if (!CGAuctionHouse::IsSellItemValid(item, 1)) { + return 0; + } + + WOWGUID sellItem; + uint8_t sellBag; + uint8_t sellSlot; + CGAuctionHouse::GetSellItem(&sellItem, &sellBag, &sellSlot); + + if (sellItem) { + CGGameUI::UnlockItem(sellItem); + } + + CGGameUI::LockItem(guid); + CGAuctionHouse::SetSellItem(guid, bag->m_guid, slot); + FrameScript_SignalEvent(SCRIPT_EVENT_NEW_AUCTION_UPDATE, nullptr); + return 0; + } + + if (CGTradeInfo::m_tradingPlayer) { + int32_t enchant = item->GetEnchantmentSpell(53) || item->GetEnchantmentSpell(54) || item->GetEnchantmentSpell(156) || item->GetEnchantmentSpell(33); + + if (CGTradeInfo::m_enchantingItem && enchant) { + CGTradeInfo::SetEnchantingItem(item); + } else { + CGTradeInfo::AddPlayerItem(guid, bag->m_guid, slot); + } + + return 0; + } + + if (CGGuildBankInfo::m_banker) { + CGGuildBankInfo::AutoStoreItem(guid, bag->m_guid, slot); + CGGameUI::SetPendingItemSound(guid, itemId); + return 0; + } + + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(item->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (item->GetInventoryType() && (!stats || !stats->m_startQuest)) { + if (CGGameUI::m_hasControl || (player->m_unit->m_unitFieldFlags & 0x100000)) { + player->AutoEquipItem(bag->m_guid, slot, 0); + } + + return 0; + } + + if (stats && stats->m_class == 16) { + FrameScript_SignalEvent(SCRIPT_EVENT_USE_GLYPH, nullptr); + } + + item->UseItem(&target, 0); + return 0; +} + +// VERIFY: 5b61867b auto +// OFFSET: 0x005D8BD0 +static int32_t Script_ShowContainerSellCursor(lua_State* L) { + if (Spell_C_IsTargeting() || CursorGetResetMode() != 1) { + return 0; + } + + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: ShowContainerSellCursor(index, slot)"); + } + + CGBag_C* bag; + int32_t slot; + int32_t bank; + + if (!CGContainerInfo::GetLuaBagAndSlot(L, &bag, &slot, &bank)) { + return 0; + } + + CGItem_C* item = bag->GetItemPointer(slot); + + if (!item || (item->m_itemFlags & 1)) { + return 0; + } + + CursorSetMode(3); + return 0; +} + static FrameScript_Method s_ScriptFunctions[] = { { "ContainerIDToInventoryID", &Script_ContainerIDToInventoryID }, { "GetContainerNumSlots", &Script_GetContainerNumSlots }, diff --git a/WoW/Source/Ui/CurrencyTypes.cpp b/WoW/Source/Ui/CurrencyTypes.cpp index dd9f9f1..f8c0bfc 100644 --- a/WoW/Source/Ui/CurrencyTypes.cpp +++ b/WoW/Source/Ui/CurrencyTypes.cpp @@ -4,6 +4,16 @@ #include "Engine/Source/Storm/H/storm.h" #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/CurrencyCategoryRec.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/DB/Rec/CurrencyTypesRec.h" +#include "WoW/Source/Object/ItemStats.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/Types.h" // STATIC: 0x00C1F44C int32_t CGCurrencyTypes::m_listSize; @@ -56,3 +66,179 @@ void CGCurrencyTypes::InitializeGame() { CGCurrencyTypes::m_listSize = 0; memset(CGCurrencyTypes::m_list, 0, sizeof(CGCurrencyTypes::m_list)); } + +// VERIFY: cd06e9a4 manual +// OFFSET: 0x005AFE30 +int32_t CGCurrencyTypes::CategoryHasKnownTypes(int32_t index, uint32_t known1, uint32_t known2, uint32_t unused1, uint32_t unused2) { + for (int32_t i = 0; i < g_currencyTypesDB.m_numRecords; i++) { + CurrencyTypesRec* rec = g_currencyTypesDB.GetRecordByIndex(i); + + if (!rec || (CGCurrencyTypes::m_categories[index].m_id != rec->m_categoryID && index != CGCurrencyTypes::m_numCategories - 1)) { + continue; + } + + uint32_t known = 0; + uint32_t unused = 0; + uint32_t mask = 0; + + if (rec->m_bitIndex <= 32) { + if (rec->m_bitIndex > 0) { + known = known1; + unused = unused1; + mask = 1 << (rec->m_bitIndex - 1); + } + } else { + known = known2; + unused = unused2; + mask = 1 << (rec->m_bitIndex - 33); + } + + if ((CGCurrencyTypes::m_categories[index].m_id == rec->m_categoryID && (mask & known)) || (index == CGCurrencyTypes::m_numCategories - 1 && (mask & unused))) { + return 1; + } + } + + return 0; +} + +// VERIFY: ef8fc97b manual +// OFFSET: 0x005AFF10 +int32_t CGCurrencyTypes::DisplayListSortCallback(const void* a, const void* b) { + const CurrencyListEntry* entryA = static_cast(a); + const CurrencyListEntry* entryB = static_cast(b); + + if (!entryA || !entryB) { + return 0; + } + + ItemStats_C* statsA = g_itemDBCache.GetRecord(entryA->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false); + ItemStats_C* statsB = g_itemDBCache.GetRecord(entryB->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false); + + if (!statsA) { + return statsB != nullptr; + } + + if (!statsB) { + return -1; + } + + const char* nameA = statsA->GetName(0); + const char* nameB = statsB->GetName(0); + + if (!nameA) { + return nameB != nullptr; + } + + if (!nameB) { + return -1; + } + + return SStrSortUTF8I(nameA, nameB, STORM_MAX_STR); +} + +// VERIFY: f01a5b7c manual +// OFFSET: 0x005B0030 +void CGCurrencyTypes::BuildDisplayList() { + CGCurrencyTypes::m_listSize = 0; + memset(CGCurrencyTypes::m_list, 0, sizeof(CGCurrencyTypes::m_list)); + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + uint64_t knownCurrencies = static_cast(player->m_player)->m_playerFieldKnownCurrencies.m_guid; + uint32_t known1 = static_cast(knownCurrencies); + uint32_t known2 = static_cast(knownCurrencies >> 32); + uint32_t unused1 = g_currencyTokensUnused1CVar->m_intValue; + uint32_t unused2 = g_currencyTokensUnused2CVar->m_intValue; + uint32_t backpack1 = g_currencyTokensBackpack1CVar->m_intValue; + uint32_t backpack2 = g_currencyTokensBackpack2CVar->m_intValue; + auto callback = reinterpret_cast(&CGCurrencyTypes::EnterWorld); + + for (int32_t category = 0; category < CGCurrencyTypes::m_numCategories; category++) { + if (!CGCurrencyTypes::CategoryHasKnownTypes(category, known1, known2, unused1, unused2)) { + continue; + } + + CurrencyListEntry* header = &CGCurrencyTypes::m_list[CGCurrencyTypes::m_listSize++]; + header->m_name = CGCurrencyTypes::m_categories[category].m_name; + header->m_isHeader = 1; + header->m_isExpanded = CGCurrencyTypes::m_categories[category].m_expanded; + header->m_categoryID = CGCurrencyTypes::m_categories[category].m_id; + + if (!CGCurrencyTypes::m_categories[category].m_expanded) { + continue; + } + + int32_t first = CGCurrencyTypes::m_listSize; + + for (int32_t i = 0; i < g_currencyTypesDB.m_numRecords; i++) { + CurrencyTypesRec* rec = g_currencyTypesDB.GetRecordByIndex(i); + + if (!rec) { + continue; + } + + uint32_t known; + uint32_t unused; + uint32_t backpack; + uint32_t mask; + + if (rec->m_bitIndex <= 32) { + if (rec->m_bitIndex <= 0) { + continue; + } + + known = known1; + unused = unused1; + backpack = backpack1; + mask = 1 << (rec->m_bitIndex - 1); + } else { + known = known2; + unused = unused2; + backpack = backpack2; + mask = 1 << (rec->m_bitIndex - 33); + } + + if (!(mask & known)) { + continue; + } + + const char* name; + + if (category == CGCurrencyTypes::m_numCategories - 1) { + if (!(mask & unused)) { + continue; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(rec->m_itemID, ClntObjMgrGetActivePlayer(), callback, nullptr, true); + name = stats ? stats->m_name[0] : nullptr; + } else { + if (rec->m_categoryID != CGCurrencyTypes::m_categories[category].m_id || (mask & unused)) { + continue; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(rec->m_itemID, ClntObjMgrGetActivePlayer(), callback, nullptr, true); + name = stats ? stats->GetName(0) : nullptr; + } + + CurrencyListEntry* entry = &CGCurrencyTypes::m_list[CGCurrencyTypes::m_listSize++]; + entry->m_name = name; + entry->m_itemID = rec->m_itemID; + entry->m_categoryID = rec->m_categoryID; + entry->m_isWatched = (backpack & mask) != 0; + } + + if (CGCurrencyTypes::m_listSize - first > 1) { + qsort(&CGCurrencyTypes::m_list[first], CGCurrencyTypes::m_listSize - first, sizeof(CurrencyListEntry), CGCurrencyTypes::DisplayListSortCallback); + } + } +} + +// VERIFY: b46648dc auto +// OFFSET: 0x005B0660 +void CGCurrencyTypes::EnterWorld() { + CGCurrencyTypes::BuildDisplayList(); + FrameScript_SignalEvent(SCRIPT_EVENT_CURRENCY_DISPLAY_UPDATE, nullptr); +} diff --git a/WoW/Source/Ui/CurrencyTypes.h b/WoW/Source/Ui/CurrencyTypes.h index 85042a8..337ff71 100644 --- a/WoW/Source/Ui/CurrencyTypes.h +++ b/WoW/Source/Ui/CurrencyTypes.h @@ -15,10 +15,10 @@ struct CurrencyCategoryInfo { struct CurrencyListEntry { /* 0000 */ const char* m_name; /* 0004 */ int32_t m_itemID; - /* 0008 */ int32_t unk_0008; + /* 0008 */ int32_t m_categoryID; /* 000C */ int32_t m_isHeader; /* 0010 */ int32_t m_isExpanded; - /* 0014 */ int32_t m_isUnused; + /* 0014 */ int32_t m_isWatched; }; class CGCurrencyTypes { @@ -27,7 +27,10 @@ class CGCurrencyTypes { static CurrencyListEntry m_list[95]; static CurrencyCategoryInfo m_categories[32]; static int32_t m_numCategories; + static void BuildDisplayList(); + static int32_t CategoryHasKnownTypes(int32_t index, uint32_t known1, uint32_t known2, uint32_t unused1, uint32_t unused2); static int32_t CurrencyCategorySortCallback(const void* a, const void* b); + static int32_t DisplayListSortCallback(const void* a, const void* b); static void InitializeGame(); static void EnterWorld(); }; diff --git a/WoW/Source/Ui/DanceStudio.cpp b/WoW/Source/Ui/DanceStudio.cpp index c8c839c..92c465e 100644 --- a/WoW/Source/Ui/DanceStudio.cpp +++ b/WoW/Source/Ui/DanceStudio.cpp @@ -1,5 +1,9 @@ #include "DanceStudio.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/Base/CDataStore.h" + +// STATIC: 0x00BEB630 +uint64_t CGDanceStudio::m_learnedDanceMoves; // VERIFY: 166fac44 auto // OFFSET: 0x00576A90 @@ -9,3 +13,10 @@ void CGDanceStudio::InitializeGame() { ClientServices::SetMessageHandler(SMSG_NOTIFY_DANCE, Packet_SMSG_NOTIFY_DANCE, nullptr); ClientServices::SetMessageHandler(SMSG_LEARNED_DANCE_MOVES, Packet_SMSG_LEARNED_DANCE_MOVES, nullptr); } + +// VERIFY: 4758a0e1 auto +// OFFSET: 0x005758A0 +int32_t Packet_SMSG_LEARNED_DANCE_MOVES(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + msg->Get(CGDanceStudio::m_learnedDanceMoves); + return 1; +} diff --git a/WoW/Source/Ui/DanceStudio.h b/WoW/Source/Ui/DanceStudio.h index 939c092..45c4730 100644 --- a/WoW/Source/Ui/DanceStudio.h +++ b/WoW/Source/Ui/DanceStudio.h @@ -15,6 +15,8 @@ int32_t Packet_SMSG_LEARNED_DANCE_MOVES(void* param, NETMESSAGE msgId, uint32_t class CGDanceStudio { public: + static uint64_t m_learnedDanceMoves; + static void InitializeGame(); static void LoadDance(int32_t danceId); static void RegisterScriptFunctions(); diff --git a/WoW/Source/Ui/EquipmentManager.cpp b/WoW/Source/Ui/EquipmentManager.cpp index 141313e..b0e510d 100644 --- a/WoW/Source/Ui/EquipmentManager.cpp +++ b/WoW/Source/Ui/EquipmentManager.cpp @@ -1,4 +1,5 @@ #include "EquipmentManager.h" +#include "Engine/Source/Base/CDataStore.h" #include "Engine/Source/ConsoleBase/ConsoleVar.h" #include "WoW/Source/Ui/ActionBarFrame.h" #include @@ -14,6 +15,9 @@ uint32_t* CGEquipmentManager::s_equipmentSetHeap; // STATIC: 0x00C1E954 uint8_t CGEquipmentManager::m_lastCanUseEquipmentSetsValue; +// STATIC: 0x00C1E955 +uint8_t CGEquipmentManager::m_loaded; + // STATIC: 0x00C1E956 uint8_t CGEquipmentManager::m_swapPending; @@ -117,3 +121,66 @@ const EQUIPMENT_SET* CGEquipmentManager::GetSetByID(int32_t id) { return nullptr; } + +// INLINED +EQUIPMENT_SET::EQUIPMENT_SET() { + this->m_guid = WOWGUID{ 0 }; + memset(this->m_items, 0, sizeof(this->m_items)); + this->unk_0230 = 0; +} + +// VERIFY: 816e8bf2 manual +// OFFSET: 0x005AF490 +int32_t Packet_SMSG_EQUIPMENT_SET_LIST(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + uint32_t count = 0; + msg->Get(count); + + uint32_t existing = 0; + + for (EQUIPMENT_SET_NODE* node = CGEquipmentManager::s_equipmentSets.Head(); !CGEquipmentManager::s_equipmentSets.IsEnd(node); node = CGEquipmentManager::s_equipmentSets.RawNext(node)) { + existing++; + } + + if (CGEquipmentManager::m_loaded && count == existing) { + msg->m_read = msg->m_size; + return 1; + } + + if (existing) { + for (EQUIPMENT_SET_NODE* node = CGEquipmentManager::s_equipmentSets.Head(); !CGEquipmentManager::s_equipmentSets.IsEnd(node); node = CGEquipmentManager::s_equipmentSets.RawNext(node)) { + ObjectFree(*CGEquipmentManager::s_equipmentSetHeap, node->m_set->m_handle); + } + + CGEquipmentManager::s_equipmentSets.Clear(); + } + + for (int32_t i = 0; i < static_cast(count) && i < 10; i++) { + EQUIPMENT_SET* set = nullptr; + uint32_t handle; + void* object = nullptr; + + if (ObjectAlloc(*CGEquipmentManager::s_equipmentSetHeap, &handle, &object, false)) { + set = object ? new (object) EQUIPMENT_SET() : nullptr; + set->m_handle = handle; + } + + SmartGUID guid; + *msg >> guid; + set->m_guid = guid; + msg->Get(reinterpret_cast(set->m_id)); + msg->GetString(set->m_name, sizeof(set->m_name)); + msg->GetString(set->m_icon, sizeof(set->m_icon)); + + for (uint32_t slot = 0; slot < 19; slot++) { + SmartGUID item; + *msg >> item; + set->m_items[slot] = item; + } + + EQUIPMENT_SET_NODE* node = CGEquipmentManager::s_equipmentSets.NewNode(2, 0, 0); + node->m_set = set; + } + + CGEquipmentManager::m_loaded = 1; + return 1; +} diff --git a/WoW/Source/Ui/EquipmentManager.h b/WoW/Source/Ui/EquipmentManager.h index c84f8a3..b870190 100644 --- a/WoW/Source/Ui/EquipmentManager.h +++ b/WoW/Source/Ui/EquipmentManager.h @@ -15,9 +15,12 @@ struct EQUIPMENT_SET { /* 0008 */ WOWGUID m_guid; /* 0010 */ int32_t m_id; /* 0014 */ char m_icon[256]; - /* 0114 */ char m_name[132]; + /* 0114 */ char m_name[128]; + /* 0194 */ uint32_t unk_0194; /* 0198 */ WOWGUID m_items[19]; /* 0230 */ uint32_t unk_0230; + + EQUIPMENT_SET(); }; struct EQUIPMENT_SET_NODE : public TSLinkedNode { @@ -34,6 +37,7 @@ class CGEquipmentManager { static TSList s_equipmentSets; static void EnterWorld(); static uint8_t m_lastCanUseEquipmentSetsValue; + static uint8_t m_loaded; static uint8_t m_swapPending; static int32_t m_ignoredSlots[19]; static int32_t m_pendingSetID; diff --git a/WoW/Source/Ui/GameUI.cpp b/WoW/Source/Ui/GameUI.cpp index 9f929a1..0bf83c4 100644 --- a/WoW/Source/Ui/GameUI.cpp +++ b/WoW/Source/Ui/GameUI.cpp @@ -145,6 +145,9 @@ #include "Engine/Source/Base/CDataStore.h" #include "WoW/Source/Object/ObjectClient/GameObject_C.h" #include "WoW/Source/DB/Rec/AreaTableRec.h" +#include "WoW/Source/DB/Rec/ItemSubClassRec.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentRec.h" +#include "WoW/Source/Object/ItemStats.h" // STATIC: 0x00AC804C const char* g_macroTaint = ""; @@ -3727,3 +3730,888 @@ void CGGameUI::SetAreaSpiritHealer(WOWGUID guid) { msg.Finalize(); ClientServices::Send2(&msg); } + +// VERIFY: fe5eee3d auto +// OFFSET: 0x00513DF0 +const char* CGGameUI::LastErrorMessage() { + return CGGameUI::m_lastErrorMessage; +} + +// VERIFY: 70b79013 auto +// OFFSET: 0x00513A00 +void CGGameUI::SetLastEnchantSpellID(int32_t spellId) { + CGGameUI::m_lastEnchantSpellID = spellId; +} + +// VERIFY: 129c4ede auto +// OFFSET: 0x00513A10 +void CGGameUI::SetLastItemSpellTarget(WOWGUID guid) { + CGGameUI::m_lastItemSpellTarget = guid; +} + +// VERIFY: 86781bd1 auto +// OFFSET: 0x00513410 +void CGGameUI::ShowSpellMissFeedback(const WOWGUID& guid, int32_t reason) { + if (static_cast(reason) > 11) { + return; + } + + uint32_t schoolMask = GetPhysicalDamageClassMask(); + const char* missString = g_spellMissStrings[reason]; + int32_t count; + char** tokens = Script_GetTokenIDsFromGUID(guid, &count); + + for (int32_t i = 0; i < count; i++) { + FrameScript_SignalEvent(SCRIPT_EVENT_UNIT_COMBAT, "%s%s%s%d%d", tokens[i], missString, "", 0, schoolMask); + } +} + +// VERIFY: a27dcaba manual +// OFFSET: 0x00513480 +void CGGameUI::ShowHealingFeedback(const WOWGUID& guid, int32_t amount, bool crit) { + if (amount) { + CGGameUI::SignalUnitCombat(guid, "HEAL", amount, GetPhysicalDamageClassMask(), crit ? 0x200 : 0); + } +} + +void CGGameUI::ShowEnergizeFeedback(const WOWGUID& guid, int32_t powerType, int32_t amount) { +} + +// VERIFY: c776ed02 auto +// OFFSET: 0x005132C0 +void CGGameUI::SignalUnitCombat(const WOWGUID& guid, const char* action, int32_t amount, uint32_t schoolMask, uint32_t flags) { + const char* modifier = ""; + + if (amount <= 0) { + if (flags & 0x20) { + modifier = "ABSORB"; + } else if (flags & 0x2000) { + modifier = "BLOCK"; + } else if (flags & 0x80) { + modifier = "RESIST"; + } + } else if (flags & 0x200) { + modifier = "CRITICAL"; + } else if (flags & 0x10000) { + modifier = "GLANCING"; + } else if (flags & 0x20000) { + modifier = "CRUSHING"; + } + + int32_t count; + char** tokens = Script_GetTokenIDsFromGUID(guid, &count); + + for (int32_t i = 0; i < count; i++) { + FrameScript_SignalEvent(SCRIPT_EVENT_UNIT_COMBAT, "%s%s%s%d%d", tokens[i], action, modifier, amount, schoolMask); + } +} + +// VERIFY: d84ea422 manual +// OFFSET: 0x00513990 +TotemInfo* CGGameUI::GetTotemInfo(uint32_t slot) { + if (slot > 3) { + return nullptr; + } + + return &CGGameUI::m_totems[slot]; +} + +// VERIFY: c8b72b4a manual +// OFFSET: 0x005139B0 +TotemInfo* CGGameUI::GetTotemInfo(WOWGUID guid) { + if (!guid.m_guid) { + return nullptr; + } + + for (uint32_t i = 0; i < 4; i++) { + if (CGGameUI::m_totems[i].m_guid == guid) { + return &CGGameUI::m_totems[i]; + } + } + + return nullptr; +} + +// VERIFY: 90d8260a manual +// OFFSET: 0x00513F50 +uint32_t TotemInfo::GetSpawnTimeLeft() { + uint32_t now = OsGetAsyncTimeMs(); + uint32_t end = this->m_duration + this->m_startTime; + + if (end && static_cast(now - end) < 0) { + return end - now; + } + + return 0; +} + +// VERIFY: 6fabf948 manual +// OFFSET: 0x0051F710 +void CGGameUI::CastSpiritHealSpell() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + SpellRec spell; + + if (g_spellDB.GetRecord(2584, &spell) && player) { + Spell_C_CancelAura(&spell, player, -1); + } +} + +// VERIFY: cd2d4923 auto +// OFFSET: 0x00513380 +void CGGameUI::ShowCombatFeedback(const WOWGUID& guid, int32_t amount, uint32_t schoolMask, uint32_t flags) { + CGGameUI::SignalUnitCombat(guid, "WOUND", amount, schoolMask, flags); +} + +// STATIC: 0x00BD08D8 +WOWGUID CGGameUI::m_pendingItem; + +struct NearestUnitData { + /* 0000 */ WOWGUID m_guid; + /* 0008 */ float m_distanceSq; + /* 000C */ int32_t m_inFront; +}; + +// STATIC: 0x00BD08C8 +static uint32_t s_nearestIndex; + +// STATIC: 0x00BD08CC +static uint32_t s_nearestSortTime; + +// STATIC: 0x00BD08D0 +static uint32_t s_nearestTargetTime; + +// STATIC: 0x00BD08D4 +static int32_t s_nearestType; + +// STATIC: 0x00BD0BFC +static TSGrowableArray s_nearestUnits; + +// VERIFY: de8a3c92 manual +// OFFSET: 0x005210D0 +void CGGameUI::CastItemSpell(WOWGUID guid, int32_t confirmed) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (!item) { + return; + } + + SpellRec spell; + PendingSpellCast* cast = Spell_C_GetTargetingSpellCast(); + + if (!cast || !g_spellDB.GetRecord(cast->m_data.m_spellId, &spell)) { + return; + } + + for (uint32_t i = 0; i < 3; i++) { + int32_t effect = spell.m_effect[i]; + + if (effect == 53 || effect == 54 || effect == 156) { + if (item->GetItemStaticFlags(0) & 0x2000) { + return; + } + + bool matchesSubclass = false; + + if (spell.m_effectMiscValueB[i]) { + const ItemSubClassRec* subclass = SDBItemSubclassGetSubClassRec(7, spell.m_effectMiscValueB[i]); + + if (subclass && subclass->m_subClassID == static_cast(item->GetSubtypeID()) && subclass->m_classID == static_cast(item->GetClassID())) { + matchesSubclass = true; + } + } + + if (spell.m_equippedItemSubclass && (spell.m_equippedItemClass != static_cast(item->GetClassID()) || !((1 << item->GetSubtypeID()) & spell.m_equippedItemSubclass)) && !matchesSubclass) { + Spell_C_SpellFailed(cast, &spell, 12, -1, -1, 0); + return; + } + + if (spell.m_equippedItemInvTypes && !((1 << item->GetInventoryType()) & spell.m_equippedItemInvTypes) && !matchesSubclass) { + Spell_C_SpellFailed(cast, &spell, 12, -1, -1, 0); + return; + } + + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(spell.m_effectMiscValue[i]); + + if (enchant && (enchant->m_flags & 1) && !item->IsBound() && !confirmed && item->GetInventoryType()) { + CGGameUI::m_pendingItem = item->m_obj->m_guid; + FrameScript_SignalEvent(SCRIPT_EVENT_BIND_ENCHANT, nullptr); + return; + } + + CGItem_C::ItemPurchaseData* purchase = item->m_itemPurchaseData; + + if (purchase && spell.m_effect[i] != 54 && !confirmed && static_cast(purchase->m_refundTimeLeft - ClntObjMgrGetActivePlayerObj()->GetPlayedTime() + 7200) > 0) { + CGGameUI::m_pendingItem = item->m_obj->m_guid; + FrameScript_SignalEvent(SCRIPT_EVENT_END_REFUND, "%d", 1); + return; + } + + if (item->IsBound() && !item->IsBoundForTrade() && !confirmed) { + SpellItemEnchantmentRec* boundEnchant; + + if (spell.m_effect[i] != 54 || ((boundEnchant = g_spellItemEnchantmentDB.GetRecord(spell.m_effectMiscValue[i])) && (boundEnchant->m_flags & 1))) { + CGGameUI::m_pendingItem = item->m_obj->m_guid; + FrameScript_SignalEvent(SCRIPT_EVENT_END_BOUND_TRADEABLE, "%s", "itemenchant"); + return; + } + } + + if (enchant && item->GetEnchantmentSpell(0) && !item->HasOnUseEnchant()) { + for (uint32_t j = 0; j < 3; j++) { + if (enchant->m_effect[j] == 7 && enchant->m_effectArg[j]) { + Spell_C_SpellFailed(cast, &spell, 170, -1, -1, 0); + return; + } + } + } + + uint32_t slot = spell.m_effect[i] != 53; + + if (!(item->GetItemStaticFlags(0) & 0x2000)) { + int32_t existingId = item->m_item->m_itemFieldEnchantment[slot].m_id; + + if (existingId) { + SpellItemEnchantmentRec* existing = g_spellItemEnchantmentDB.GetRecord(existingId); + + if (existing && enchant) { + CGGameUI::m_pendingItem = item->m_obj->m_guid; + FrameScript_SignalEvent(SCRIPT_EVENT_REPLACE_ENCHANT, "%s%s", existing->m_name, enchant->m_name); + return; + } + + continue; + } + } + } + + effect = spell.m_effect[i]; + + if (effect != 127 && effect != 158) { + continue; + } + + if (effect == 127 && !(item->GetItemStaticFlags(0) & 0x40000)) { + Spell_C_SpellFailed(cast, &spell, 17, -1, -1, 0); + return; + } + + if (spell.m_effect[i] == 158 && !(item->GetItemStaticFlags(0) & 0x20000000)) { + Spell_C_SpellFailed(cast, &spell, 16, -1, -1, 0); + return; + } + + WOWGUID none = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(item->m_obj->m_entryID, none, nullptr, nullptr, false); + + if (stats) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + int32_t skillIndex = player->GetSkillIndex(stats->m_requiredSkill); + + if (skillIndex < 0 || static_cast(player->GetSkillValue(skillIndex)) < static_cast(stats->m_requiredSkillRank)) { + Spell_C_SpellFailed(cast, &spell, 150, stats->m_requiredSkill, stats->m_requiredSkillRank, 0); + return; + } + } + + int32_t minPoints; + int32_t maxPoints; + Spell_C_GetMinMaxPoints(&spell, i, &minPoints, &maxPoints, 0, 0, 0, 0); + + if (item->m_item->m_itemFieldStackCount < minPoints) { + Spell_C_SpellFailed(cast, &spell, 55, item->m_obj->m_entryID, minPoints, 0); + return; + } + } + + Spell_C_HandleSpriteClick(item, nullptr); +} + +// VERIFY: 6fb7fcd5 auto +// OFFSET: 0x005131D0 +static int QSortCompareNearestUnit(const void* a, const void* b) { + const NearestUnitData* left = static_cast(a); + const NearestUnitData* right = static_cast(b); + + if (!left || !right) { + SErrDisplayAppFatalMessage("", "", 0); + } + + if (left->m_inFront != right->m_inFront) { + return 2 * (left->m_inFront == 0) - 1; + } + + if (right->m_distanceSq == left->m_distanceSq) { + return 0; + } + + return right->m_distanceSq >= left->m_distanceSq ? -1 : 1; +} + +// VERIFY: 7d0d99e3 manual +// OFFSET: 0x00518E40 +int32_t UnitMatchesTargetType(CGUnit_C* unit, CGUnit_C* target, int32_t type) { + switch (type) { + case 1: { + return unit->CanAttack(target) && !target->IsDeadOrGhost() && !(target->m_unit->m_unitDynamicFlags & 0x20) && target->GetClientStandState() != 7; + } + + case 2: { + if (!(target->m_obj->m_type & TYPEMASK_PLAYER)) { + return 0; + } + + return unit->CanAttack(target) && !target->IsDeadOrGhost() && !(target->m_unit->m_unitDynamicFlags & 0x20) && target->GetClientStandState() != 7; + } + + case 3: { + return unit->CanAssist(target, false) && target->m_unit->m_unitFieldHealth > 0; + } + + case 4: { + if (!(target->m_obj->m_type & TYPEMASK_PLAYER)) { + return 0; + } + + return unit->CanAssist(target, false) && target->m_unit->m_unitFieldHealth > 0; + } + + case 5: { + return CGPartyInfo::IsMember(target->m_obj->m_guid) ? 1 : 0; + } + + case 6: { + return CGGameUI::IsPartyMember(target->m_obj->m_guid) != 0; + } + + default: { + return 1; + } + } +} + +// VERIFY: d9fd51cd manual +// OFFSET: 0x00524440 +static int32_t TargetUpdateProc(WOWGUID guid, void* param) { + CGUnit_C* searcher = static_cast(param); + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit || unit == searcher || !UnitMatchesTargetType(searcher, unit, s_nearestType)) { + return 1; + } + + C3Vector searcherPos = searcher->GetPosition(); + C3Vector unitPos = unit->GetPosition(); + float dx = unitPos.x - searcherPos.x; + float dy = unitPos.y - searcherPos.y; + float dz = unitPos.z - searcherPos.z; + float distanceSq = dx * dx + dy * dy + dz * dz; + C3Vector targetPos = unit->GetPosition(); + C3Vector fromPos = searcher->GetPosition(); + float facingTo = CalculateFacingTo(&fromPos, &targetPos); + float delta = fmod(facingTo - searcher->GetFacing() + 12.566371f, 6.2831855f); + static float s_coneAngle = 0.52359879f; + int32_t inFront = 0; + float maxDistanceSq; + + if (s_coneAngle > delta || 6.2831855f - s_coneAngle < delta) { + maxDistanceSq = 1681.0f; + inFront = 1; + } else { + maxDistanceSq = 100.0f; + } + + if (maxDistanceSq >= distanceSq) { + CreatureTypeRec* creatureType = g_creatureTypeDB.GetRecord(unit->GetCreatureType()); + + if ((!creatureType || !(creatureType->m_flags & 1)) && World::QueryObjectVisible(unit->m_worldObject) && (!(unit->m_obj->m_type & TYPEMASK_PLAYER) || !static_cast(unit)->IsCommentatorUberOrInArena())) { + NearestUnitData* data = s_nearestUnits.New(); + data->m_distanceSq = distanceSq; + data->m_guid = guid; + data->m_inFront = inFront; + } + } + + return 1; +} + +// VERIFY: 72ff3550 manual +// OFFSET: 0x00524FC0 +void TargetNearestEnemy(int32_t reverse, int32_t type) { + while (true) { + if (lua_tainted) { + CGGameUI::ShowBlockedActionFeedback(nullptr, 0); + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + CGUnit_C* searcher = player->GetPossessedUnit(); + + if (!searcher) { + searcher = player; + } + + uint32_t count; + + if (!s_nearestSortTime || !s_nearestTargetTime || s_nearestTargetTime + 3000 <= OsGetAsyncTimeMs() || !(count = s_nearestUnits.m_count) || s_nearestType != type) { + s_nearestIndex = 0; + s_nearestSortTime = 0; + s_nearestTargetTime = 0; + s_nearestType = type; + s_nearestUnits.SetCount(0); + ClntObjMgrEnumVisibleObjects(TargetUpdateProc, searcher); + + if (!s_nearestUnits.m_count) { + if (player->GetTransportGUID() == searcher->m_obj->m_guid.m_guid) { + VehicleSeatRec* seat = player->m_vehiclePassenger ? player->m_vehiclePassenger->m_seatRec : nullptr; + + if (seat && (seat->m_flags & 0x4000)) { + searcher = player; + ClntObjMgrEnumVisibleObjects(TargetUpdateProc, player); + } + } + + if (!s_nearestUnits.m_count) { + return; + } + } + + qsort(s_nearestUnits.m_data, s_nearestUnits.m_count, sizeof(NearestUnitData), QSortCompareNearestUnit); + s_nearestSortTime = OsGetAsyncTimeMs(); + + if (!s_nearestSortTime) { + s_nearestSortTime = 1; + } + + count = s_nearestUnits.m_count; + } else if (CGGameUI::m_lockedTarget == s_nearestUnits.m_data[s_nearestIndex].m_guid) { + if (reverse) { + if (s_nearestIndex) { + s_nearestIndex--; + } else { + s_nearestIndex = s_nearestUnits.m_count - 1; + } + } else if (++s_nearestIndex >= s_nearestUnits.m_count) { + s_nearestIndex = 0; + + if (s_nearestSortTime + 1000 <= OsGetAsyncTimeMs()) { + s_nearestSortTime = 0; + continue; + } + + count = s_nearestUnits.m_count; + } + } + + if (!count) { + return; + } + + s_nearestTargetTime = OsGetAsyncTimeMs(); + uint32_t i = s_nearestIndex; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(s_nearestUnits.m_data[i].m_guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + bool restart = false; + + while (true) { + if (unit && UnitMatchesTargetType(searcher, unit, type)) { + s_nearestIndex = i; + CGGameUI::Target(s_nearestUnits.m_data[i].m_guid); + return; + } + + if (++i >= s_nearestUnits.m_count) { + i = 0; + + if (s_nearestSortTime + 1000 <= OsGetAsyncTimeMs()) { + s_nearestSortTime = 0; + restart = true; + break; + } + } + + if (i == s_nearestIndex) { + break; + } + + unit = static_cast(ClntObjMgrObjectPtr(s_nearestUnits.m_data[i].m_guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + } + + if (restart) { + continue; + } + + s_nearestUnits.SetCount(0); + return; + } +} + +// STATIC: 0x00AC8050 +static const char* s_victimStateTokens[9] = { "MISS", "WOUND", "DODGE", "PARRY", "INTERRUPT", "BLOCK", "EVADE", "IMMUNE", "DEFLECT" }; + +// VERIFY: e98c251d manual +// OFFSET: 0x005133B0 +void CGGameUI::ShowCombatFeedbackAttackRoundInfo(const ATTACKROUNDINFO* info) { + if (!info || info->m_victimState >= 9) { + SErrDisplayAppFatalMessage("", "", 0); + } + + CGGameUI::SignalUnitCombat(info->m_target, s_victimStateTokens[info->m_victimState], info->m_damage, info->m_schoolMask[0], info->m_hitInfo); +} + +// VERIFY: de4027e3 auto +// OFFSET: 0x00524350 +void CGGameUI::BreakTarget(WOWGUID guid) { + if (guid == CGGameUI::m_lockedTarget) { + Spell_C_CancelAutoRepeat(true); + } + + CGGameUI::ClearTarget(guid, 1); + + if (guid == CGGameUI::m_lastTarget) { + CGGameUI::m_lastTarget = WOWGUID(); + } + + if (guid == CGGameUI::m_lastEnemyTarget) { + CGGameUI::m_lastEnemyTarget = WOWGUID(); + } + + if (guid == CGGameUI::m_lastFriendTarget) { + CGGameUI::m_lastFriendTarget = WOWGUID(); + } + + if (guid == CGGameUI::m_currentObjectTrack && CGWorldFrame::s_currentWorldFrame) { + CGWorldFrame::s_currentWorldFrame->HandleSpriteTrack(WOWGUID()); + } + + if (guid == CGGameUI::unk_BD07D0) { + CGGameUI::SetFocusTarget(WOWGUID()); + } + + if (guid == CGGameUI::m_directionalTarget) { + CGGameUI::m_directionalTarget = WOWGUID(); + } +} + +// STATIC: 0x00BD0BD4 +TSHashTable CGGameUI::s_threatMap; + +// VERIFY: e2bc6d49 manual +// OFFSET: 0x00519D50 +uint8_t CGGameUI::THREATMAP::ComputeMaxThreatLevel(const WOWGUID& guid) { + uint8_t level = 0; + + for (uint32_t i = this->m_units.Count(); i;) { + i--; + + if (!this->m_units[i]) { + continue; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(this->m_units[i], TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + this->m_units[i] = WOWGUID(); + continue; + } + + uint8_t status; + unit->CalculateThreat(guid, &status, nullptr, nullptr, nullptr); + + if (level <= 2) { + if (status > level) { + level = status; + } + } else if (level == 4 && status == 3) { + level = 3; + } + } + + return level; +} + +// VERIFY: a758952f manual +// OFFSET: 0x00519CF0 +void CGGameUI::THREATMAP::RemoveUnit(const WOWGUID& guid) { + for (uint32_t i = this->m_units.Count(); i;) { + i--; + + if (this->m_units[i] == guid) { + this->m_units[i] = WOWGUID(); + return; + } + } +} + +// VERIFY: ef8e6045 manual +// OFFSET: 0x005256A0 +void CGGameUI::THREATMAP::AddUnit(const WOWGUID& guid) { + WOWGUID* empty = nullptr; + + for (uint32_t i = this->m_units.Count(); i;) { + i--; + + if (this->m_units[i] == guid) { + return; + } + + if (!this->m_units[i]) { + empty = &this->m_units[i]; + } + } + + if (!empty) { + empty = this->m_units.New(); + } + + *empty = guid; +} + +// VERIFY: 2285dd15 auto +// OFFSET: 0x0052A1A0 +uint8_t CGUnit_C::GetThreatSituation(const WOWGUID& guid) { + CGGameUI::THREATMAP* map = CGGameUI::s_threatMap.Ptr(static_cast(guid.m_guid), CHashKeyGUID(guid.m_guid)); + + if (map) { + return map->ComputeMaxThreatLevel(guid); + } + + return 0; +} + +// VERIFY: 88074792 auto +// OFFSET: 0x0052A160 +void CGGameUI::ThreatMapRemove(const WOWGUID& unit, const WOWGUID& target) { + CGGameUI::THREATMAP* map = CGGameUI::s_threatMap.Ptr(static_cast(target.m_guid), CHashKeyGUID(target.m_guid)); + + if (map) { + map->RemoveUnit(unit); + } +} + +// VERIFY: c9bac8e5 manual +// OFFSET: 0x0052B370 +void CGGameUI::ThreatMapAdd(const WOWGUID& unit, const WOWGUID& target) { + uint32_t hashval = static_cast(target.m_guid); + CHashKeyGUID key(target.m_guid); + CGGameUI::THREATMAP* map = CGGameUI::s_threatMap.Ptr(hashval, key); + + if (!map) { + map = CGGameUI::s_threatMap.New(hashval, key, 0, 0); + } + + map->AddUnit(unit); + + if (CGGameUI::m_threatWarningEnabled && target == ClntObjMgrGetActivePlayer()) { + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player->m_unit->m_unitFieldLevel >= 14) { + CGTutorial::TriggerTutorial(53); + } + } +} + +// VERIFY: 2a158b69 auto +// OFFSET: 0x00512AB0 +void CGGameUI::UnitTooltipUpdate(const WOWGUID& guid) { + if (CGGameUI::m_gameTooltip && CGGameUI::m_gameTooltip->m_unitGuid == guid && !CGGameUI::m_gameTooltip->m_fading) { + WOWGUID none = WOWGUID(); + CGGameUI::m_gameTooltip->SetUnit(guid, 1, none, 0); + } +} + +// VERIFY: 60160ac7 manual +// OFFSET: 0x005196F0 +void CGGameUI::DoPowerRegen() { + uint32_t now = OsGetAsyncTimeMs(); + + if (!CGGameUI::m_lastRegenTime) { + CGGameUI::m_lastRegenTime = now; + return; + } + + uint32_t elapsed = now - CGGameUI::m_lastRegenTime; + + if (elapsed < 100) { + return; + } + + CGGameUI::m_lastRegenTime = now; + + if (!g_predictedPowerCVar->m_intValue) { + return; + } + + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (player) { + player->DoPowerRegen(elapsed); + } + + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (pet) { + pet->DoPowerRegen(elapsed); + } +} + +// VERIFY: 8e843e3a auto +// OFFSET: 0x00512A30 +int32_t CGGameUI::IsRaidMemberOrPet(const WOWGUID& guid) { + if (CGPartyInfo::IsMemberOrPet(guid)) { + return 1; + } + + if (CGRaidInfo::IsPlayerOrPetInRaid(guid)) { + return 1; + } + + return 0; +} + +// VERIFY: 7f1e37fb auto +// OFFSET: 0x005124E0 +void CGGameUI::ClearLootSlot(uint8_t slot) { + CGLootInfo::ClearSlot(slot); +} + +// VERIFY: 5e51540d auto +// OFFSET: 0x005124F0 +void CGGameUI::LootSlotChanged(uint8_t slot) { + CGLootInfo::OnLootSlotChanged(slot); +} + +// VERIFY: 60912e63 manual +// OFFSET: 0x005264F0 +void CGGameUI::OpenLoot(CGObject_C* object, int32_t coins, uint32_t lootType) { + if (object->m_obj->m_type & TYPEMASK_UNIT) { + CGGameUI::Target(object->m_obj->m_guid); + } + + CGLootInfo::SetObject(object, coins, lootType); +} + +// VERIFY: 4b188323 manual +// OFFSET: 0x00523640 +void CGGameUI::CloseLoot(bool a1, bool a2, bool a3) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + WOWGUID guid = CGLootInfo::m_lootObj; + + if (!guid) { + return; + } + + if ((CGLootDisplay::GetLootAcquireType() == 4 || CGLootDisplay::GetLootAcquireType() == 7 || CGLootDisplay::GetLootAcquireType() == 8) && CGLootInfo::HasLoot() && !a2) { + CGLootInfo::DoAutoLoot(1); + } + + if (a3) { + CGGameUI::DisplayError(ERR_LOOT_NO_UI); + } + + CGObject_C* object = ClntObjMgrObjectPtr(guid, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (object && (object->m_obj->m_type & TYPEMASK_ITEM)) { + if (a2) { + return; + } + + CGGameUI::UnlockItem(guid); + } + + if (player) { + player->ClearLootingObject(); + } + + if (a1) { + CDataStore msg; + msg.Put(static_cast(CMSG_LOOT_RELEASE)); + msg.Put(guid.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + CGLootInfo::SetObject(nullptr, 0, 0); + + if (object && (object->m_obj->m_type & TYPEMASK_UNIT) && static_cast(static_cast(object)->m_unit->m_unitFieldHealth) <= 0) { + CGGameUI::ClearTarget(guid, 1); + } + + if (CGGameUI::m_cursorItemType == 6) { + CGGameUI::ClearCursor(1, 1); + } +} + +// VERIFY: 5fa8caad auto +// OFFSET: 0x00524600 +void CGGameUI::SetRegenEnabled(int32_t enabled) { + if (enabled) { + CGGameUI::m_simpleTop->m_allowProtectedActions = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_PLAYER_REGEN_ENABLED, nullptr); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_PLAYER_REGEN_DISABLED, nullptr); + CGGameUI::m_simpleTop->m_allowProtectedActions = 0; + } + + CGGameUI::UpdateCombatMode(); +} + +// VERIFY: 4e314fe3 manual +// OFFSET: 0x00513740 +void CGGameUI::LockItem(WOWGUID guid) { + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (item) { + item->Lock(); + } + + CGActionBar::UpdateUsable(); +} + +// VERIFY: f953bccb manual +// OFFSET: 0x00520E40 +void CGGameUI::UnlockAllItems() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || !player->GetBag()) { + return; + } + + CGBag_C* bag = player->GetBag(); + uint32_t numSlots = bag->m_numSlots; + + for (uint32_t i = 0; i < numSlots; i++) { + WOWGUID guid = i < static_cast(bag->m_numSlots) ? bag->m_slots[i] : WOWGUID(); + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (!item) { + continue; + } + + item->Unlock(); + + if (!(item->m_obj->m_type & TYPEMASK_CONTAINER) || !item->GetBag()) { + continue; + } + + for (uint32_t j = 0; j < static_cast(item->GetBag()->m_numSlots); j++) { + CGBag_C* container = item->GetBag(); + WOWGUID contained = i < static_cast(container->m_numSlots) ? container->m_slots[i] : WOWGUID(); + CGItem_C* containedItem = static_cast(ClntObjMgrObjectPtr(contained, TYPEMASK_ITEM, __FILE__, __LINE__)); + + if (containedItem) { + containedItem->Unlock(); + } + } + } +} + +// VERIFY: 1fe92b1e auto +// OFFSET: 0x005A4780 +void CGGameUI::SetPendingItemSound(WOWGUID guid, int32_t itemId) { + CGGameUI::unk_BD08B0 = guid; + CGGameUI::unk_BD08A4 = itemId; +} diff --git a/WoW/Source/Ui/GameUI.h b/WoW/Source/Ui/GameUI.h index 9b67ddd..c3d1d27 100644 --- a/WoW/Source/Ui/GameUI.h +++ b/WoW/Source/Ui/GameUI.h @@ -13,7 +13,9 @@ #include "WoW/Source/Ui/TotemInfo.h" #include "WoW/Source/Ui/Types.h" #include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/Object/ObjectClient/Object_C.h" +class CGUnit_C; class AreaTableRec; class CImVector; class CDataStore; @@ -63,7 +65,14 @@ extern CVar* s_cvQuestLogCollapseFilter; extern CVar* s_cvAutoRangedCombat; extern CVar* s_cvAutoFilledMultiCastSlots; extern CVar* g_threatWarningCVar; +extern CVar* g_threatWorldTextCVar; +extern CVar* g_currencyTokensUnused1CVar; +extern CVar* g_currencyTokensUnused2CVar; +extern CVar* g_currencyTokensBackpack1CVar; +extern CVar* g_currencyTokensBackpack2CVar; +extern CVar* s_cvThreatPlaySounds; extern CVar* g_autoSelfCastCVar; +extern CVar* g_secureAbilityToggleCVar; extern CVar* g_predictedHealthCVar; extern const char* g_macroTaint; @@ -80,6 +89,21 @@ struct SAVEDVARIABLE : public TSHashObject { class CGGameUI { public: + struct THREATMAP : public TSHashObject { + /* 0020 */ TSGrowableArray m_units; + + uint8_t ComputeMaxThreatLevel(const WOWGUID& guid); + void RemoveUnit(const WOWGUID& guid); + void AddUnit(const WOWGUID& guid); + }; + + static TSHashTable s_threatMap; + static void ThreatMapRemove(const WOWGUID& unit, const WOWGUID& target); + static void ThreatMapAdd(const WOWGUID& unit, const WOWGUID& target); + static void UnitTooltipUpdate(const WOWGUID& guid); + static void UnlockAllItems(); + static void SetRegenEnabled(int32_t enabled); + static TSHashTable s_savedVariables[2]; static int32_t HandleMouseDown(const CMouseEvent& evt); static void OnClientControlChanged(int32_t control); @@ -119,6 +143,9 @@ class CGGameUI { static int32_t unk_BD08CC; static void InitClientControlState(const WOWGUID& guid); static void StartCinematic(int32_t cinematic); + static void SetInstanceLockTime(uint32_t time, uint32_t a2, uint32_t a3); + static void SetInstanceBootTime(uint32_t time); + static void DisplayNameError(uint32_t error); static void UpdateActivePlayer(); static void ClearClientControls(); static void OpenPlayerSkinned(bool a1); @@ -170,6 +197,9 @@ class CGGameUI { static int32_t IsAutoLooting(); static void ShowCombatFeedback(const WOWGUID& guid, int32_t amount, uint32_t schoolMask, uint32_t flags); static void ShowSpellMissFeedback(const WOWGUID& guid, int32_t reason); + static void ShowHealingFeedback(const WOWGUID& guid, int32_t amount, bool crit); + static void ShowEnergizeFeedback(const WOWGUID& guid, int32_t powerType, int32_t amount); + static void SignalUnitCombat(const WOWGUID& guid, const char* action, int32_t amount, uint32_t schoolMask, uint32_t flags); static void ShowCombatFeedbackAttackRoundInfo(const ATTACKROUNDINFO* info); static void HandleFocusChanged(const CFocusEvent& evt); static int32_t Idle(const void* data, void* param); @@ -194,6 +224,7 @@ class CGGameUI { static void Shutdown(); static void ShutdownGame(); static WOWGUID m_currentObjectTrack; + static WOWGUID m_pendingItem; static WOWGUID m_interactTarget; static float m_interactMaxDistSq; static WOWGUID m_areaSpiritHealerGUID; @@ -223,6 +254,12 @@ class CGGameUI { static int32_t CameraMusicIsPlaying(); static int32_t CanPerformAction(uint32_t action); + static void CastItemSpell(WOWGUID guid, int32_t confirmed); + static const char* LastErrorMessage(); + static void SetLastEnchantSpellID(int32_t spellId); + static void SetLastItemSpellTarget(WOWGUID guid); + static int32_t m_lastEnchantSpellID; + static WOWGUID m_lastItemSpellTarget; static void OnMouseModeNormal(); static void OnMouseModeRelative(); static uint32_t GetCurrentDungeonDifficulty(); @@ -240,10 +277,16 @@ class CGGameUI { static void InvalidatePlayer(const WOWGUID& guid); static int32_t SequenceMusicIsPlaying(); static TotemInfo* GetTotemInfo(WOWGUID guid); + static TotemInfo* GetTotemInfo(uint32_t slot); static int32_t IsKeyDown(KEY key); static int32_t IsRaidMemberOrPet(const WOWGUID& guid); static void ClearInteractTarget(const WOWGUID& guid, int32_t a2); static void CloseLoot(bool a1, bool a2, bool a3); + static void OpenLoot(CGObject_C* object, int32_t coins, uint32_t lootType); + static void ClearLootSlot(uint8_t slot); + static void LootSlotChanged(uint8_t slot); + static void LockItem(WOWGUID guid); + static void SetPendingItemSound(WOWGUID guid, int32_t itemId); static void EnterWorld(); static void RegisterSavedVariable(const char* name, int32_t perCharacter); static void BreakTarget(WOWGUID guid); @@ -262,6 +305,7 @@ class CGGameUI { static int32_t GetCursorVirtualItemOfType(int32_t type); static void DropCursorSpell(); static void SetCursorSpell(int32_t spellId); + static void SetCursorPetAction(const uint32_t* action); static void SetCursorMacro(int32_t macroId); static void SetCursorVirtualItem(int32_t id, int32_t displayId, int32_t slot, int32_t type, int32_t stackSplit); static void SetCursorEquipmentSet(int32_t setId); @@ -388,13 +432,8 @@ int32_t Script_DeleteCursorItem(lua_State* L); int32_t Script_EquipPendingItem(lua_State* L); int32_t Script_CancelPendingEquip(lua_State* L); int32_t Script_TargetUnit(lua_State* L); -int32_t Script_TargetNearest(lua_State* L); -int32_t Script_TargetNearestEnemy(lua_State* L); -int32_t Script_TargetNearestEnemyPlayer(lua_State* L); -int32_t Script_TargetNearestFriend(lua_State* L); -int32_t Script_TargetNearestFriendPlayer(lua_State* L); -int32_t Script_TargetNearestPartyMember(lua_State* L); -int32_t Script_TargetNearestRaidMember(lua_State* L); +void TargetNearestEnemy(int32_t reverse, int32_t type); +int32_t UnitMatchesTargetType(CGUnit_C* unit, CGUnit_C* target, int32_t type); int32_t Script_TargetDirectionEnemy(lua_State* L); int32_t Script_TargetDirectionFriend(lua_State* L); int32_t Script_TargetLastTarget(lua_State* L); @@ -462,8 +501,6 @@ int32_t Script_GetExtendedItemInfo(lua_State* L); int32_t Script_GetItemIcon(lua_State* L); int32_t Script_GetItemFamily(lua_State* L); int32_t Script_GetItemCount(lua_State* L); -int32_t Script_GetItemSpell(lua_State* L); -int32_t Script_GetItemCooldown(lua_State* L); int32_t Script_PickupItem(lua_State* L); int32_t Script_IsCurrentItem(lua_State* L); int32_t Script_IsUsableItem(lua_State* L); @@ -509,7 +546,6 @@ int32_t Script_CanGrantLevel(lua_State* L); int32_t Script_GrantLevel(lua_State* L); int32_t Script_CanSummonFriend(lua_State* L); int32_t Script_SummonFriend(lua_State* L); -int32_t Script_GetTotemTimeLeft(lua_State* L); int32_t Script_GetNumDeclensionSets(lua_State* L); int32_t Script_DeclineName(lua_State* L); int32_t Script_AcceptLevelGrant(lua_State* L); @@ -517,7 +553,6 @@ int32_t Script_UploadSettings(lua_State* L); int32_t Script_DownloadSettings(lua_State* L); int32_t Script_GetMovieResolution(lua_State* L); int32_t Script_GameMovieFinished(lua_State* L); -int32_t Script_GetThreatStatusColor(lua_State* L); int32_t Script_GetItemUniqueness(lua_State* L); int32_t Script_EndRefund(lua_State* L); int32_t Script_EndBoundTradeable(lua_State* L); @@ -525,6 +560,12 @@ int32_t Script_GetAccountExpansionLevel(lua_State* L); extern CVar* g_profanityFilterCVar; extern CVar* g_spamFilterCVar; +extern CVar* g_serviceTypeFilterCVar; +extern CVar* g_minimapZoomCVar; +extern CVar* g_minimapInsideZoomCVar; +extern CVar* g_enablePVPNotifyAFKCVar; +extern CVar* g_chatBubblesCVar; +extern CVar* g_chatBubblesPartyCVar; void UpdateInstanceOwnershipPacket(int32_t owns); diff --git a/WoW/Source/Ui/GameUI_Scripts.cpp b/WoW/Source/Ui/GameUI_Scripts.cpp index 7c817e6..67b96a2 100644 --- a/WoW/Source/Ui/GameUI_Scripts.cpp +++ b/WoW/Source/Ui/GameUI_Scripts.cpp @@ -148,6 +148,7 @@ #include "_Triage/GxRestart.h" #include "WoW/Source/Object/ObjectClient/Object_C.h" #include "WoW/Source/Object/Player.h" +#include "WoW/Source/DB/Rec/SpellRec.h" // STATIC: 0x00BD0CC4 static CWOWClientStatus* s_loadAddOnStatus; @@ -2522,7 +2523,167 @@ static int32_t Script_GetCurrentTitle(lua_State* L) { return 1; } +// VERIFY: c9010307 manual +// OFFSET: 0x00510FC0 +static int32_t Script_GetItemCooldown(lua_State* L) { + int32_t itemId = 0; + + if (lua_isnumber(L, 1)) { + itemId = lua_tointeger(L, 1); + } else if (lua_isstring(L, 1)) { + itemId = GetItemIDByName(lua_tolstring(L, 1, nullptr)); + } + + uint32_t start = 0; + uint32_t duration = 0; + uint32_t enable = 0; + + if (itemId) { + CGItem_C* item = CGActionBar::FindUseEnchantItemPtr(itemId); + + if (item) { + Spell_C_GetItemCooldown(item, &duration, &start, &enable); + } else { + Spell_C_GetItemCooldown(itemId, &duration, &start, &enable); + } + } + + lua_pushnumber(L, start * 0.001); + lua_pushnumber(L, duration * 0.001); + lua_pushnumber(L, enable); + return 3; +} + +// VERIFY: 75f296f7 auto +// OFFSET: 0x00517100 +static int32_t Script_GetItemSpell(lua_State* L) { + SpellRec spell; + int32_t itemId = 0; + + if (lua_isnumber(L, 1)) { + itemId = lua_tointeger(L, 1); + } else if (lua_isstring(L, 1)) { + itemId = GetItemIDByName(lua_tolstring(L, 1, nullptr)); + } + + CGItem_C* item = CGActionBar::FindUseEnchantItemPtr(itemId); + int32_t spellId = item ? item->GetEnchantmentSpell(0) : CGItem_C::GetUseSpell(itemId); + + if (g_spellDB.GetRecord(spellId, &spell)) { + lua_pushstring(L, spell.m_name); + lua_pushstring(L, spell.m_nameSubtext); + } else { + lua_pushnil(L); + lua_pushnil(L); + } + + return 2; +} + +// VERIFY: 42d23833 manual +// OFFSET: 0x00517C60 +static int32_t Script_GetTotemTimeLeft(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetTotemTimeLeft(slot)"); + } + + uint32_t slot = static_cast(lua_tonumber(L, 1)) - 1; + + if (slot > 3) { + luaL_error(L, "Totem slot must be in range of 1 to %d", 4); + } + + TotemInfo* totem = &CGGameUI::m_totems[slot]; + + if (totem && totem->m_guid.m_guid) { + lua_pushnumber(L, totem->GetSpawnTimeLeft() / 1000); + } else { + lua_pushnumber(L, 0.0); + } + + return 1; +} + +// VERIFY: 8266a857 manual +// OFFSET: 0x00525A90 +static int32_t Script_TargetNearest(lua_State* L) { + if (CGUIMacros::IsActionAllowed(5)) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 0); + CGUIMacros::m_state &= ~0x20u; + } + + return 0; +} + +// VERIFY: 54ce30e6 manual +// OFFSET: 0x00525AD0 +static int32_t Script_TargetNearestEnemy(lua_State* L) { + if (CGUIMacros::IsActionAllowed(5)) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 1); + CGUIMacros::m_state &= ~0x20u; + } + + return 0; +} + +// VERIFY: 32d545fd manual +// OFFSET: 0x00525B10 +static int32_t Script_TargetNearestEnemyPlayer(lua_State* L) { + if (CGUIMacros::IsActionAllowed(5)) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 2); + CGUIMacros::m_state &= ~0x20u; + } + + return 0; +} + +// VERIFY: bcf021cd manual +// OFFSET: 0x00525B50 +static int32_t Script_TargetNearestFriend(lua_State* L) { + if (CGUIMacros::IsActionAllowed(5)) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 3); + CGUIMacros::m_state &= ~0x20u; + } + + return 0; +} + +// VERIFY: 04298fa1 manual +// OFFSET: 0x00525B90 +static int32_t Script_TargetNearestFriendPlayer(lua_State* L) { + if (CGUIMacros::IsActionAllowed(5)) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 4); + CGUIMacros::m_state &= ~0x20u; + } + + return 0; +} + +// VERIFY: b149bc61 auto +// OFFSET: 0x00525BD0 +static int32_t Script_TargetNearestPartyMember(lua_State* L) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 5); + return 0; +} + +// VERIFY: 3be6e022 auto +// OFFSET: 0x00525C00 +static int32_t Script_TargetNearestRaidMember(lua_State* L) { + TargetNearestEnemy(StringToBOOL(L, 1, 0), 6); + return 0; +} + // STATIC: 0x00AC80B0 +// VERIFY: ea127e1f manual +// OFFSET: 0x00511FE0 +static int32_t Script_GetThreatStatusColor(lua_State* L) { + uint32_t color = *CGTooltip::GetThreatStateColor(static_cast(static_cast(lua_tonumber(L, 1) + 1.0))); + lua_pushnumber(L, ((color >> 16) & 0xFF) * 0.0039215689); + lua_pushnumber(L, ((color >> 8) & 0xFF) * 0.0039215689); + lua_pushnumber(L, (color & 0xFF) * 0.0039215689); + return 3; +} + static FrameScript_Method s_ScriptFunctions[] = { { "FrameXML_Debug", &Script_FrameXML_Debug }, { "GetBuildInfo", &Script_GetBuildInfo }, diff --git a/WoW/Source/Ui/GlyphInfo.h b/WoW/Source/Ui/GlyphInfo.h index cd71a18..2229c8a 100644 --- a/WoW/Source/Ui/GlyphInfo.h +++ b/WoW/Source/Ui/GlyphInfo.h @@ -5,10 +5,7 @@ struct lua_State; -int32_t Script_GetGlyphSocketInfo(lua_State* L); -int32_t Script_GlyphMatchesSocket(lua_State* L); -int32_t Script_PlaceGlyphInSocket(lua_State* L); -int32_t Script_GetGlyphLink(lua_State* L); void GlyphInfoRegisterScriptFunctions(); +void GlyphInfoUnregisterScriptFunctions(); #endif diff --git a/WoW/Source/Ui/GlyphInfo_Scripts.cpp b/WoW/Source/Ui/GlyphInfo_Scripts.cpp index 2f05ff1..0f5cddd 100644 --- a/WoW/Source/Ui/GlyphInfo_Scripts.cpp +++ b/WoW/Source/Ui/GlyphInfo_Scripts.cpp @@ -7,6 +7,17 @@ #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "Engine/Source/FrameXML/LoadXML.h" +#include "Engine/Source/lua-5.1/src/lauxlib.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/GlyphPropertiesRec.h" +#include "WoW/Source/DB/Rec/GlyphSlotRec.h" +#include "WoW/Source/DB/Rec/SpellIconRec.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/Ui/TalentInfo.h" +#include "WoW/Source/UIUtil/Tooltip.h" // VERIFY: 6144c30d auto // OFFSET: 0x005B71E0 @@ -15,6 +26,122 @@ static int32_t Script_GetNumGlyphSockets(lua_State* L) { return 1; } +// VERIFY: 9cc859f5 manual +// OFFSET: 0x005B7260 +static int32_t Script_GetGlyphSocketInfo(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetGlyphSocketInfo(index[, talentGroup])"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGTalentGroup_C* group = TalentInfoGetTalentGroup(TalentInfoGetScriptGroupIndex(L, 2), 0, 0); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (index >= 6 || !group || !player) { + return 0; + } + + if (player->m_player->m_playerGlyphsEnabled & (1 << index)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + GlyphSlotRec* slot = g_glyphSlotDB.GetRecord(player->m_player->m_playerFieldGlyphSlots1[index]); + + if (slot) { + lua_pushnumber(L, slot->m_type + 1); + } else { + lua_pushnil(L); + } + + GlyphPropertiesRec* glyph = g_glyphPropertiesDB.GetRecord(group->GetGlyph(index)); + + if (glyph) { + lua_pushnumber(L, glyph->m_spellID); + SpellIconRec* icon = g_spellIconDB.GetRecord(glyph->m_spellIconID); + + if (icon) { + lua_pushstring(L, icon->m_textureFilename); + } else { + lua_pushnil(L); + } + } else { + lua_pushnil(L); + lua_pushnil(L); + } + + return 4; +} + +// VERIFY: bf189600 manual +// OFFSET: 0x005B7410 +static int32_t Script_GlyphMatchesSocket(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GlyphMatchesSocket(socketIndex)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + lua_pushnil(L); + return 1; + } + + SpellRec spell; + PendingSpellCast* cast = Spell_C_GetTargetingSpellCast(); + + if (!cast || !g_spellDB.GetRecord(cast->m_data.m_spellId, &spell)) { + return 0; + } + + for (uint32_t i = 0; i < 3; i++) { + if (spell.m_effect[i] != 74) { + continue; + } + + GlyphPropertiesRec* glyph = g_glyphPropertiesDB.GetRecord(spell.m_effectMiscValue[i]); + GlyphSlotRec* slot = g_glyphSlotDB.GetRecord(player->m_player->m_playerFieldGlyphSlots1[index]); + + if (!glyph || !slot) { + continue; + } + + if (slot->m_type != glyph->m_glyphSlotFlags) { + return 0; + } + + lua_pushnumber(L, 1.0); + return 1; + } + + return 0; +} + +// VERIFY: fcc848cc manual +// OFFSET: 0x005B75A0 +static int32_t Script_PlaceGlyphInSocket(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: PlaceGlyphInSocket(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (index >= 6 || !player) { + return 0; + } + + if (Spell_C_HandleGlyphClick(index)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + // VERIFY: 2a5b7041 manual // OFFSET: 0x005B7660 static int32_t Script_RemoveGlyphFromSocket(lua_State* L) { @@ -36,6 +163,25 @@ static int32_t Script_RemoveGlyphFromSocket(lua_State* L) { return 0; } +// VERIFY: 9c680b33 manual +// OFFSET: 0x005B7740 +static int32_t Script_GetGlyphLink(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetGlyphLink(index[, talentGroup])"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGTalentGroup_C* group = TalentInfoGetTalentGroup(TalentInfoGetScriptGroupIndex(L, 2), 0, 0); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (index >= 6 || !player || !group) { + return 0; + } + + lua_pushstring(L, CGTooltip::GetGlyphLink(player->m_player->m_playerFieldGlyphSlots1[index], group->GetGlyph(index))); + return 1; +} + // STATIC: 0x00ACFF54 static FrameScript_Method s_ScriptFunctions[] = { { "GetNumGlyphSockets", &Script_GetNumGlyphSockets }, @@ -53,3 +199,11 @@ void GlyphInfoRegisterScriptFunctions() { FrameScript_RegisterFunction(s_ScriptFunctions[i].m_name, s_ScriptFunctions[i].m_method); } } + +// VERIFY: 8012ebde auto +// OFFSET: 0x005B7240 +void GlyphInfoUnregisterScriptFunctions() { + for (uint32_t i = 0; i < sizeof(s_ScriptFunctions) / sizeof(s_ScriptFunctions[0]); i++) { + FrameScript_UnregisterFunction(s_ScriptFunctions[i].m_name); + } +} diff --git a/WoW/Source/Ui/GuildBankFrame.cpp b/WoW/Source/Ui/GuildBankFrame.cpp index 2b5822a..e934c5d 100644 --- a/WoW/Source/Ui/GuildBankFrame.cpp +++ b/WoW/Source/Ui/GuildBankFrame.cpp @@ -4,6 +4,7 @@ #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/GameUI.h" #include "WoW/Source/Ui/Types.h" +#include "Engine/Source/Base/CDataStore.h" // STATIC: 0x00C1DC10 WOWGUID CGGuildBankInfo::m_banker; @@ -29,6 +30,18 @@ int32_t CGGuildBankInfo::m_remainingWithdrawMoney; // STATIC: 0x00C1DC20 uint64_t CGGuildBankInfo::m_money; +// STATIC: 0x00C1DBF0 +int32_t CGGuildBankInfo::m_numLogEntries[6]; + +// STATIC: 0x00ACF8C8 +uint8_t CGGuildBankInfo::unk_ACF8C8 = 0xFF; + +// STATIC: 0x00C0F8E8 +int32_t CGGuildBankInfo::unk_C0F8E8[6]; + +// STATIC: 0x00C1DC38 +TSGrowableArray CGGuildBankInfo::m_tabSlots[6]; + // VERIFY: a63db2b3 auto // OFFSET: 0x005A77D0 void CGGuildBankInfo::InitializeGame() { @@ -55,3 +68,31 @@ void CGGuildBankInfo::SetGuildBanker(const WOWGUID& banker) { CGGuildBankInfo::m_banker = WOWGUID(); CGGuildBankInfo::m_pendingBanker = WOWGUID(); } + +// VERIFY: 9ecc3e00 manual +// OFFSET: 0x005A56F0 +void CGGuildBankInfo::EnterWorld() { + for (int32_t i = 0; i < 6; i++) { + CGGuildBankInfo::m_numLogEntries[i] = 0; + } + + CGGuildBankInfo::m_numMoneyTransactions = 0; + CGGuildBankInfo::m_numTabs = 0; + CGGuildBankInfo::m_banker = WOWGUID{ 0 }; + CGGuildBankInfo::m_pendingBanker = WOWGUID{ 0 }; + CGGuildBankInfo::unk_ACF8C8 = 0xFF; + + for (int32_t tab = 0; tab < 6; tab++) { + for (uint32_t i = 0; i < CGGuildBankInfo::m_tabSlots[tab].m_count; i++) { + CGGuildBankInfo::m_tabSlots[tab].m_data[i].m_itemID = 0; + } + + CGGuildBankInfo::m_guildBankTabInfo[tab].unk_2140 = 1; + CGGuildBankInfo::unk_C0F8E8[tab] = 1; + } + + CDataStore msg; + msg.Put(static_cast(MSG_GUILD_BANK_MONEY_WITHDRAWN)); + msg.Finalize(); + ClientServices::Send2(&msg); +} diff --git a/WoW/Source/Ui/GuildBankFrame.h b/WoW/Source/Ui/GuildBankFrame.h index adae8cc..23a135e 100644 --- a/WoW/Source/Ui/GuildBankFrame.h +++ b/WoW/Source/Ui/GuildBankFrame.h @@ -2,6 +2,7 @@ #define WOW_SOURCE_UI_GUILDBANKFRAME_H #include +#include "Engine/Source/Storm/H/stpl.h" #include "WoW/Source/Net/Types.h" #include "WoW/Source/Object/WGUID.h" @@ -15,6 +16,11 @@ struct GuildBankTabInfo { /* 2140 */ int32_t unk_2140; }; +struct GuildBankSlotInfo { + /* 0000 */ int32_t m_itemID; + /* 0004 */ uint8_t unk_0004[40]; +}; + int32_t Packet_SMSG_GUILD_BANK_LIST(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t Packet_MSG_GUILD_BANK_LOG_QUERY(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t Packet_MSG_GUILD_BANK_MONEY_WITHDRAWN(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); @@ -24,13 +30,19 @@ class CGGuildBankInfo { public: static WOWGUID m_banker; static WOWGUID m_pendingBanker; - static void SetGuildBanker(const WOWGUID& banker); + static void AutoStoreItem(WOWGUID item, WOWGUID container, uint32_t slot); static int32_t m_numMoneyTransactions; static uint8_t m_numTabs; static GuildBankTabInfo m_guildBankTabInfo[6]; static uint8_t m_currentTab; static int32_t m_remainingWithdrawMoney; static uint64_t m_money; + static int32_t m_numLogEntries[6]; + static uint8_t unk_ACF8C8; + static int32_t unk_C0F8E8[6]; + static TSGrowableArray m_tabSlots[6]; + + static void SetGuildBanker(const WOWGUID& banker); static void EnterWorld(); static void InitializeGame(); static void ClearAllTabs(); diff --git a/WoW/Source/Ui/GuildInfo.cpp b/WoW/Source/Ui/GuildInfo.cpp index f4e1103..911b936 100644 --- a/WoW/Source/Ui/GuildInfo.cpp +++ b/WoW/Source/Ui/GuildInfo.cpp @@ -5,6 +5,8 @@ #include #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/Types.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" // STATIC: 0x00C22ACC int32_t CGGuildInfo::m_numEventLogEntries; @@ -105,3 +107,24 @@ void CGGuildInfo::SetShowOffline(int32_t show) { FrameScript_SignalEvent(SCRIPT_EVENT_GUILD_ROSTER_UPDATE, nullptr); } } + +// VERIFY: 504618a5 manual +// OFFSET: 0x005CB900 +void CGGuildInfo::EnterWorld() { + CGGuildInfo::m_infoText[0] = '\0'; + CGGuildInfo::m_motd[0] = '\0'; + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player && player->m_player->m_playerGuildid) { + CDataStore msg; + msg.Put(static_cast(MSG_GUILD_PERMISSIONS)); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + for (int32_t i = 0; i < 6; i++) { + CGGuildInfo::m_rankInfo[0].m_bankTabRights[i] = -1; + CGGuildInfo::m_rankInfo[0].m_bankTabStacksPerDay[i] = -1; + } +} diff --git a/WoW/Source/Ui/InstanceEncounter_C.cpp b/WoW/Source/Ui/InstanceEncounter_C.cpp index 03b7d78..b820abf 100644 --- a/WoW/Source/Ui/InstanceEncounter_C.cpp +++ b/WoW/Source/Ui/InstanceEncounter_C.cpp @@ -1,4 +1,6 @@ #include "InstanceEncounter_C.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" // STATIC: 0x00C242FC int32_t CGInstanceEncounter_C::m_units; @@ -21,3 +23,11 @@ WOWGUID CGInstanceEncounter_C::GetBoss(uint32_t index) { uint32_t CGInstanceEncounter_C::GetNumBossSlots() { return CGInstanceEncounter_C::m_units; } + +// VERIFY: e1fb6f4f auto +// OFFSET: 0x005EDED0 +void CGInstanceEncounter_C::EnterWorld() { + if (!CGGameUI::m_currentlyReloadingUI) { + ClientServices::SetMessageHandler(SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, Packet_SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, nullptr); + } +} diff --git a/WoW/Source/Ui/InstanceEncounter_C.h b/WoW/Source/Ui/InstanceEncounter_C.h index bc09445..4bf3b91 100644 --- a/WoW/Source/Ui/InstanceEncounter_C.h +++ b/WoW/Source/Ui/InstanceEncounter_C.h @@ -2,8 +2,11 @@ #define WOW_SOURCE_UI_INSTANCEENCOUNTER_C_H #include +#include "WoW/Source/Net/Types.h" #include "WoW/Source/Object/WGUID.h" +class CDataStore; + struct InstanceEncounterUnit { /* 0000 */ WOWGUID m_guid; /* 0008 */ uint32_t unk_0008[2]; @@ -18,4 +21,6 @@ class CGInstanceEncounter_C { static InstanceEncounterUnit* m_unitList; }; +int32_t Packet_SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); + #endif diff --git a/WoW/Source/Ui/ItemSocketInfo.cpp b/WoW/Source/Ui/ItemSocketInfo.cpp index 6143fea..f30dbcd 100644 --- a/WoW/Source/Ui/ItemSocketInfo.cpp +++ b/WoW/Source/Ui/ItemSocketInfo.cpp @@ -2,10 +2,23 @@ #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/GemPropertiesRec.h" #include "WoW/Source/Object/ItemStats.h" +#include + +// STATIC: 0x00C20FA8 +uint8_t CGItemSocketInfo::unk_C20FA8[3]; + +// STATIC: 0x00C20FB0 +WOWGUID CGItemSocketInfo::m_gemItemContainer[3]; // STATIC: 0x00C20FC8 WOWGUID CGItemSocketInfo::m_gemItems[3]; +// STATIC: 0x00C20FE0 +WOWGUID CGItemSocketInfo::m_socketItem; + +// STATIC: 0x00C20FE8 +int32_t CGItemSocketInfo::unk_C20FE8; + // VERIFY: c7291b92 manual // OFFSET: 0x005C48D0 int32_t CGItemSocketInfo::GemMatchesSocket(const ItemStats_C* item, const ItemStats_C* gem, int32_t socket) { @@ -46,3 +59,17 @@ int32_t CGItemSocketInfo::GemMatchesSocket(const ItemStats_C* item, const ItemSt return match; } + +// VERIFY: ef895c80 auto +// OFFSET: 0x005C44F0 +void CGItemSocketInfo::EnterWorld() { + CGItemSocketInfo::m_socketItem = WOWGUID{ 0 }; + CGItemSocketInfo::unk_C20FE8 = 0; + CGItemSocketInfo::m_gemItems[0] = WOWGUID{ 0 }; + CGItemSocketInfo::m_gemItems[1] = WOWGUID{ 0 }; + CGItemSocketInfo::m_gemItems[2] = WOWGUID{ 0 }; + CGItemSocketInfo::m_gemItemContainer[0] = WOWGUID{ 0 }; + CGItemSocketInfo::m_gemItemContainer[1] = WOWGUID{ 0 }; + CGItemSocketInfo::m_gemItemContainer[2] = WOWGUID{ 0 }; + memset(CGItemSocketInfo::unk_C20FA8, 0, sizeof(CGItemSocketInfo::unk_C20FA8)); +} diff --git a/WoW/Source/Ui/ItemSocketInfo.h b/WoW/Source/Ui/ItemSocketInfo.h index f3bbce1..c0e998d 100644 --- a/WoW/Source/Ui/ItemSocketInfo.h +++ b/WoW/Source/Ui/ItemSocketInfo.h @@ -24,7 +24,11 @@ class ItemStats_C; class CGItemSocketInfo { public: + static uint8_t unk_C20FA8[3]; + static WOWGUID m_gemItemContainer[3]; static WOWGUID m_gemItems[3]; + static WOWGUID m_socketItem; + static int32_t unk_C20FE8; static void EnterWorld(); static int32_t GemMatchesSocket(const ItemStats_C* item, const ItemStats_C* gem, int32_t socket); diff --git a/WoW/Source/Ui/LFGInfo.cpp b/WoW/Source/Ui/LFGInfo.cpp index 586afe1..8cd8fc4 100644 --- a/WoW/Source/Ui/LFGInfo.cpp +++ b/WoW/Source/Ui/LFGInfo.cpp @@ -5,6 +5,9 @@ // STATIC: 0x00BEAA14 int32_t CGLookingForGroup::m_searchJoinedID; +// STATIC: 0x00BEAA18 +uint32_t CGLookingForGroup::m_lastProposalID; + // STATIC: 0x00BEAA24 uint32_t CGLookingForGroup::m_randomDungeonBestChoice; @@ -41,6 +44,15 @@ LFGRewardInfo CGLookingForGroup::m_reward; // STATIC: 0x00BEAA28 LFGQueueStatus CGLookingForGroup::m_queueStatus; +// STATIC: 0x00BEAA4C +int32_t CGLookingForGroup::m_roleCheckState; + +// STATIC: 0x00BEAA50 +TSGrowableArray CGLookingForGroup::m_roleCheckSlots; + +// STATIC: 0x00BEAA60 +TSGrowableArray CGLookingForGroup::m_roleCheckMembers; + // VERIFY: 0e4c2bfa manual // OFFSET: 0x00557260 bool CGLookingForGroup::HasRaidDungeon(LFGInfo* info) { diff --git a/WoW/Source/Ui/LFGInfo.h b/WoW/Source/Ui/LFGInfo.h index da2fae7..8dbce7b 100644 --- a/WoW/Source/Ui/LFGInfo.h +++ b/WoW/Source/Ui/LFGInfo.h @@ -83,6 +83,14 @@ struct LFGQueueStatus { /* 0020 */ int32_t m_queuedTime; }; +struct LFGRoleCheckMember { + /* 0000 */ WOWGUID m_guid; + /* 0008 */ int32_t m_confirmed; + /* 000C */ uint32_t m_roles; + /* 0010 */ int32_t m_level; + /* 0014 */ uint32_t unk_0014; +}; + class CGLookingForGroup { public: struct LFGEntryInfo { @@ -91,6 +99,7 @@ class CGLookingForGroup { }; static int32_t m_searchJoinedID; + static uint32_t m_lastProposalID; static uint32_t m_randomDungeonBestChoice; static TSFixedArray m_randomDungeons; static TSFixedArray m_lfdEntries; @@ -103,8 +112,15 @@ class CGLookingForGroup { static LFGPartyLockInfo m_partyLockInfo; static LFGRewardInfo m_reward; static LFGQueueStatus m_queueStatus; + static int32_t m_roleCheckState; + static TSGrowableArray m_roleCheckSlots; + static TSGrowableArray m_roleCheckMembers; static void EnterWorld(); static void InitializeGame(); + static int32_t GetLFGRoleUpdate(lua_State* L); + static int32_t GetLFGRoleUpdateSlot(lua_State* L); + static void RequestLFGStatus(); + static void RequestLFGPlayerInfo(); static void ClearPartyInfo(); static uint8_t GetClassRoles(uint32_t classID); static bool HasRaidDungeon(LFGInfo* info); @@ -124,8 +140,6 @@ int32_t Script_SearchLFGGetResults(lua_State* L); int32_t Script_SearchLFGGetEncounterResults(lua_State* L); int32_t Script_SearchLFGGetPartyResults(lua_State* L); int32_t Script_SearchLFGSort(lua_State* L); -int32_t Script_GetLFGRoleUpdate(lua_State* L); -int32_t Script_GetLFGRoleUpdateSlot(lua_State* L); int32_t Script_GetLFGRoleUpdateMember(lua_State* L); int32_t Script_CompleteLFGRoleCheck(lua_State* L); int32_t Script_GetLFGProposal(lua_State* L); diff --git a/WoW/Source/Ui/LFGInfo_Scripts.cpp b/WoW/Source/Ui/LFGInfo_Scripts.cpp index 8b53426..36d2782 100644 --- a/WoW/Source/Ui/LFGInfo_Scripts.cpp +++ b/WoW/Source/Ui/LFGInfo_Scripts.cpp @@ -545,6 +545,18 @@ static int32_t Script_IsListedInLFR(lua_State* L) { return 1; } +// VERIFY: 31a496e4 auto +// OFFSET: 0x00554680 +static int32_t Script_GetLFGRoleUpdate(lua_State* L) { + return CGLookingForGroup::GetLFGRoleUpdate(L); +} + +// VERIFY: bd40434c auto +// OFFSET: 0x00554740 +static int32_t Script_GetLFGRoleUpdateSlot(lua_State* L) { + return CGLookingForGroup::GetLFGRoleUpdateSlot(L); +} + // STATIC: 0x00ACD668 static FrameScript_Method s_ScriptFunctions[] = { { "SetLFGDungeon", &Script_SetLFGDungeon }, diff --git a/WoW/Source/Ui/LootFrame.cpp b/WoW/Source/Ui/LootFrame.cpp index 6420b91..5f8a04e 100644 --- a/WoW/Source/Ui/LootFrame.cpp +++ b/WoW/Source/Ui/LootFrame.cpp @@ -1,6 +1,25 @@ #include "LootFrame.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ItemStats.h" +#include "WoW/Source/Object/ObjectClient/Bag_C.h" +#include "WoW/Source/Object/ObjectClient/GameObject_C.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/UIUtil/Tooltip.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/Base/CDataStore.h" +#include + +// STATIC: 0x00BFA688 +uint32_t CGLootInfo::m_itemsPending; // STATIC: 0x00BFA68C uint32_t CGLootInfo::m_lootType; @@ -14,6 +33,15 @@ int32_t CGLootInfo::m_coins; // STATIC: 0x00BFA8D8 WOWGUID CGLootInfo::m_lootObj; +// STATIC: 0x00BFA8E0 +int32_t CGLootInfo::m_autolooted; + +// STATIC: 0x00BFA8F0 +static char s_lootSlotTexture[260]; + +// STATIC: 0x00ACEE24 +static int32_t s_bindConfirmSlot = -1; + // STATIC: 0x00D38130 static uint32_t s_currencyMultiplier[3]; @@ -84,3 +112,660 @@ void GetCurrencyText(int32_t amount, char* buffer, uint32_t size, const char* se SStrPack(buffer, text, size); } } + +// VERIFY: b3b4c460 auto +// OFFSET: 0x007E7CC0 +void GetCurrencyIcon(int32_t amount, char* buffer, uint32_t size) { + const char* path = ClientDBStringLookup(3); + SStrPrintf(buffer, size, "%s%s", path, *path ? "\\" : ""); + + if (amount < 10) { + SStrPack(buffer, "INV_Misc_Coin_05", size); + } else if (amount < 100) { + SStrPack(buffer, "INV_Misc_Coin_06", size); + } else if (amount < 1000) { + SStrPack(buffer, "INV_Misc_Coin_03", size); + } else if (amount < 10000) { + SStrPack(buffer, "INV_Misc_Coin_04", size); + } else { + SStrPack(buffer, amount >= 100000 ? "INV_Misc_Coin_02" : "INV_Misc_Coin_01", size); + } +} + +// VERIFY: 64cf72fb auto +// OFFSET: 0x00588180 +void CGLootInfo::LeaveWorld() { + CGGameUI::CloseLoot(true, false, false); +} + +// VERIFY: c5c33408 auto +// OFFSET: 0x00588190 +int32_t CGLootWindow::GetNumLootItems() { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + int32_t count = 0; + + for (uint32_t i = 0; i < 18; i++) { + if (CGLootInfo::m_slots[i].m_itemID > 0) { + count = i + 1; + } + } + + if (CGLootInfo::m_coins) { + count++; + } + + return count; +} + +// VERIFY: c8b3d26f manual +// OFFSET: 0x00588210 +int32_t CGLootInfo::GetLootItem(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return 0; + } + + slot--; + } + + if (slot >= 18) { + return 0; + } + + return CGLootInfo::m_slots[slot].m_itemID; +} + +// VERIFY: 7938a0f3 manual +// OFFSET: 0x00588250 +int32_t CGLootInfo::GetLootItemCount(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return 0; + } + + slot--; + } + + if (slot >= 18) { + return 0; + } + + return CGLootInfo::m_slots[slot].m_count; +} + +// VERIFY: 71dd0d3a manual +// OFFSET: 0x00588290 +int32_t CGLootInfo::GetLootItemRandomSuffix(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return 0; + } + + slot--; + } + + if (slot >= 18) { + return 0; + } + + return CGLootInfo::m_slots[slot].m_randomSuffix; +} + +// VERIFY: cddf7717 manual +// OFFSET: 0x005882D0 +int32_t CGLootInfo::GetLootItemRandomPropertyId(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return 0; + } + + slot--; + } + + if (slot >= 18) { + return 0; + } + + return CGLootInfo::m_slots[slot].m_randomPropertyId; +} + +// VERIFY: 3e451cc5 auto +// OFFSET: 0x00588310 +int32_t CGLootWindow::GetLootItemRarity(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return 0; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return 0; + } + + slot--; + } + + if (slot >= 18) { + return 0; + } + + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(CGLootInfo::m_slots[slot].m_itemID, none, nullptr, nullptr, false); + + if (stats) { + return stats->m_quality; + } + + return -1; +} + +// VERIFY: 7ef12198 manual +// OFFSET: 0x00588380 +const char* CGLootInfo::GetLootSlotTexture(uint32_t slot) { + if (!CGLootInfo::m_lootObj) { + return nullptr; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + if (CGLootInfo::m_coins >= 0) { + GetCurrencyIcon(CGLootInfo::m_coins, s_lootSlotTexture, sizeof(s_lootSlotTexture)); + return s_lootSlotTexture; + } + + return nullptr; + } + + slot--; + } + + if (slot >= 18 || !CGLootInfo::m_slots[slot].m_itemID) { + return nullptr; + } + + const char* path = ClientDBStringLookup(3); + SStrPrintf(s_lootSlotTexture, sizeof(s_lootSlotTexture), "%s%s%s", path, *path ? "\\" : "", CGItem_C::GetInventoryArt(CGLootInfo::m_slots[slot].m_displayId)); + return s_lootSlotTexture; +} + +// VERIFY: c23ec458 auto +// OFFSET: 0x00588430 +void CGLootInfo::GetLootSlotText(char* buffer, uint32_t size, uint32_t slot) { + *buffer = 0; + + if (!CGLootInfo::m_lootObj) { + return; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + if (CGLootInfo::m_coins > 0) { + GetCurrencyText(CGLootInfo::m_coins, buffer, size, "\n"); + } + + return; + } + + slot--; + } + + if (slot < 18 && CGLootInfo::m_slots[slot].m_itemID) { + CGItem_C::BuildItemName(buffer, size, CGLootInfo::m_slots[slot].m_itemID, CGLootInfo::m_slots[slot].m_randomPropertyId); + } +} + +// VERIFY: 8cf50ab0 auto +// OFFSET: 0x005884A0 +char* CGLootInfo::GetLootSlotLink(uint32_t slot, char* buffer, uint32_t size) { + if (!CGLootInfo::m_lootObj) { + return nullptr; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return nullptr; + } + + slot--; + } + + if (slot >= 18 || !CGLootInfo::m_slots[slot].m_itemID) { + return nullptr; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(CGLootInfo::m_slots[slot].m_itemID, CGLootInfo::m_lootObj, nullptr, nullptr, false); + + if (!stats) { + return nullptr; + } + + SStrCopy(buffer, CGTooltip::GetItemHyperlinkString(CGLootInfo::m_slots[slot].m_itemID, stats->m_quality, 0, CGLootInfo::m_slots[slot].m_randomPropertyId, CGLootInfo::m_slots[slot].m_randomSuffix), size); + return buffer; +} + +// VERIFY: d8364d91 auto +// OFFSET: 0x00588530 +uint32_t CGLootDisplay::GetLootAcquireType() { + return CGLootInfo::m_lootType; +} + +// VERIFY: 500b1dce manual +// OFFSET: 0x00588EB0 +int32_t CGLootInfo::HasLoot() { + if (!ClntObjMgrObjectPtr(CGLootInfo::m_lootObj, TYPEMASK_OBJECT, __FILE__, __LINE__)) { + return 0; + } + + if (CGLootInfo::m_coins > 0) { + return 1; + } + + for (uint32_t i = 0; i < 18; i++) { + if (CGLootInfo::m_slots[i].m_itemID) { + return 1; + } + } + + return 0; +} + +// VERIFY: 8a56cb16 manual +// OFFSET: 0x00588F90 +void CGLootInfo::DoAutoLoot(int32_t a1) { + if (CGLootInfo::m_itemsPending) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_OPENED, "%d", 1); + return; + } + + if (CGLootInfo::m_coins) { + player->LootMoney(); + } + + int32_t confirmShown = 0; + + for (uint32_t i = 0; i < 18; i++) { + ::LootSlot& slot = CGLootInfo::m_slots[i]; + + if (!slot.m_itemID) { + continue; + } + + int32_t slotType = CGPlayer_C::GetLootItemSlotType(slot.m_slot); + + if (slotType && slotType != 4) { + continue; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(slot.m_itemID, CGLootInfo::m_lootObj, nullptr, nullptr, false); + + if (stats->m_bonding != 1 || stats->m_quality < 2 || (stats->m_flags[0] & 0x800) || slotType == 4) { + SI2::PlayItemSound(0, stats->m_displayId); + CGPlayer_C::AutoStoreLootItem(slot.m_slot); + } else if (!confirmShown) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_BIND_CONFIRM, "%u", CGLootInfo::m_coins ? i + 2 : i + 1); + s_bindConfirmSlot = i; + confirmShown = 1; + } + } + + player->SetAutoLoot(0); + CGLootInfo::m_autolooted = 1; + + if (!CGLootInfo::HasLoot()) { + CGGameUI::CloseLoot(true, false, false); + return; + } + + if (!a1) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_OPENED, "%d", 1); + } +} + +// VERIFY: 98fb4bdd auto +// OFFSET: 0x00589100 +void CGPlayer_C::OnLootClearMoney() { + if (CGLootInfo::m_coins > 0) { + CGLootInfo::m_coins = -1; + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_SLOT_CLEARED, "%d", 1); + + if (!CGLootInfo::HasLoot()) { + CGGameUI::CloseLoot(true, false, false); + } + } +} + +// VERIFY: 0569898a manual +// OFFSET: 0x00589140 +void CGLootInfo::LootSlot(uint32_t slot) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + if (CGLootInfo::m_coins > 0) { + player->LootMoney(); + CGLootInfo::m_coins = -1; + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_SLOT_CLEARED, "%d", 1); + + if (!CGLootInfo::HasLoot()) { + CGGameUI::CloseLoot(true, false, false); + } + } + + return; + } + + slot--; + } + + if (slot >= 18 || !CGLootInfo::m_slots[slot].m_itemID) { + return; + } + + ::LootSlot& entry = CGLootInfo::m_slots[slot]; + int32_t slotType = CGPlayer_C::GetLootItemSlotType(entry.m_slot); + + switch (slotType) { + case 1: + CGGameUI::DisplayError(ERR_LOOT_ROLL_PENDING); + break; + + case 2: + FrameScript_SignalEvent(SCRIPT_EVENT_OPEN_MASTER_LOOT_LIST, nullptr); + break; + + case 3: + CGGameUI::DisplayError(ERR_LOOT_CANT_LOOT_THAT); + break; + + default: { + ItemStats_C* stats = g_itemDBCache.GetRecord(entry.m_itemID, CGLootInfo::m_lootObj, nullptr, nullptr, false); + + if (!stats) { + break; + } + + if (stats->m_bonding != 1 || stats->m_quality < 2 || (stats->m_flags[0] & 0x800) || slotType == 4) { + SI2::PlayItemSound(0, stats->m_displayId); + CGPlayer_C::AutoStoreLootItem(entry.m_slot); + } else if (player->GetBag()->ItemCountValid(entry.m_itemID, stats, entry.m_count, true)) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_BIND_CONFIRM, "%u", CGLootInfo::m_coins ? slot + 2 : slot + 1); + s_bindConfirmSlot = slot; + } + + break; + } + } +} + +// VERIFY: f307de88 manual +// OFFSET: 0x00589300 +void CGLootInfo::ConfirmLootSlot(uint32_t slot) { + if (!ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)) { + return; + } + + if (CGLootInfo::m_coins) { + if (!slot) { + return; + } + + slot--; + } + + if (static_cast(slot) != s_bindConfirmSlot || !CGLootInfo::m_slots[slot].m_itemID) { + return; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(CGLootInfo::m_slots[slot].m_itemID, CGLootInfo::m_lootObj, nullptr, nullptr, false); + SI2::PlayItemSound(0, stats->m_displayId); + CGPlayer_C::AutoStoreLootItem(CGLootInfo::m_slots[slot].m_slot); + s_bindConfirmSlot = -1; +} + +// VERIFY: 51446391 auto +// OFFSET: 0x005893A0 +void CGLootInfo::GiveMasterLoot(uint32_t slot, WOWGUID target) { + if (!CGLootInfo::m_lootObj) { + return; + } + + if (CGLootInfo::m_coins) { + slot--; + } + + if (slot >= 18 || !CGLootInfo::m_slots[slot].m_itemID || CGPlayer_C::GetLootItemSlotType(CGLootInfo::m_slots[slot].m_slot) != 2) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_LOOT_MASTER_GIVE)); + msg.Put(CGLootInfo::m_lootObj.m_guid); + msg.Put(CGLootInfo::m_slots[slot].m_slot); + msg.Put(target.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 95e3db4e manual +// OFFSET: 0x00589460 +void CGLootInfo::LootButtonItemStatsCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (!success) { + return; + } + + for (uint32_t i = 0; i < 18; i++) { + ::LootSlot& slot = CGLootInfo::m_slots[i]; + + if (slot.m_pending && slot.m_itemID == id) { + if (slot.m_pending == SCRIPT_EVENT_LOOT_SLOT_CHANGED) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_SLOT_CHANGED, "%d", (CGLootInfo::m_coins != 0) + i + 1); + } + + slot.m_pending = 0; + } + } + + if (--CGLootInfo::m_itemsPending) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player && player->m_autoLoot) { + CGLootInfo::DoAutoLoot(0); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_OPENED, "%d", 0); + } +} + +// VERIFY: 98edc3f9 manual +// OFFSET: 0x005896B0 +void CGLootInfo::SetObject(CGObject_C* object, int32_t coins, uint32_t lootType) { + if (CGLootInfo::m_lootObj) { + CGObject_C* current = ClntObjMgrObjectPtr(CGLootInfo::m_lootObj, TYPEMASK_OBJECT, __FILE__, __LINE__); + + if (current) { + if (current->m_obj->m_type & TYPEMASK_UNIT) { + if (!CGLootInfo::HasLoot()) { + static_cast(current)->RemoveLootEffect(); + } + } else if (current->m_obj->m_type & TYPEMASK_GAMEOBJECT) { + static_cast(current)->SetDisplayState(1); + } else if (current->m_obj->m_type & TYPEMASK_ITEM) { + CGGameUI::UnlockItem(CGLootInfo::m_lootObj); + } + } + + for (uint32_t i = 0; i < 18; i++) { + if (CGLootInfo::m_slots[i].m_pending) { + g_itemDBCache.CancelCallback(CGLootInfo::m_slots[i].m_itemID, CGLootInfo::LootButtonItemStatsCallback, nullptr); + } + } + + WOWGUID guid = object ? object->m_obj->m_guid : WOWGUID(); + + if (CGLootInfo::m_lootObj != guid) { + CGLootInfo::m_autolooted = 0; + } + + CGLootInfo::m_lootObj = WOWGUID(); + memset(CGLootInfo::m_slots, 0, sizeof(CGLootInfo::m_slots)); + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_CLOSED, nullptr); + } + + if (!object) { + return; + } + + CGLootInfo::m_lootObj = object->m_obj->m_guid; + CGLootInfo::m_coins = coins; + CGLootInfo::m_itemsPending = 0; + CGLootInfo::m_lootType = lootType; + s_bindConfirmSlot = -1; + uint32_t count = 0; + memset(CGLootInfo::m_slots, 0, sizeof(CGLootInfo::m_slots)); + + for (uint32_t i = 0; i < 18; i++) { + int32_t itemId = CGPlayer_C::GetLootItem(i); + + if (!itemId) { + continue; + } + + ::LootSlot& slot = CGLootInfo::m_slots[count++]; + slot.m_itemID = itemId; + slot.m_displayId = CGPlayer_C::GetLootItemDisplayId(i); + slot.m_count = CGPlayer_C::GetLootItemCount(i); + slot.m_randomSuffix = CGPlayer_C::GetLootItemRandomSuffix(i); + slot.m_randomPropertyId = CGPlayer_C::GetLootItemRandomPropertyId(i); + slot.m_slot = static_cast(i); + slot.m_slotType = CGPlayer_C::GetLootItemSlotType(i); + } + + for (uint32_t i = 0; i < count; i++) { + if (g_itemDBCache.GetRecord(CGLootInfo::m_slots[i].m_itemID, CGLootInfo::m_lootObj, CGLootInfo::LootButtonItemStatsCallback, nullptr, false)) { + CGLootInfo::m_slots[i].m_pending = 0; + } else { + CGLootInfo::m_itemsPending++; + CGLootInfo::m_slots[i].m_pending = 1; + } + } + + if (CGLootInfo::m_itemsPending) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player && player->m_autoLoot) { + CGLootInfo::DoAutoLoot(0); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_OPENED, "%d", 0); + } +} + +// VERIFY: 464fbb82 manual +// OFFSET: 0x00589920 +void CGLootInfo::ClearSlot(uint8_t slot) { + uint32_t index = 0; + + while (!CGLootInfo::m_slots[index].m_itemID || CGLootInfo::m_slots[index].m_slot != slot) { + if (++index >= 18) { + return; + } + } + + if (CGLootInfo::m_slots[index].m_pending) { + g_itemDBCache.CancelCallback(CGLootInfo::m_slots[index].m_itemID, CGLootInfo::LootButtonItemStatsCallback, nullptr); + } + + memset(&CGLootInfo::m_slots[index], 0, sizeof(CGLootInfo::m_slots[index])); + + if (CGLootInfo::m_coins) { + index++; + } + + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_SLOT_CLEARED, "%d", index + 1); + + if (!CGLootInfo::HasLoot()) { + CGGameUI::CloseLoot(true, false, false); + } +} + +// VERIFY: 653fe234 manual +// OFFSET: 0x00589A30 +void CGLootInfo::OnLootSlotChanged(uint8_t slot) { + uint32_t index = 0xFFFFFFFF; + + for (uint32_t i = 0; i < 18; i++) { + if (CGLootInfo::m_slots[i].m_itemID && CGLootInfo::m_slots[i].m_slot == slot) { + index = i; + break; + } + } + + if (index == 0xFFFFFFFF) { + for (uint32_t i = 0; i < 18; i++) { + if (!CGLootInfo::m_slots[i].m_itemID) { + index = i; + break; + } + } + + if (index >= 18) { + return; + } + } + + ::LootSlot& entry = CGLootInfo::m_slots[index]; + entry.m_itemID = CGPlayer_C::GetLootItem(slot); + entry.m_displayId = CGPlayer_C::GetLootItemDisplayId(slot); + entry.m_count = CGPlayer_C::GetLootItemCount(slot); + entry.m_randomSuffix = CGPlayer_C::GetLootItemRandomSuffix(slot); + entry.m_randomPropertyId = CGPlayer_C::GetLootItemRandomPropertyId(slot); + entry.m_slot = slot; + entry.m_slotType = CGPlayer_C::GetLootItemSlotType(slot); + + if (g_itemDBCache.GetRecord(entry.m_itemID, CGLootInfo::m_lootObj, CGLootInfo::LootButtonItemStatsCallback, nullptr, false)) { + entry.m_pending = 0; + } else { + CGLootInfo::m_itemsPending++; + entry.m_pending = SCRIPT_EVENT_LOOT_SLOT_CHANGED; + } + + if (CGLootInfo::m_coins) { + index++; + } + + if (!CGLootInfo::m_itemsPending) { + FrameScript_SignalEvent(SCRIPT_EVENT_LOOT_SLOT_CHANGED, "%d", index + 1); + } +} diff --git a/WoW/Source/Ui/LootFrame.h b/WoW/Source/Ui/LootFrame.h index 758e194..de3e8d3 100644 --- a/WoW/Source/Ui/LootFrame.h +++ b/WoW/Source/Ui/LootFrame.h @@ -6,6 +6,7 @@ #include "WoW/Source/Object/WGUID.h" struct lua_State; +class CGObject_C; struct LootInfo { /* 0000 */ uint32_t unk_0000; @@ -24,10 +25,10 @@ void LootInitialize(); struct LootSlot { /* 0000 */ int32_t m_pending; /* 0004 */ int32_t m_itemID; - /* 0008 */ int32_t unk_0008; + /* 0008 */ int32_t m_displayId; /* 000C */ int32_t m_count; - /* 0010 */ int32_t unk_0010; - /* 0014 */ int32_t unk_0014; + /* 0010 */ int32_t m_randomSuffix; + /* 0014 */ int32_t m_randomPropertyId; /* 0018 */ uint8_t m_slot; /* 0019 */ uint8_t unk_0019[3]; /* 001C */ int32_t m_slotType; @@ -35,29 +36,49 @@ struct LootSlot { class CGLootInfo { public: + static uint32_t m_itemsPending; static uint32_t m_lootType; static LootSlot m_slots[18]; static int32_t m_coins; static WOWGUID m_lootObj; + static int32_t m_autolooted; static void InitializeGame(); + static void LeaveWorld(); static void DoAutoLoot(int32_t a1); + static int32_t HasLoot(); + static void LootSlot(uint32_t slot); + static void ConfirmLootSlot(uint32_t slot); + static void GiveMasterLoot(uint32_t slot, WOWGUID target); + static void LootButtonItemStatsCallback(int32_t id, const WOWGUID& guid, void* param, bool success); + static void SetObject(CGObject_C* object, int32_t coins, uint32_t lootType); + static void ClearSlot(uint8_t slot); + static void OnLootSlotChanged(uint8_t slot); + static int32_t GetLootItem(uint32_t slot); + static int32_t GetLootItemCount(uint32_t slot); + static int32_t GetLootItemRandomSuffix(uint32_t slot); + static int32_t GetLootItemRandomPropertyId(uint32_t slot); + static const char* GetLootSlotTexture(uint32_t slot); + static void GetLootSlotText(char* buffer, uint32_t size, uint32_t slot); + static char* GetLootSlotLink(uint32_t slot, char* buffer, uint32_t size); +}; + +class CGLootWindow { + public: + static int32_t GetNumLootItems(); + static int32_t GetLootItemRarity(uint32_t slot); +}; + +class CGLootDisplay { + public: + static uint32_t GetLootAcquireType(); }; int32_t Script_SetLootPortrait(lua_State* L); -int32_t Script_GetNumLootItems(lua_State* L); -int32_t Script_GetLootSlotInfo(lua_State* L); -int32_t Script_GetLootSlotLink(lua_State* L); -int32_t Script_LootSlot(lua_State* L); -int32_t Script_ConfirmLootSlot(lua_State* L); -int32_t Script_CloseLoot(lua_State* L); -int32_t Script_GiveMasterLoot(lua_State* L); -int32_t Script_GetLootRollItemLink(lua_State* L); -int32_t Script_RollOnLoot(lua_State* L); -int32_t Script_ConfirmLootRoll(lua_State* L); void LootInfoRegisterScriptFunctions(); void CurrencyBreakdown(int32_t amount, int32_t* parts); void GetCurrencyText(int32_t amount, char* buffer, uint32_t size, const char* separator); +void GetCurrencyIcon(int32_t amount, char* buffer, uint32_t size); #endif diff --git a/WoW/Source/Ui/LootFrame_Scripts.cpp b/WoW/Source/Ui/LootFrame_Scripts.cpp index b2a5db0..6727fec 100644 --- a/WoW/Source/Ui/LootFrame_Scripts.cpp +++ b/WoW/Source/Ui/LootFrame_Scripts.cpp @@ -13,6 +13,9 @@ #include "Engine/Source/Storm/H/storm.h" #include "WoW/Source/Game/GameClient/NameCache.h" #include "WoW/Source/Ui/Types.h" +#include "Engine/Source/FrameXML/LoadXML.h" +#include "WoW/Source/UIUtil/Tooltip.h" +#include "WoW/Source/Ui/GameUI.h" // VERIFY: 58fe7575 manual // OFFSET: 0x00588CC0 @@ -182,6 +185,155 @@ static int32_t Script_GetMasterLootCandidate(lua_State* L) { return 1; } +// VERIFY: c26f542e auto +// OFFSET: 0x00588540 +static int32_t Script_GetNumLootItems(lua_State* L) { + lua_pushnumber(L, CGLootWindow::GetNumLootItems()); + return 1; +} + +// VERIFY: d7d7a642 manual +// OFFSET: 0x00588570 +static int32_t Script_GetLootSlotInfo(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetLootSlotInfo(slot)"); + } + + uint32_t slot = static_cast(lua_tonumber(L, 1)) - 1; + lua_pushstring(L, CGLootInfo::GetLootSlotTexture(slot)); + char text[256]; + CGLootInfo::GetLootSlotText(text, sizeof(text), slot); + lua_pushstring(L, text); + lua_pushnumber(L, CGLootInfo::GetLootItemCount(slot)); + lua_pushnumber(L, CGLootWindow::GetLootItemRarity(slot)); + uint32_t index = slot; + + if (CGLootInfo::m_lootObj) { + if (CGLootInfo::m_coins) { + if (!slot) { + lua_pushnil(L); + return 5; + } + + index = slot - 1; + } + + if (index < 18 && CGLootInfo::m_slots[index].m_slotType == 3) { + lua_pushnumber(L, 1.0); + return 5; + } + } + + lua_pushnil(L); + return 5; +} + +// VERIFY: c50a7ab9 manual +// OFFSET: 0x005886D0 +static int32_t Script_GetLootSlotLink(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetLootSlotLink(slot)"); + } + + char link[1024]; + lua_pushstring(L, CGLootInfo::GetLootSlotLink(static_cast(lua_tonumber(L, 1)) - 1, link, sizeof(link))); + return 1; +} + +// VERIFY: a1b183d2 auto +// OFFSET: 0x005888B0 +static int32_t Script_CloseLoot(lua_State* L) { + CGGameUI::CloseLoot(true, false, StringToBOOL(L, 1, 0) != 0); + return 0; +} + +// VERIFY: 520678de manual +// OFFSET: 0x00588C00 +static int32_t Script_GetLootRollItemLink(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetLootRollItemLink(id)"); + } + + PendingLootRoll* roll = FindRoll(static_cast(lua_tonumber(L, 1))); + + if (!roll) { + return 0; + } + + WOWGUID none = WOWGUID(); + ItemStats_C* stats = g_itemDBCache.GetRecord(roll->m_itemId, none, nullptr, nullptr, false); + + if (!stats) { + return 0; + } + + lua_pushstring(L, CGTooltip::GetItemHyperlinkString(roll->m_itemId, stats->m_quality, 0, roll->m_randomPropertyId, roll->m_randomSuffix)); + return 1; +} + +// VERIFY: c94773c2 auto +// OFFSET: 0x00588D60 +static int32_t Script_RollOnLoot(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: RollOnLoot(id, rollType)"); + } + + int32_t id = static_cast(lua_tonumber(L, 1)); + LootRoll(id, static_cast(lua_tonumber(L, 2)), false); + return 0; +} + +// VERIFY: cb1996cb manual +// OFFSET: 0x00588DD0 +static int32_t Script_ConfirmLootRoll(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: ConfirmLootRoll(id, rollType)"); + } + + int32_t id = static_cast(lua_tonumber(L, 1)); + LootRoll(id, static_cast(lua_tonumber(L, 2)), true); + return 0; +} + +// VERIFY: 87cfdafa manual +// OFFSET: 0x00589520 +static int32_t Script_LootSlot(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: LootSlot(slot)"); + } + + CGLootInfo::LootSlot(static_cast(lua_tonumber(L, 1)) - 1); + return 0; +} + +// VERIFY: c2324f9f manual +// OFFSET: 0x00589590 +static int32_t Script_ConfirmLootSlot(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: LootSlot(slot)"); + } + + CGLootInfo::ConfirmLootSlot(static_cast(lua_tonumber(L, 1)) - 1); + return 0; +} + +// VERIFY: f12b832e manual +// OFFSET: 0x00589600 +static int32_t Script_GiveMasterLoot(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: GiveMasterLoot(slot, index)"); + } + + uint32_t slot = static_cast(lua_tonumber(L, 1)) - 1; + WOWGUID target = GetMasterLootCandidate(static_cast(lua_tonumber(L, 2)) - 1); + + if (target) { + CGLootInfo::GiveMasterLoot(slot, target); + } + + return 0; +} + // STATIC: 0x00ACEE28 static FrameScript_Method s_ScriptFunctions[] = { { "SetLootPortrait", &Script_SetLootPortrait }, diff --git a/WoW/Source/Ui/MailInfo.cpp b/WoW/Source/Ui/MailInfo.cpp index 8219837..71598fb 100644 --- a/WoW/Source/Ui/MailInfo.cpp +++ b/WoW/Source/Ui/MailInfo.cpp @@ -1,9 +1,19 @@ #include "MailInfo.h" +#include +#include #include #include "Engine/Source/Storm/H/storm.h" #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/StationeryRec.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/Ui/Types.h" +#include "Engine/Source/Base/CDataStore.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/Object/ItemStats.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" // STATIC: 0x00BEB038 SendMailItem CGMailInfo::m_sendItems[16]; @@ -50,13 +60,25 @@ int32_t CGMailInfo::m_commandPending; // STATIC: 0x00BEB1B9 uint8_t CGMailInfo::m_sendMailShowing; +// STATIC: 0x00BEB1C8 +uint32_t CGMailInfo::m_numStationeries; + +// STATIC: 0x00BEB1D4 +uint32_t CGMailInfo::m_pendingStationeryCallbacks; + +// STATIC: 0x00BEB1E8 +int32_t CGMailInfo::m_doPendingQuery; + +// STATIC: 0x00BEB1EC +int32_t CGMailInfo::m_autoLooting; + // STATIC: 0x00BEB1F0 TSFixedArray CGMailInfo::m_stationeries; // STATIC: 0x00BEB1FC TSGrowableArray CGMailInfo::m_inbox; -// VERIFY: 4a1994f4 manual +// VERIFY: c5353046 manual // OFFSET: 0x00572210 void CGMailInfo::InitializeGame() { uint32_t numStationeries = g_stationeryDB.m_numRecords; @@ -69,8 +91,7 @@ void CGMailInfo::InitializeGame() { CGMailInfo::m_stationeries.m_data[i]->m_id = rec->m_id; CGMailInfo::m_stationeries.m_data[i]->m_itemID = rec->m_itemID; CGMailInfo::m_stationeries.m_data[i]->m_isDefault = rec->m_flags & 1; - CGMailInfo::m_stationeries.m_data[i]->unk_0010 = 0; - CGMailInfo::m_stationeries.m_data[i]->unk_0014 = 0; + CGMailInfo::m_stationeries.m_data[i]->m_itemGUID = WOWGUID{ 0 }; } CGMailInfo::m_inbox.SetCount(8); @@ -87,3 +108,162 @@ void CGMailInfo::InitializeGame() { ClientServices::SetMessageHandler(SMSG_RECEIVED_MAIL, Packet_SMSG_RECEIVED_MAIL, nullptr); ClientServices::SetMessageHandler(SMSG_SHOW_MAILBOX, Packet_SMSG_SHOW_MAILBOX, nullptr); } + +// VERIFY: 2350f8eb auto +// OFFSET: 0x0056DED0 +void CGMailInfo::UpdatePendingMail(float elapsed) { + for (int32_t i = 0; i < 3; i++) { + MailSenderInfo& sender = s_recentSenders[i]; + + if ((sender.m_guid || sender.m_entry) && sender.unk_0014 > 0.0f) { + float remaining = sender.unk_0014 - elapsed; + sender.unk_0014 = remaining > 0.0f ? remaining : 0.0f; + + if (fabs(sender.unk_0014) < 0.00000023841858f) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_PENDING_MAIL, nullptr); + } + } + } + + if (CGMailInfo::m_nextMailTime > 0.0f) { + float remaining = CGMailInfo::m_nextMailTime - elapsed; + CGMailInfo::m_nextMailTime = remaining > 0.0f ? remaining : 0.0f; + + if (fabs(CGMailInfo::m_nextMailTime) < 0.00000023841858f) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_PENDING_MAIL, nullptr); + } + } +} + +// VERIFY: 4eaaa3df manual +// OFFSET: 0x0056DD00 +static int32_t QSortStationery(const void* a, const void* b) { + const StationeryInfo* infoA = *static_cast(a); + const StationeryInfo* infoB = *static_cast(b); + + if (infoA->m_isDefault != infoB->m_isDefault) { + return 2 * (infoA->m_isDefault == 0) - 1; + } + + if (infoA->m_itemGUID && !infoB->m_itemGUID) { + return -1; + } + + if (infoB->m_itemGUID && !infoA->m_itemGUID) { + return 1; + } + + ItemStats_C* statsA = g_itemDBCache.GetRecord(infoA->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false); + ItemStats_C* statsB = g_itemDBCache.GetRecord(infoB->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false); + + if (!statsA) { + if (!statsB) { + return 0; + } + + return 2 * (statsA == nullptr) - 1; + } + + if (!statsB) { + return 2 * (statsA == nullptr) - 1; + } + + if (statsA->m_buyPrice != statsB->m_buyPrice) { + return 2 * (statsA->m_buyPrice >= statsB->m_buyPrice) - 1; + } + + return SStrSortUTF8I(statsA->GetName(0), statsB->GetName(0), STORM_MAX_STR); +} + +// VERIFY: 77c88115 manual +// OFFSET: 0x0056FC80 +void CGMailInfo::UpdateStationeryList() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + CGMailInfo::m_numStationeries = 0; + + for (uint32_t i = 0; i < CGMailInfo::m_stationeries.m_count; i++) { + StationeryRec* rec = g_stationeryDB.GetRecord(CGMailInfo::m_stationeries.m_data[i]->m_id); + CGItem_C* item = player->m_bag.FindItemOfType(rec->m_itemID, 0); + CGMailInfo::m_stationeries.m_data[i]->m_itemGUID = item ? item->m_obj->m_guid : WOWGUID{ 0 }; + + if (CGMailInfo::m_stationeries.m_data[i]->m_isDefault || CGMailInfo::m_stationeries.m_data[i]->m_itemGUID) { + if (g_itemDBCache.GetRecord(rec->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false)) { + CGMailInfo::m_numStationeries++; + } + } + } + + qsort(CGMailInfo::m_stationeries.m_data, CGMailInfo::m_stationeries.m_count, sizeof(StationeryInfo*), QSortStationery); +} + +// VERIFY: 4741646d manual +// OFFSET: 0x0056FF70 +void CGMailInfo::QueryNextMailTime() { + CDataStore msg; + msg.Put(static_cast(MSG_QUERY_NEXT_MAIL_TIME)); + msg.Finalize(); + ClientServices::Send2(&msg); + CGMailInfo::m_nextMailTime = -1.0f; + CGMailInfo::m_doPendingQuery = 0; +} + +// VERIFY: a66c7d69 auto +// OFFSET: 0x00571520 +void StationeryItemCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (!--CGMailInfo::m_pendingStationeryCallbacks) { + CGMailInfo::UpdateStationeryList(); + } +} + +// VERIFY: a800705f auto +// OFFSET: 0x00571530 +void CGMailInfo::EnterWorld() { + CGMailInfo::m_object = WOWGUID{ 0 }; + memset(CGMailInfo::m_sendItems, 0, sizeof(CGMailInfo::m_sendItems)); + CGMailInfo::m_nextMailTime = -1.0f; + CGMailInfo::m_sendMoney = 0; + CGMailInfo::m_lockSendItems = 0; + CGMailInfo::unk_BEB1C4 = 0; + CGMailInfo::m_numStationeries = 0; + CGMailInfo::m_selectedStationery = 0; + CGMailInfo::m_selectedPackage = 0; + CGMailInfo::m_pendingStationeryCallbacks = 0; + CGMailInfo::m_numInboxItems = 0; + CGMailInfo::m_totalInboxItems = 0; + CGMailInfo::m_nextUpdateTime = 0; + CGMailInfo::m_commandPending = 0; + CGMailInfo::m_sendMailShowing = 0; + + for (uint32_t i = 0; i < CGMailInfo::m_stationeries.m_count; i++) { + if (!g_itemDBCache.GetRecord(CGMailInfo::m_stationeries.m_data[i]->m_itemID, WOWGUID{ 0 }, StationeryItemCallback, nullptr, false)) { + CGMailInfo::m_pendingStationeryCallbacks++; + } + } + + if (!CGMailInfo::m_pendingStationeryCallbacks) { + CGMailInfo::UpdateStationeryList(); + } + + memset(s_recentSenders, 0, sizeof(s_recentSenders)); + CGMailInfo::QueryNextMailTime(); + CGMailInfo::m_autoLooting = 0; +} + +// VERIFY: f68c3d1a auto +// OFFSET: 0x0056D3C0 +uint32_t CGMailInfo::GetNumSendItems() { + uint32_t count = 0; + + for (uint32_t i = 0; i < 16; i++) { + if (CGMailInfo::m_sendItems[i].m_guid) { + count++; + } + } + + return count; +} diff --git a/WoW/Source/Ui/MailInfo.h b/WoW/Source/Ui/MailInfo.h index 7fd4966..f9b0438 100644 --- a/WoW/Source/Ui/MailInfo.h +++ b/WoW/Source/Ui/MailInfo.h @@ -22,8 +22,7 @@ struct StationeryInfo { /* 0004 */ int32_t m_itemID; /* 0008 */ int32_t m_isDefault; /* 000C */ int32_t unk_000C; - /* 0010 */ int32_t unk_0010; - /* 0014 */ int32_t unk_0014; + /* 0010 */ WOWGUID m_itemGUID; }; struct MailboxMessageInfo { @@ -62,6 +61,7 @@ class CGMailInfo { static void ClearSendMail(bool signal); static void CloseMail(bool leavingWorld); static uint8_t m_sendMailShowing; + static void AddItemToOutgoingMail(int32_t index, WOWGUID item, WOWGUID container, uint32_t slot); static TSFixedArray m_stationeries; static TSGrowableArray m_inbox; static void EnterWorld(); @@ -77,8 +77,18 @@ class CGMailInfo { static WOWGUID m_object; static uint32_t m_nextUpdateTime; static int32_t m_commandPending; + static uint32_t m_numStationeries; + static uint32_t m_pendingStationeryCallbacks; + static int32_t m_doPendingQuery; + static int32_t m_autoLooting; + + static uint32_t GetNumSendItems(); + static void QueryNextMailTime(); + static void UpdateStationeryList(); }; +void StationeryItemCallback(int32_t id, const WOWGUID& guid, void* param, bool success); + int32_t Script_CloseMail(lua_State* L); int32_t Script_ClearSendMail(lua_State* L); int32_t Script_ClickSendMailItemButton(lua_State* L); @@ -87,7 +97,6 @@ int32_t Script_SetSendMailCOD(lua_State* L); int32_t Script_GetNumStationeries(lua_State* L); int32_t Script_GetSendMailItem(lua_State* L); int32_t Script_GetSendMailItemLink(lua_State* L); -int32_t Script_GetSendMailPrice(lua_State* L); int32_t Script_SendMail(lua_State* L); int32_t Script_GetInboxHeaderInfo(lua_State* L); int32_t Script_GetInboxText(lua_State* L); diff --git a/WoW/Source/Ui/MailInfo_Scripts.cpp b/WoW/Source/Ui/MailInfo_Scripts.cpp index 7915ba1..6414b68 100644 --- a/WoW/Source/Ui/MailInfo_Scripts.cpp +++ b/WoW/Source/Ui/MailInfo_Scripts.cpp @@ -202,7 +202,7 @@ static int32_t Script_SelectStationery(lua_State* L) { return 0; } -// VERIFY: f642dbb8 manual +// VERIFY: a8f5093e manual // OFFSET: 0x0056DF80 static int32_t Script_GetStationeryInfo(lua_State* L) { if (!lua_isnumber(L, 1)) { @@ -220,7 +220,7 @@ static int32_t Script_GetStationeryInfo(lua_State* L) { lua_pushstring(L, stats->m_name[0]); lua_pushstring(L, s_stationeryTexture); - if (stationery->unk_0010) { + if (stationery->m_itemGUID) { lua_pushnil(L); } else { lua_pushnumber(L, stats->m_buyPrice); @@ -281,6 +281,46 @@ static int32_t Script_GetNumPackages(lua_State* L) { return 1; } +// VERIFY: 12b74c11 auto +// OFFSET: 0x00571B00 +static int32_t Script_GetSendMailPrice(lua_State* L) { + uint32_t price = 30; + uint32_t itemPrice = 30 * CGMailInfo::GetNumSendItems(); + + if (itemPrice >= 30) { + price = itemPrice; + } + + if (CGMailInfo::m_selectedStationery) { + for (uint32_t i = 0; i < CGMailInfo::m_numStationeries; i++) { + StationeryInfo* stationery = CGMailInfo::m_stationeries.m_data[i]; + + if (stationery->m_id == CGMailInfo::m_selectedStationery) { + if (!stationery->m_itemGUID) { + ItemStats_C* stats = g_itemDBCache.GetRecord(stationery->m_itemID, WOWGUID{ 0 }, nullptr, nullptr, false); + + if (stats) { + price += stats->m_buyPrice; + } + } + + break; + } + } + } + + if (CGMailInfo::m_selectedPackage) { + PackageRec* rec = g_packageDB.GetRecord(CGMailInfo::m_selectedPackage); + + if (rec) { + price += rec->m_cost; + } + } + + lua_pushnumber(L, price + CGMailInfo::m_sendMoney); + return 1; +} + // STATIC: 0x00ACE610 static FrameScript_Method s_ScriptFunctions[] = { { "CloseMail", &Script_CloseMail }, diff --git a/WoW/Source/Ui/MerchantFrame.cpp b/WoW/Source/Ui/MerchantFrame.cpp index c0d240f..c10ba3f 100644 --- a/WoW/Source/Ui/MerchantFrame.cpp +++ b/WoW/Source/Ui/MerchantFrame.cpp @@ -1,4 +1,7 @@ #include "MerchantFrame.h" +#include +#include +#include "WoW/Source/Object/Player.h" #include "Engine/Source/Tempest/CMath.h" #include "WoW/Source/Object/ObjectClient/Item_C.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" @@ -138,3 +141,78 @@ ItemStats_C* CGMerchantInfo::GetItemStats(int32_t itemId) { return stats; } + +// VERIFY: e792c48f manual +// OFFSET: 0x005841A0 +static int32_t QSortBuybackTimestamps(const void* a, const void* b) { + uint32_t timeA = static_cast(a)->m_timestamp; + uint32_t timeB = static_cast(b)->m_timestamp; + + if (timeB > timeA) { + return -1; + } + + return timeB < timeA; +} + +// VERIFY: e50eb21c manual +// OFFSET: 0x00584BB0 +void CGMerchantInfo::SortBuybackItems() { + memset(CGMerchantInfo::m_buybackSlots, 0, sizeof(CGMerchantInfo::m_buybackSlots)); + CGMerchantInfo::m_numBuybackItems = 0; + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + BuybackEntry entries[12]; + + for (uint32_t slot = 74; slot - 74 < 12; slot++) { + if (slot < static_cast(player->m_bag.m_numSlots) && player->m_bag.m_slots[slot] && slot - 74 < 12 && player->m_player->m_playerFieldBuybackPrice1[slot - 74]) { + entries[CGMerchantInfo::m_numBuybackItems].m_timestamp = player->m_player->m_playerFieldBuybackTimestamp1[slot - 74]; + entries[CGMerchantInfo::m_numBuybackItems].m_slot = slot; + CGMerchantInfo::m_numBuybackItems++; + } + } + + qsort(entries, CGMerchantInfo::m_numBuybackItems, sizeof(BuybackEntry), QSortBuybackTimestamps); + + for (uint32_t i = 0; i < CGMerchantInfo::m_numBuybackItems; i++) { + CGMerchantInfo::m_buybackSlots[i] = entries[i].m_slot; + } +} + +// VERIFY: 620ce8ba auto +// OFFSET: 0x00585F60 +static int32_t BuybackUpdateHandler(WOWGUID guid, uint32_t fieldOffset, uint32_t fieldSize, const void* oldValue, void* param) { + CGMerchantInfo::SortBuybackItems(); + FrameScript_SignalEvent(SCRIPT_EVENT_MERCHANT_UPDATE, nullptr); + return 1; +} + +// VERIFY: 6e746dba auto +// OFFSET: 0x00585F80 +void CGMerchantInfo::EnterWorld() { + CGMerchantInfo::m_merchant = WOWGUID{ 0 }; + CGMerchantInfo::m_numMerchantItems = 0; + memset(CGMerchantInfo::m_items, 0, sizeof(CGMerchantInfo::m_items)); + ClntObjMgrSetObjMirrorHandler(ClntObjMgrGetActivePlayer(), ID_PLAYER, offsetof(CGPlayerLocalData, m_playerFieldBuybackPrice1), sizeof(CGPlayerLocalData::m_playerFieldBuybackPrice1) + sizeof(CGPlayerLocalData::m_playerFieldBuybackTimestamp1), BuybackUpdateHandler, nullptr, static_cast(0), 0); + CGMerchantInfo::SortBuybackItems(); +} + +// VERIFY: 20b7ca61 auto +// OFFSET: 0x005840C0 +void CGMerchantInfo::RefreshList() { + if (CGMerchantInfo::m_merchant) { + FrameScript_SignalEvent(SCRIPT_EVENT_MERCHANT_UPDATE, nullptr); + } +} + +// VERIFY: ceeabfca manual +// OFFSET: 0x005845B0 +int32_t CGMerchantInfo::CanRepair() { + CGUnit_C* merchant = static_cast(ClntObjMgrObjectPtr(CGMerchantInfo::m_merchant, TYPEMASK_UNIT, __FILE__, __LINE__)); + return merchant && (merchant->m_unit->m_unitNpcFlags & 0x1000); +} diff --git a/WoW/Source/Ui/MerchantFrame.h b/WoW/Source/Ui/MerchantFrame.h index bb9ab47..4fbf60f 100644 --- a/WoW/Source/Ui/MerchantFrame.h +++ b/WoW/Source/Ui/MerchantFrame.h @@ -20,6 +20,11 @@ struct MerchantItem { /* 001C */ int32_t m_extendedCostID; }; +struct BuybackEntry { + /* 0000 */ uint32_t m_timestamp; + /* 0004 */ uint32_t m_slot; +}; + class CGMerchantInfo { public: static uint32_t m_buybackSlots[12]; @@ -27,8 +32,11 @@ class CGMerchantInfo { static ItemStats_C* GetItemStats(int32_t itemId); static uint32_t m_pendingItemStats; static void SetMerchant(WOWGUID merchant, const MerchantItem* items, int32_t count); + static void RefreshList(); + static int32_t CanRepair(); static void CloseMerchant(); static void EnterWorld(); + static void SortBuybackItems(); static MerchantItem* FindItemById(int32_t itemId); static int32_t GetRepairCost(CGItem_C* item); static MerchantItem m_items[150]; diff --git a/WoW/Source/Ui/MinimapFrame.cpp b/WoW/Source/Ui/MinimapFrame.cpp index 5538fcc..ce6dd7d 100644 --- a/WoW/Source/Ui/MinimapFrame.cpp +++ b/WoW/Source/Ui/MinimapFrame.cpp @@ -23,6 +23,15 @@ #include "WoW/Source/Ui/WorldFrame.h" #include "Engine/Source/Tempest/CMath.h" #include "WoW/Source/DB/Rec/AreaPOIRec.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Ui/Types.h" +#include +#include +#include "Engine/Source/BlizzardCore/SFile2-Core.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Ui/CGWorldStateInfo.h" // STATIC: 0x00ACEBAC int32_t CGMinimapFrame::s_scaleChanged = 1; @@ -145,8 +154,68 @@ const TrackingTypeInfo CGMinimapFrame::s_trackingTypes[15] = { { 3, 0x0, "MINIMAP_TRACKING_TRIVIAL_QUESTS", "TrivialQuests", 0x0 }, }; +// STATIC: 0x00A41E04 +static const int32_t s_outdoorZoomTiles[6] = { 14, 12, 10, 8, 6, 4 }; + +// STATIC: 0x00A41E1C +static const float s_indoorZoomRadius[6] = { 150.0f, 120.0f, 90.0f, 60.0f, 40.0f, 25.0f }; + +// STATIC: 0x00AF4E48 +static int32_t s_mapId = -1; + +// STATIC: 0x00AF4E4C +static int32_t s_outdoorZoom = 3; + +// STATIC: 0x00AF4E50 +static int32_t s_indoorZoom = 3; + +// STATIC: 0x00AF4E58 +static const char* s_minimapTexturePath = "Textures\\Minimap"; + +// STATIC: 0x00D39210 +static float s_closestPOIFacing[3]; + +// STATIC: 0x00D3921C +static int32_t s_closestPOIs[3]; + +// STATIC: 0x00D39228 +static int32_t s_poisChanged; + +// STATIC: 0x00D39230 +static char s_dynamicPOINames[4][64]; + +// STATIC: 0x00D39434 +static uint8_t s_isIndoors; + +// STATIC: 0x00D39444 +static uint32_t s_numPOIs; + +// STATIC: 0x00D39448 +static uint32_t s_numClosestPOIs; + +// STATIC: 0x00D3944C +static int32_t s_closestPOIsChanged; + +// STATIC: 0x00D39454 +static C3Vector s_playerPosition; + // STATIC: 0x00D39490 -static AreaPOIRec s_dynamicPOIs[2]; +static AreaPOIRec s_dynamicPOIs[4]; + +// STATIC: 0x00D395F0 +static TSFixedArray s_pois; + +// STATIC: 0x00D395FC +static TSFixedArray s_poiVisible; + +// STATIC: 0x00D39608 +static TSFixedArray s_poiOnEdge; + +// STATIC: 0x00D39614 +static TSGrowableArray s_visiblePOIs; + +// STATIC: 0x00D39624 +static TSHashTable s_md5Names; // INLINED void CGMinimapFrame::operator delete(void* ptr) { @@ -477,3 +546,271 @@ const TrackingTypeInfo* CGMinimapFrame::GetTrackingTypeByIndex(int32_t index) { AreaPOIRec* MinimapGetGossipPoi() { return &s_dynamicPOIs[1]; } + +// VERIFY: 23614ed9 manual +// OFFSET: 0x0057EA30 +void CGMinimapFrame::SetTrackingSpell(int32_t spellId) { + CGMinimapFrame::s_trackingSpell = spellId; + + if (spellId) { + CGMinimapFrame::LoadTrackingInfo(0); + } else { + Script_SendUniqueSignal(SCRIPT_EVENT_MINIMAP_UPDATE_TRACKING); + } +} + +// VERIFY: 08401ea1 auto +// OFFSET: 0x007F3B90 +float MinimapGetViewRadius() { + if (s_isIndoors) { + return s_indoorZoomRadius[s_indoorZoom]; + } + + return s_outdoorZoomTiles[s_outdoorZoom] * 0.5f * 33.333332f; +} + +// VERIFY: 10a7b5c4 manual +// OFFSET: 0x007F44A0 +void UpdatePointsOfInterest() { + if (s_mapId == -1) { + return; + } + + s_visiblePOIs.SetCount(0); + float viewRadius = MinimapGetViewRadius(); + + for (uint32_t i = 0; i < s_numPOIs; i++) { + AreaPOIRec* poi = s_pois.m_data[i]; + + if ((poi->m_pos[0] == 0.0f && poi->m_pos[1] == 0.0f) || (poi->m_worldStateID && !GetWorldState(poi->m_worldStateID))) { + if (!s_poiVisible.m_data[i] && !s_poiOnEdge.m_data[i]) { + continue; + } + + s_poiVisible.m_data[i] = 0; + s_poiOnEdge.m_data[i] = 0; + s_poisChanged = 1; + continue; + } + + float dy = s_playerPosition.y - poi->m_pos[1]; + float dx = s_playerPosition.x - poi->m_pos[0]; + + if (sqrt(dx * dx + dy * dy) / viewRadius > 0.8f) { + if (!s_poiVisible.m_data[i] && s_poiOnEdge.m_data[i]) { + continue; + } + + s_poiVisible.m_data[i] = 0; + s_poiOnEdge.m_data[i] = 1; + s_poisChanged = 1; + continue; + } + + if (!(poi->m_flags & 2)) { + if (!s_poiVisible.m_data[i] && !s_poiOnEdge.m_data[i]) { + continue; + } + + s_poiVisible.m_data[i] = 0; + s_poiOnEdge.m_data[i] = 0; + s_poisChanged = 1; + continue; + } + + *s_visiblePOIs.New() = poi; + + if (s_poiVisible.m_data[i] && !s_poiOnEdge.m_data[i]) { + continue; + } + + s_poiVisible.m_data[i] = 1; + s_poiOnEdge.m_data[i] = 0; + s_poisChanged = 1; + } + + int32_t worst = -1; + uint32_t count = 0; + float distances[3] = { 694.44446f, 694.44446f, 694.44446f }; + int32_t indices[3] = { -1, -1, -1 }; + int32_t importance[3]; + + for (uint32_t i = 0; i < s_numPOIs; i++) { + if (!s_poiOnEdge.m_data[i]) { + continue; + } + + AreaPOIRec* poi = s_pois.m_data[i]; + float dy = poi->m_pos[1] - s_playerPosition.y; + float dx = poi->m_pos[0] - s_playerPosition.x; + float distance = sqrt(dx * dx + dy * dy); + + if (distance > 694.44446f && poi != &s_dynamicPOIs[2]) { + continue; + } + + if (worst == -1) { + distances[count] = distance; + indices[count] = i; + importance[count] = poi->m_importance; + count++; + } else if (poi->m_importance < importance[worst] || (poi->m_importance == importance[worst] && distance < distances[worst])) { + distances[worst] = distance; + indices[worst] = i; + importance[worst] = poi->m_importance; + } + + if (count == 3) { + worst = 0; + + for (int32_t j = 1; j < 3; j++) { + if (importance[j] > importance[worst] || (importance[j] == importance[worst] && distances[worst] < distances[j])) { + worst = j; + } + } + } + } + + if (s_numClosestPOIs != count) { + s_numClosestPOIs = count; + s_closestPOIsChanged = 1; + } else { + for (uint32_t j = 0; j < count; j++) { + if (indices[j] != s_closestPOIs[j]) { + s_closestPOIsChanged = 1; + break; + } + } + } + + for (uint32_t j = 0; j < count; j++) { + s_closestPOIs[j] = indices[j]; + AreaPOIRec* poi = s_pois.m_data[indices[j]]; + C3Vector position(poi->m_pos[0], poi->m_pos[1], s_playerPosition.z); + s_closestPOIFacing[j] = CalculateFacingTo(&s_playerPosition, &position); + } +} + +// VERIFY: 3a8b6454 auto +// OFFSET: 0x007F4990 +void MinimapSetCorpsePOI(float x, float y) { + const char* name = FrameScript_GetText("CORPSE_RED", -1, GENDER_NOT_APPLICABLE); + s_dynamicPOIs[2].m_pos[0] = x; + s_dynamicPOIs[2].m_pos[1] = y; + s_dynamicPOIs[2].m_flags = 2; + s_dynamicPOIs[2].m_continentID = s_mapId; + s_dynamicPOIs[2].m_icon[0] = 8; + s_dynamicPOIs[2].m_importance = -1; + SStrCopy(s_dynamicPOINames[2], name, sizeof(s_dynamicPOINames[2])); + UpdatePointsOfInterest(); + s_closestPOIsChanged = 1; +} + +// VERIFY: 7ee85ac8 auto +// OFFSET: 0x007F4A00 +void MinimapSetSpiritHealerPOI(float x, float y) { + const char* name = FrameScript_GetText("SPIRIT_HEALER_RELEASE_RED", -1, GENDER_NOT_APPLICABLE); + s_dynamicPOIs[3].m_pos[0] = x; + s_dynamicPOIs[3].m_pos[1] = y; + s_dynamicPOIs[3].m_flags = 2; + s_dynamicPOIs[3].m_continentID = s_mapId; + s_dynamicPOIs[3].m_icon[0] = 8; + s_dynamicPOIs[3].m_importance = -1; + SStrCopy(s_dynamicPOINames[3], name, sizeof(s_dynamicPOINames[3])); + UpdatePointsOfInterest(); + s_closestPOIsChanged = 1; +} + +// VERIFY: 0eda32e5 manual +// OFFSET: 0x007F6540 +static void LoadMD5Names() { + char path[260]; + SStrPrintf(path, sizeof(path), "%s\\md5translate.trs", s_minimapTexturePath); + void* data; + + if (!SFile::LoadFile(path, &data, nullptr, 1, nullptr)) { + return; + } + + const char* cursor = static_cast(data); + char line[260]; + memset(line, 0, sizeof(line)); + + do { + SStrTokenize(&cursor, line, sizeof(line), "\r\n", nullptr); + + if (!*cursor || !line[0]) { + break; + } + + if (!SStrCmp(line, "dir:", SStrLen("dir:"))) { + continue; + } + + char* tab = SStrChr(line, '\t'); + + if (!tab) { + continue; + } + + *tab = '\0'; + MINIMAPMD5NAME* entry = s_md5Names.Ptr(line); + + if (!entry) { + entry = s_md5Names.New(line, 0, 0); + } + + SStrCopy(entry->m_md5Name, tab + 1, sizeof(entry->m_md5Name)); + } while (line[0] && *cursor); + + SFile::Unload(data); +} + +// VERIFY: 885c45ba manual +// OFFSET: 0x007F6730 +void MinimapInitialize(int32_t mapId) { + s_numPOIs = 0; + + for (int32_t pass = 0; pass < 2; pass++) { + if (pass > 0) { + s_pois.SetCount(s_numPOIs); + s_poiVisible.SetCount(s_numPOIs); + s_poiOnEdge.SetCount(s_numPOIs); + memset(s_poiVisible.m_data, 0, sizeof(int32_t) * s_poiVisible.m_count); + memset(s_poiOnEdge.m_data, 0, sizeof(int32_t) * s_poiOnEdge.m_count); + } + + uint32_t count = 0; + + for (int32_t i = g_areaPOIDB.m_numRecords - 1; i >= 0; i--) { + AreaPOIRec* rec = g_areaPOIDB.GetRecordByIndex(i); + + if (rec->m_continentID == mapId && (rec->m_flags & 1)) { + if (pass > 0) { + s_pois.m_data[count] = rec; + } + + count++; + } + } + + s_numPOIs = count + 4; + } + + for (uint32_t i = 0; i < 4; i++) { + s_pois.m_data[s_numPOIs - 4 + i] = &s_dynamicPOIs[i]; + memset(&s_dynamicPOIs[i], 0, sizeof(s_dynamicPOIs[i])); + s_dynamicPOIs[i].m_name = s_dynamicPOINames[i]; + } + + s_closestPOIFacing[0] = -1.0f; + s_closestPOIFacing[1] = -1.0f; + s_closestPOIFacing[2] = -1.0f; + s_closestPOIs[0] = -1; + s_closestPOIs[1] = -1; + s_closestPOIs[2] = -1; + s_outdoorZoom = g_minimapZoomCVar->m_intValue; + s_indoorZoom = g_minimapInsideZoomCVar->m_intValue; + FrameScript_SignalEvent(SCRIPT_EVENT_MINIMAP_UPDATE_ZOOM, nullptr); + LoadMD5Names(); +} diff --git a/WoW/Source/Ui/MinimapFrame.h b/WoW/Source/Ui/MinimapFrame.h index bf5140b..c3679fd 100644 --- a/WoW/Source/Ui/MinimapFrame.h +++ b/WoW/Source/Ui/MinimapFrame.h @@ -8,6 +8,8 @@ #include "Engine/Source/Gx/CGxTex.h" #include "Engine/Source/Tempest/C3Vector.h" #include "Engine/Source/Tempest/C2Vector.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/Object/WGUID.h" class CRenderBatch; class CScriptRegion; @@ -18,6 +20,10 @@ struct lua_State; class AreaPOIRec; +struct MINIMAPMD5NAME : public TSHashObject { + /* 0018 */ char m_md5Name[40]; +}; + struct TrackingTypeInfo { /* 0000 */ int32_t m_type; /* 0004 */ uint32_t m_npcFlags; @@ -32,8 +38,10 @@ class CGMinimapFrame : public CSimpleFrame { public: static void EnterWorld(); static CDataAllocator s_minimapHeap; + static void SetPingPosition(const WOWGUID& guid, const C2Vector& position); static void MinimapTextureCallback(EGxTexCommand command, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevel, void* userArg, uint32_t& texelStrideInBytes, const void*& texels); static void SetTrackingSpell(int32_t spellId); + static void LoadTrackingInfo(int32_t a1); static int32_t s_metatable; static int32_t s_objectType; @@ -93,7 +101,9 @@ int32_t Script_SetTracking(lua_State* L); void MinimapRegisterScriptFunctions(); void MinimapInitialize(int32_t mapId); +float MinimapGetViewRadius(); AreaPOIRec* MinimapGetGossipPoi(); +void UpdatePointsOfInterest(); void MinimapSetCorpsePOI(float x, float y); void MinimapSetSpiritHealerPOI(float x, float y); diff --git a/WoW/Source/Ui/NamePlateFrame.h b/WoW/Source/Ui/NamePlateFrame.h index 63cf622..bd41ec2 100644 --- a/WoW/Source/Ui/NamePlateFrame.h +++ b/WoW/Source/Ui/NamePlateFrame.h @@ -17,6 +17,8 @@ class CGNamePlateFrame : public CSimpleFrame { public: static CGNamePlateFrame* GetNamePlateFocus(); + void UpdateLevelDisplay(CGUnit_C* unit); + /* 029C */ TSLink m_link; /* 02A4 */ uint32_t unk_02A4; /* 02A8 */ WOWGUID m_guid; diff --git a/WoW/Source/Ui/PaperDollInfoFrame.cpp b/WoW/Source/Ui/PaperDollInfoFrame.cpp index 44ffc31..6c1f683 100644 --- a/WoW/Source/Ui/PaperDollInfoFrame.cpp +++ b/WoW/Source/Ui/PaperDollInfoFrame.cpp @@ -8,6 +8,8 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/Types.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/Ui/TalentInfo.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" // STATIC: 0x00C24230 TSFixedArray CGCharacterInfo::m_invAlertStatus; @@ -207,3 +209,50 @@ int32_t Packet_MSG_INSPECT_ARENA_TEAMS(void* param, NETMESSAGE msgId, uint32_t t FrameScript_SignalEvent(SCRIPT_EVENT_INSPECT_HONOR_UPDATE, nullptr); return 1; } + +// VERIFY: aedc8113 auto +// OFFSET: 0x005E76B0 +void CGCharacterInfo::SetInspectTarget(const WOWGUID& guid) { + if (guid == CGCharacterInfo::m_inspectTarget) { + return; + } + + CGCharacterInfo::m_inspectTarget = guid; + CGCharacterInfo::m_hasHonorData = 0; + CGCharacterInfo::m_honorRequestPending = 0; + + for (uint32_t i = 0; i < 3; i++) { + CGCharacterInfo::m_inspectArenaTeams[i].m_teamId = 0; + } + + CGTalentInfo_Inspect::SetInspectTarget(guid); +} + +// VERIFY: dcb1d352 manual +// OFFSET: 0x005E84C0 +void CGCharacterInfo::UpdateItem(WOWGUID guid) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_ITEM, __FILE__, __LINE__)); + int32_t slot = player->m_bag.FindItemSlot(guid); + + if (slot == -1 && item && item->m_item->m_itemFieldContained != ClntObjMgrGetActivePlayer()) { + slot = player->m_bag.FindItemSlot(item->m_item->m_itemFieldContained); + } + + if (static_cast(slot) > 22) { + if ((slot >= 39 && slot <= 66) || static_cast(slot - 67) <= 6) { + FrameScript_SignalEvent(SCRIPT_EVENT_PLAYERBANKSLOTS_CHANGED, "%d", slot - 38); + } + + if (!item || item->m_obj->m_entryID != CGCharacterInfo::GetActivePlayerAmmoID(player)) { + return; + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_UNIT_INVENTORY_CHANGED, "%s", "player"); +} diff --git a/WoW/Source/Ui/PaperDollInfoFrame.h b/WoW/Source/Ui/PaperDollInfoFrame.h index ce43d01..ceee47e 100644 --- a/WoW/Source/Ui/PaperDollInfoFrame.h +++ b/WoW/Source/Ui/PaperDollInfoFrame.h @@ -37,6 +37,7 @@ class CGCharacterInfo { static int32_t CanInspect(const CGPlayer_C* unit); static int32_t GetActivePlayerAmmoID(const CGPlayer_C* player); static void EnterWorld(); + static void SetInspectTarget(const WOWGUID& guid); static void InitializeGame(); static void UpdateInventoryAlerts(); static void UpdateItem(WOWGUID guid); @@ -46,7 +47,6 @@ int32_t Script_GetInventoryItemsForSlot(lua_State* L); int32_t Script_GetInventoryItemBroken(lua_State* L); int32_t Script_GetInventoryItemCount(lua_State* L); int32_t Script_GetInventoryItemQuality(lua_State* L); -int32_t Script_GetInventoryItemCooldown(lua_State* L); int32_t Script_GetInventoryItemDurability(lua_State* L); int32_t Script_GetInventoryItemLink(lua_State* L); int32_t Script_GetInventoryItemID(lua_State* L); diff --git a/WoW/Source/Ui/PaperDollInfoFrame_Scripts.cpp b/WoW/Source/Ui/PaperDollInfoFrame_Scripts.cpp index 465d194..eb77ff1 100644 --- a/WoW/Source/Ui/PaperDollInfoFrame_Scripts.cpp +++ b/WoW/Source/Ui/PaperDollInfoFrame_Scripts.cpp @@ -14,6 +14,7 @@ #include "Engine/Source/FrameScript/FrameScript_Object.h" #include "WoW/Source/DB/Rec/PaperDollItemFrameRec.h" #include "WoW/Source/Object/ObjectClient/Bag_C.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" // VERIFY: c886e670 auto // OFFSET: 0x005E9BC0 @@ -209,6 +210,36 @@ static int32_t Script_IsInventoryItemLocked(lua_State* L) { return 1; } +// VERIFY: 2fff9517 manual +// OFFSET: 0x005E7E60 +static int32_t Script_GetInventoryItemCooldown(lua_State* L) { + const char* unitName; + int32_t slot = 0; + + if (!GetUnitAndSlotFromLua(L, unitName, slot)) { + return 0; + } + + CGPlayer_C* unit; + CGItem_C* item; + + if (slot != -1 && CGCharacterInfo::CanInspect(unit = static_cast(GetUnitFromName(unitName))) && (item = unit->m_bag.GetItemPointer(slot)) && item->GetEnchantmentSpell(0) && (!item->GetUsableSpellCharges() || item->GetCurrentSpellCharges())) { + uint32_t start = 0; + uint32_t duration = 0; + uint32_t enable = 0; + Spell_C_GetItemCooldown(item, &duration, &start, &enable); + lua_pushnumber(L, start * 0.001); + lua_pushnumber(L, duration * 0.001); + lua_pushnumber(L, enable); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + } + + return 3; +} + // STATIC: 0x00AD1270 static FrameScript_Method s_ScriptFunctions[] = { { "GetInventorySlotInfo", &Script_GetInventorySlotInfo }, diff --git a/WoW/Source/Ui/PartyFrame.cpp b/WoW/Source/Ui/PartyFrame.cpp index 61f49fa..2c50d06 100644 --- a/WoW/Source/Ui/PartyFrame.cpp +++ b/WoW/Source/Ui/PartyFrame.cpp @@ -337,3 +337,49 @@ int32_t CGPartyInfo::IsPlayerOrPetInParty(const WOWGUID& guid) { return 0; } + +// VERIFY: a81ee60b manual +// OFFSET: 0x0052D310 +int32_t CGPartyInfo::IsMemberOrPet(const WOWGUID& guid) { + if (!guid) { + return 0; + } + + if (guid == ClntObjMgrGetActivePlayer()) { + return 1; + } + + CGUnit_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + const WOWGUID& pet = player->m_unit->m_unitFieldCharm ? player->m_unit->m_unitFieldCharm : player->m_unit->m_unitFieldSummon; + + if (pet == guid) { + return 1; + } + } + + for (uint32_t i = 0; i < 4; i++) { + if (!CGPartyInfo::m_members[i]) { + continue; + } + + if (CGPartyInfo::m_members[i] == guid) { + return 1; + } + + CGUnit_C* member = static_cast(ClntObjMgrObjectPtr(CGPartyInfo::m_members[i], TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (member) { + const WOWGUID& pet = member->m_unit->m_unitFieldCharm ? member->m_unit->m_unitFieldCharm : member->m_unit->m_unitFieldSummon; + + if (pet == guid) { + return 1; + } + } else if ((unk_BD0D08[i].m_flags & 1) && unk_BD0D08[i].m_pet.m_guid == guid) { + return 1; + } + } + + return 0; +} diff --git a/WoW/Source/Ui/PartyFrame.h b/WoW/Source/Ui/PartyFrame.h index 530a42f..bcb1c5b 100644 --- a/WoW/Source/Ui/PartyFrame.h +++ b/WoW/Source/Ui/PartyFrame.h @@ -20,7 +20,8 @@ class CGPartyPetState { /* 0060 */ uint32_t m_maxHealth; /* 0064 */ uint16_t m_power; /* 0066 */ uint16_t m_maxPower; - /* 0068 */ uint8_t unk_0068[320]; + /* 0068 */ int32_t m_auras[64]; + /* 0168 */ uint8_t m_auraFlags[64]; }; class CGPartyMemberState { @@ -37,7 +38,8 @@ class CGPartyMemberState { /* 001A */ uint16_t m_zoneID; /* 001C */ int16_t m_posX; /* 001E */ int16_t m_posY; - /* 0020 */ uint8_t unk_0020[320]; + /* 0020 */ int32_t m_auras[64]; + /* 0120 */ uint8_t m_auraFlags[64]; /* 0160 */ CGPartyPetState m_pet; /* 0308 */ uint32_t unk_0308[2]; }; @@ -52,6 +54,7 @@ class CGPartyInfo { static uint8_t m_playerRole; static void InitializeGame(); static void CheckClearLFGSlot(); + static int32_t IsMemberOrPet(const WOWGUID& guid); static void RegisterScriptFunctions(); static WOWGUID m_members[4]; static uint32_t m_dungeonDifficulty; diff --git a/WoW/Source/Ui/PetInfo.cpp b/WoW/Source/Ui/PetInfo.cpp index b5adc7e..951e1ab 100644 --- a/WoW/Source/Ui/PetInfo.cpp +++ b/WoW/Source/Ui/PetInfo.cpp @@ -8,6 +8,19 @@ #include "WoW/Source/Net/Types.h" #include "WoW/Source/Ui/Types.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Ui/SpellBookFrame.h" +#include "WoW/Source/Ui/ClassTrainerFrame.h" +#include "WoW/Source/DB/Rec/SummonPropertiesRec.h" +#include "WoW/Source/Object/ObjectClient/AuraData.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "WoW/Source/Ui/TalentInfo.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Object/ObjectClient/Vehicle_C.h" +#include "WoW/Source/DB/Rec/VehicleSeatRec.h" +#include "Engine/Source/Os/TimeManager.h" // STATIC: 0x00C234DC int32_t CGPetInfo::m_attackingTarget; @@ -45,6 +58,9 @@ WOWGUID CGPetInfo::m_pet; // STATIC: 0x00C234D8 uint32_t CGPetInfo::m_petBarState; +// STATIC: 0x00C23530 +static TSGrowableArray s_petSpellActions; + // VERIFY: 0f361a6f auto // OFFSET: 0x005D3080 void CGPetInfo::HideGrid() { @@ -206,3 +222,559 @@ uint32_t* CGPetInfo::FindSpellByID(int32_t spellId) { return nullptr; } + +// VERIFY: 16cfdcd2 auto +// OFFSET: 0x005D30E0 +void CGPetInfo::SetPossessedSpell(int32_t spellId) { + int32_t previous = CGPetInfo::m_possessSpell; + CGPetInfo::m_possessSpell = spellId; + + if (spellId) { + CGPetInfo::m_petBarState = 1; + } + + if (previous != spellId) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_BONUS_ACTIONBAR, nullptr); + } +} + +// VERIFY: 0082bae7 manual +// OFFSET: 0x005D3410 +uint32_t* CGPetInfo::GetPetSpellAction(int32_t spellId) { + for (uint32_t i = s_petSpellActions.m_count; i; ) { + i--; + + if ((s_petSpellActions.m_data[i] & 0xFFFFFF) == static_cast(spellId)) { + return &s_petSpellActions.m_data[i]; + } + } + + return nullptr; +} + +// VERIFY: b235dc3e manual +// OFFSET: 0x005D3450 +void CGPetInfo::UpdatePetSpellAction(const uint32_t* action) { + uint32_t value = *action; + + if ((value & 0x3F000000) != 0x1000000) { + return; + } + + for (uint32_t i = s_petSpellActions.m_count; i; ) { + i--; + + if ((s_petSpellActions.m_data[i] & 0x3FFFFFFF) == (value & 0x3FFFFFFF)) { + s_petSpellActions.m_data[i] = value; + return; + } + } +} + +// VERIFY: 9c92f690 manual +// OFFSET: 0x005D5E10 +void CGPetInfo::SetSpellAutocast(int32_t spellId, int32_t enable) { + if (!CGGameUI::CanPerformAction(2) || !CGPetInfo::PetActionsUsable(false)) { + return; + } + + uint32_t* action = CGPetInfo::GetPetSpellAction(spellId); + + if (!action || !(*action & 0x80000000)) { + return; + } + + if (enable < 0) { + enable = !(*action & 0x40000000); + } + + if (enable) { + *action |= 0x40000000; + } else { + *action &= ~0x40000000; + } + + for (uint32_t i = 0; i < 10; i++) { + if (!((*action ^ CGPetInfo::m_actions[i]) & 0x3FFFFFFF)) { + if (*action & 0x40000000) { + CGPetInfo::m_actions[i] |= 0x40000000; + } else { + CGPetInfo::m_actions[i] &= ~0x40000000; + } + } + } + + CDataStore msg; + msg.Put(static_cast(CMSG_PET_SPELL_AUTOCAST)); + msg.Put(CGPetInfo::GetPet(0).m_guid); + msg.Put(static_cast(spellId)); + msg.Put(static_cast((*action & 0x40000000) != 0)); + msg.Finalize(); + ClientServices::Send2(&msg); + + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE, nullptr); +} + +// VERIFY: c40a54ec auto +// OFFSET: 0x005D2FF0 +void CGPetInfo::SetPetMode(uint32_t mode) { + CGPetInfo::m_petMode = mode | (CGPetInfo::m_petMode & 0xFFFFFF00); + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE, nullptr); +} + +// VERIFY: a72652ae auto +// OFFSET: 0x005D3020 +void CGPetInfo::SetPetOrders(uint32_t orders) { + CGPetInfo::m_petMode = (orders << 8) | (CGPetInfo::m_petMode & 0x80000FF); + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE, nullptr); +} + +// VERIFY: d8b1283c manual +// OFFSET: 0x005D3E80 +bool CGPetInfo::PetActionsUsable(bool ignoreControl) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || player->m_unit->m_unitFieldCharmedby.m_guid) { + return false; + } + + if (player->GetFarSightGuid() && player->GetFarSightGuid() != CGPetInfo::GetPet(0).m_guid) { + return false; + } + + for (uint32_t i = 0; i < s_pets.m_count; i++) { + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(i), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!pet) { + continue; + } + + const WOWGUID& owner = pet->m_unit->m_unitFieldCharmedby.m_guid ? pet->m_unit->m_unitFieldCharmedby : pet->m_unit->m_unitFieldSummonedby; + + if (owner == ClntObjMgrGetActivePlayer() && (ignoreControl || pet->IsControllable())) { + if (!(CGPetInfo::m_petMode & 0x8000000)) { + return true; + } + + if (player->GetTransportGUID() == pet->m_obj->m_guid.m_guid) { + return true; + } + } + } + + return false; +} + +// VERIFY: db3a399f manual +// OFFSET: 0x005D4210 +void CGPetInfo::SendPetAction(const uint32_t& action, const WOWGUID& target, int32_t a3) { + if (!CGGameUI::CanPerformAction(2)) { + return; + } + + WOWGUID actionTarget = (a3 || target.m_guid) ? target : CGGameUI::m_lockedTarget; + + switch ((action >> 24) & 0x3F) { + case 1: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: { + if (!CGPetInfo::PetActionsUsable(true)) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(action & 0xFFFFFF, &spell)) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (Spell_C_IsActiveSpell(&spell, pet)) { + if (!Spell_C_WasSpellRecentlyUsed(spell.m_id, 1)) { + Spell_C_CancelAura(&spell, pet, -1); + } + + return; + } + + uint32_t pacified = 0; + uint32_t silenced = 0; + uint32_t disarmed = 0; + + if (s_pets.m_count) { + for (uint32_t i = 0; i < s_pets.m_count; i++) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(i), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return; + } + + if (!(spell.m_attributesExE & 0x8) && (unit->m_unit->m_unitFieldFlags & 0x40000)) { + pacified++; + } else if (!(spell.m_attributesExE & 0x20000) && (unit->m_unit->m_unitFieldFlags & 0x800000)) { + silenced++; + } else if (!(spell.m_attributesExE & 0x40000) && (unit->m_unit->m_unitFieldFlags & 0x400000)) { + disarmed++; + } + } + + if ((pacified && pacified == s_pets.m_count) || (silenced && silenced == s_pets.m_count) || (disarmed && disarmed == s_pets.m_count)) { + return; + } + } + + if (!(spell.m_attributesExD & 0x20) && player->GetPossessedUnit() != pet) { + Spell_C_StartSpellCooldown(&spell, pet); + break; + } + + Spell_C_CastSpell(pet, spell.m_id, nullptr, actionTarget, nullptr, false); + return; + } + + case 6: + if (!CGPetInfo::PetActionsUsable(false)) { + return; + } + + CGPetInfo::SetPetMode(action & 0xFFFFFF); + break; + + case 7: { + if (!CGPetInfo::PetActionsUsable(false)) { + return; + } + + int32_t orders = action & 0xFFFFFF; + + if (orders <= 1) { + CGPetInfo::SetPetOrders(orders); + break; + } + + if (orders != 2) { + break; + } + + for (uint32_t i = 0; i < s_pets.m_count; i++) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(i), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit && unit->VerifyAttackIconPressed(&actionTarget, a3, 1, 1, false)) { + CGPetInfo::m_attackingTarget = 1; + } + } + + if (!CGPetInfo::m_attackingTarget) { + return; + } + + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE, nullptr); + break; + } + + default: + if (!CGPetInfo::PetActionsUsable(false)) { + return; + } + + break; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_PET_ACTION)); + msg.Put(CGPetInfo::GetPet(0).m_guid); + msg.Put(action); + msg.Put(actionTarget.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 4d63ce45 manual +// OFFSET: 0x005D62A0 +void CGPetInfo::FindPossessedSpell() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + int32_t onCharmVehicle = 0; + + if (player->GetTransportGUID()) { + const WOWGUID& charm = player->m_unit->m_unitFieldCharm.m_guid ? player->m_unit->m_unitFieldCharm : player->m_unit->m_unitFieldSummon; + + if (player->GetTransportGUID() == charm.m_guid) { + onCharmVehicle = 1; + } + } + + SpellRec spell; + + for (uint32_t i = 0; i < player->GetAuraCount(); i++) { + AuraData* aura = i < player->GetAuraCount() ? &player->m_auras[i] : nullptr; + + if ((aura->m_flags & 0x80) || !g_spellDB.GetRecord(aura->m_spellId, &spell)) { + continue; + } + + for (uint32_t j = 0; j < 3; j++) { + int32_t auraType = spell.m_effectAura[j]; + + if (auraType == 2 || auraType == 128 || auraType == 6 || (auraType == 236 && onCharmVehicle)) { + CGPetInfo::SetPossessedSpell(aura->m_spellId); + return; + } + } + + for (uint32_t j = 0; j < 3; j++) { + if (spell.m_effect[j] != 28) { + continue; + } + + SummonPropertiesRec* properties = g_summonPropertiesDB.GetRecord(spell.m_effectMiscValueB[j]); + + if (properties && properties->m_control == 3) { + CGPetInfo::SetPossessedSpell(aura->m_spellId); + return; + } + } + } +} + +// VERIFY: 81b39234 manual +// OFFSET: 0x005D6B90 +int32_t Packet_SMSG_PET_SPELLS(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + for (uint32_t i = 0; i < 10; i++) { + CGPetInfo::m_actions[i] = 0; + } + + s_petSpellActions.SetCount(0); + Spell_C_ClearPetCooldowns(); + + uint32_t expiration = 0; + uint16_t family = 0; + uint64_t pet; + msg->Get(pet); + + if (pet) { + msg->Get(family); + msg->Get(expiration); + uint32_t mode; + msg->Get(mode); + CGPetInfo::m_petMode = mode; + + for (uint32_t i = 0; i < 10; i++) { + uint32_t action; + msg->Get(action); + uint32_t value = action; + CGPetInfo::SetAction(i, value, 0); + + if (((action >> 24) & 0x3F) >= 8 && ((action >> 24) & 0x3F) <= 17) { + CGSpellBook::AddSpellToNameCache(action & 0xFFFFFF, 1); + } + } + + uint8_t count; + msg->Get(count); + s_petSpellActions.SetCount(count); + ClearPetSpellInfo(); + + for (uint32_t i = 0; i < count; i++) { + uint32_t action; + msg->Get(action); + s_petSpellActions.m_data[i] = action; + CGSpellBook::AddPetSpell(action & 0xFFFFFF); + } + + msg->Get(count); + + for (uint32_t i = 0; i < count; i++) { + uint32_t spellId; + msg->Get(spellId); + uint16_t category; + msg->Get(category); + uint32_t cooldown; + msg->Get(cooldown); + uint32_t categoryCooldown; + msg->Get(categoryCooldown); + bool onHold = static_cast(categoryCooldown) < 0; + categoryCooldown &= ~0x80000000; + Spell_C_SetCooldownLeft(spellId, 0, category, cooldown, categoryCooldown, onHold, 1); + } + } else { + ClearPetSpellInfo(); + } + + CGPetInfo::SetPet(WOWGUID{ pet }, expiration, family); + CGSpellBook::UpdateSpells(0, 1, 0); + CGClassTrainer::RefreshList(); + return 1; +} + +// VERIFY: 2c74fc11 manual +// OFFSET: 0x005D3240 +static int32_t PetTempActionBarCallback(uint32_t index, const void* data) { + return index < 10 ? index | 0x10000000 : 0; +} + +// VERIFY: adc6dd8d auto +// OFFSET: 0x005D34B0 +void CGPetInfo::SetComboPoints(WOWGUID target, uint8_t points) { + CGPetInfo::m_comboTarget = target; + CGPetInfo::m_comboPoints = points; + CGSpellBook::UpdateUsable(); + Script_SendUnitSignal(CGPetInfo::GetPet(0), 149); + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE_USABLE, nullptr); +} + +// VERIFY: 1003d217 manual +// OFFSET: 0x005D4AD0 +void CGPetInfo::UpdatePetTempBar() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + int32_t active = 0; + + if (player && player->m_obj->m_guid == ClntObjMgrGetActivePlayer() && player->m_player->m_playerFarsight.m_guid && player->GetFarSightGuid() == CGPetInfo::GetPet(0).m_guid && CGPetInfo::IsPetBarUsed()) { + active = 1; + CVehicle_C* vehicle; + VehicleSeatRec* seat; + + if (!s_pets.m_count || !s_pets.m_data[0].m_guid || player->GetTransportGUID() != s_pets.m_data[0].m_guid || !(vehicle = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__))->m_vehicle) || !(seat = vehicle->GetVehicleSeatRec(static_cast(player->m_movementData.m_transportSeat))) || (active = seat->m_vehicleAbilityDisplay == 1) != 0) { + CGActionBar::UpdateTemporaryActionBar(PetTempActionBarCallback, nullptr); + } + } + + CGActionBar::SetTemporaryActionBarFlags(1, active); + CGActionBar::UpdateBonusBar(); + FrameScript_SignalEvent(SCRIPT_EVENT_PET_BAR_UPDATE, nullptr); +} + +// VERIFY: 138ffa1d manual +// OFFSET: 0x005D6900 +void CGPetInfo::SetPet(WOWGUID pet, uint32_t expiration, int32_t family) { + int32_t changed = CGPetInfo::m_pet != pet; + CGPetInfo::m_pet = pet; + + if (pet) { + uint32_t index = 0; + + if (s_pets.m_count) { + for (index = 0; index < s_pets.m_count; index++) { + if (s_pets.m_data[index] == pet) { + break; + } + } + + if (index) { + WOWGUID first = s_pets.m_data[0]; + s_pets.m_data[0] = pet; + + if (index < s_pets.m_count) { + s_pets.m_data[index] = first; + } + } + } + + if (index == s_pets.m_count) { + CGPetInfo::SetPetCount(1); + + if (s_pets.m_count) { + s_pets.m_data[0] = pet; + } + } + } else { + CGPetInfo::SetPetCount(0); + } + + CGPetInfo::m_expirationTime = expiration ? expiration + OsGetAsyncTimeMs() : 0; + + if (changed) { + CGPetInfo::m_petBarState = 0; + CGPetInfo::m_attackingTarget = 0; + + if (s_pets.m_count && s_pets.m_data[0]) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(s_pets.m_data[0], TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + CGPetInfo::m_attackingTarget = unit->IsInCombat() != 0; + + if (unit->CanGainXP()) { + FrameScript_SignalEvent(SCRIPT_EVENT_PET_UI_CLOSE, nullptr); + } + } + + CGTalentInfo::UpdatePetTabInfo(family); + } else { + CGPetInfo::SetComboPoints(WOWGUID(), 0); + CGTalentInfo::UpdatePetTabInfo(0); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_UNIT_PET_2, "%s", "player"); + } + + CGPetInfo::UpdatePetTempBar(); + + if (Spell_C_IsModal(CGPetInfo::GetPet(0)) && (changed || !s_pets.m_count || !s_pets.m_data[0])) { + Spell_C_CancelSpellByCaster(pet); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && changed && player->m_unit->m_unitFieldHealth <= 0) { + if (s_pets.m_count && s_pets.m_data[0]) { + FrameScript_SignalEvent(SCRIPT_EVENT_RAISED_AS_GHOUL, nullptr); + } else { + CGGameUI::UpdateActivePlayer(); + } + } +} + +// VERIFY: bb0a37d3 auto +// OFFSET: 0x005D4620 +void CGPetInfo::PetAttackTarget(const WOWGUID& target, int32_t a2) { + uint32_t action = 0x7000002; + CGPetInfo::SendPetAction(action, target, a2); +} + +// VERIFY: a7d77109 manual +// OFFSET: 0x005D36A0 +int32_t Packet_SMSG_PET_UPDATE_COMBO_POINTS(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + SmartGUID pet; + SmartGUID target; + uint8_t points; + *msg >> pet; + *msg >> target; + msg->Get(points); + + if (pet == CGPetInfo::GetPet(0)) { + CGPetInfo::SetComboPoints(target, points); + } + + return 1; +} + +// VERIFY: 8d48f08a manual +// OFFSET: 0x005D30A0 +void CGPetInfo::SetIsAttackingTarget(int32_t attacking) { + if (attacking) { + FrameScript_SignalEvent(SCRIPT_EVENT_PET_ATTACK_START, nullptr); + CGPetInfo::m_attackingTarget = attacking; + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_PET_ATTACK_STOP, nullptr); + CGPetInfo::m_attackingTarget = 0; + } +} diff --git a/WoW/Source/Ui/PetInfo.h b/WoW/Source/Ui/PetInfo.h index 393a606..861f9ca 100644 --- a/WoW/Source/Ui/PetInfo.h +++ b/WoW/Source/Ui/PetInfo.h @@ -25,6 +25,7 @@ class CGPetInfo { static int32_t m_possessSpell; static WOWGUID m_comboTarget; static void PetClearTarget(); + static void PetDismiss(); static void PetAttackTarget(const WOWGUID& target, int32_t a2); static int32_t m_attackingTarget; static uint32_t m_actions[10]; @@ -35,8 +36,18 @@ class CGPetInfo { static void SetPetCount(uint32_t count); static int32_t IsAttackAction(uint32_t index); static uint32_t GetPetMode(); - static void SetPet(WOWGUID pet, uint32_t a2, int32_t a3); + static void SetPet(WOWGUID pet, uint32_t expiration, int32_t family); + static void SetComboPoints(WOWGUID target, uint8_t points); + static void SetIsAttackingTarget(int32_t attacking); + static void UpdatePetTempBar(); static void SendPetAction(const uint32_t& action, const WOWGUID& target, int32_t a3); + static uint32_t* GetPetSpellAction(int32_t spellId); + static void UpdatePetSpellAction(const uint32_t* action); + static void SetPossessedSpell(int32_t spellId); + static void SetAction(uint32_t index, const uint32_t& action, int32_t a3); + static void SetSpellAutocast(int32_t spellId, int32_t enable); + static void SetPetMode(uint32_t mode); + static void SetPetOrders(uint32_t orders); static const char* GetModeToken(uint32_t mode); static const char* GetOrdersToken(uint32_t order); }; diff --git a/WoW/Source/Ui/PetitionInfo.cpp b/WoW/Source/Ui/PetitionInfo.cpp index 621496e..1a43787 100644 --- a/WoW/Source/Ui/PetitionInfo.cpp +++ b/WoW/Source/Ui/PetitionInfo.cpp @@ -4,9 +4,21 @@ // STATIC: 0x00C22B20 WOWGUID CGPetitionInfo::m_petitionGUID; +// STATIC: 0x00C22B28 +WOWGUID CGPetitionInfo::m_petitionItem; + +// STATIC: 0x00C22B30 +uint32_t CGPetitionInfo::unk_C22B30; + // STATIC: 0x00C22B34 int32_t CGPetitionInfo::m_signed; +// STATIC: 0x00C22B38 +uint32_t CGPetitionInfo::m_numPetitionNames; + +// STATIC: 0x00C22B3C +int32_t CGPetitionInfo::m_pendingNameQueries; + // STATIC: 0x00C22B40 CGPetition* CGPetitionInfo::m_petition; @@ -18,3 +30,15 @@ TSGrowableArray CGPetitionInfo::m_signers; void CGPetitionInfo::InitializeGame() { ClientServices::SetMessageHandler(SMSG_OFFER_PETITION_ERROR, Packet_SMSG_OFFER_PETITION_ERROR, nullptr); } + +// VERIFY: 5e76943f manual +// OFFSET: 0x005CF580 +void CGPetitionInfo::EnterWorld() { + CGPetitionInfo::m_petitionGUID = WOWGUID{ 0 }; + CGPetitionInfo::m_petitionItem = WOWGUID{ 0 }; + CGPetitionInfo::unk_C22B30 = 0; + CGPetitionInfo::m_numPetitionNames = 0; + CGPetitionInfo::m_pendingNameQueries = 0; + CGPetitionInfo::m_petition = nullptr; + CGPetitionInfo::m_signers.SetCount(10); +} diff --git a/WoW/Source/Ui/PetitionInfo.h b/WoW/Source/Ui/PetitionInfo.h index 283c6a0..c7706e6 100644 --- a/WoW/Source/Ui/PetitionInfo.h +++ b/WoW/Source/Ui/PetitionInfo.h @@ -18,9 +18,14 @@ struct PetitionSignerInfo { class CGPetitionInfo { public: static WOWGUID m_petitionGUID; + static WOWGUID m_petitionItem; + static uint32_t unk_C22B30; static int32_t m_signed; + static uint32_t m_numPetitionNames; + static int32_t m_pendingNameQueries; static CGPetition* m_petition; static TSGrowableArray m_signers; + static void EnterWorld(); static void InitializeGame(); }; diff --git a/WoW/Source/Ui/PetitionInfo_Scripts.cpp b/WoW/Source/Ui/PetitionInfo_Scripts.cpp index 95daf24..88b8c8e 100644 --- a/WoW/Source/Ui/PetitionInfo_Scripts.cpp +++ b/WoW/Source/Ui/PetitionInfo_Scripts.cpp @@ -8,13 +8,10 @@ #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" -// STATIC: 0x00C22B38 -static uint32_t s_numPetitionNames; - -// VERIFY: d50f1520 manual +// VERIFY: b24a9953 manual // OFFSET: 0x005CEAC0 static int32_t Script_GetNumPetitionNames(lua_State* L) { - lua_pushnumber(L, s_numPetitionNames); + lua_pushnumber(L, CGPetitionInfo::m_numPetitionNames); return 1; } @@ -42,7 +39,7 @@ static int32_t Script_SignPetition(lua_State* L) { return 0; } -// VERIFY: 05f0a836 manual +// VERIFY: 5cff31d5 manual // OFFSET: 0x005CF040 static int32_t Script_CanSignPetition(lua_State* L) { CGPetition* petition = CGPetitionInfo::m_petition; @@ -52,7 +49,7 @@ static int32_t Script_CanSignPetition(lua_State* L) { if (petition->m_staticType == 0 || petition->m_staticType == 1) { CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); - if ((!petition->m_staticType && player && player->m_player->m_playerGuildid) || static_cast(s_numPetitionNames) >= static_cast(petition->m_maxSignatures)) { + if ((!petition->m_staticType && player && player->m_player->m_playerGuildid) || static_cast(CGPetitionInfo::m_numPetitionNames) >= static_cast(petition->m_maxSignatures)) { canSign = 0; } } @@ -63,8 +60,8 @@ static int32_t Script_CanSignPetition(lua_State* L) { } } - for (uint32_t i = 0; i < s_numPetitionNames; i++) { - PetitionSignerInfo* signer = i < s_numPetitionNames ? &CGPetitionInfo::m_signers.m_data[i] : nullptr; + for (uint32_t i = 0; i < CGPetitionInfo::m_numPetitionNames; i++) { + PetitionSignerInfo* signer = i < CGPetitionInfo::m_numPetitionNames ? &CGPetitionInfo::m_signers.m_data[i] : nullptr; if (signer && signer->m_guid == ClntObjMgrGetActivePlayer()) { lua_pushnil(L); diff --git a/WoW/Source/Ui/PetitionVendor.cpp b/WoW/Source/Ui/PetitionVendor.cpp index 394b2f2..ccc464f 100644 --- a/WoW/Source/Ui/PetitionVendor.cpp +++ b/WoW/Source/Ui/PetitionVendor.cpp @@ -5,6 +5,9 @@ // STATIC: 0x00C0F7C8 WOWGUID CGPetitionVendorInfo::m_vendor; +// STATIC: 0x00C0F7D0 +uint32_t CGPetitionVendorInfo::m_numPetitionItems; + // STATIC: 0x00C0F7D8 WOWGUID CGPetitionVendorInfo::m_petitionItem; @@ -20,3 +23,10 @@ void PetitionVendorClose() { CGPetitionVendorInfo::m_vendor = WOWGUID(); FrameScript_SignalEvent(SCRIPT_EVENT_PETITION_VENDOR_CLOSED, nullptr); } + +// VERIFY: 670e5b68 auto +// OFFSET: 0x005A1F50 +void CGPetitionVendorInfo::EnterWorld() { + CGPetitionVendorInfo::m_numPetitionItems = 0; + CGPetitionVendorInfo::m_petitionItem = WOWGUID{ 0 }; +} diff --git a/WoW/Source/Ui/PetitionVendor.h b/WoW/Source/Ui/PetitionVendor.h index 7bd0741..c3d7d6f 100644 --- a/WoW/Source/Ui/PetitionVendor.h +++ b/WoW/Source/Ui/PetitionVendor.h @@ -18,7 +18,9 @@ void PetitionVendorClose(); class CGPetitionVendorInfo { public: static WOWGUID m_vendor; + static uint32_t m_numPetitionItems; static WOWGUID m_petitionItem; + static void EnterWorld(); }; diff --git a/WoW/Source/Ui/PetitionVendor_Scripts.cpp b/WoW/Source/Ui/PetitionVendor_Scripts.cpp index 939075f..49be18c 100644 --- a/WoW/Source/Ui/PetitionVendor_Scripts.cpp +++ b/WoW/Source/Ui/PetitionVendor_Scripts.cpp @@ -6,13 +6,10 @@ #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/Net/Types.h" -// STATIC: 0x00C0F7D0 -static uint32_t s_numPetitionItems; - -// VERIFY: 7b8583d7 manual +// VERIFY: f68ff2aa manual // OFFSET: 0x005A1F70 static int32_t Script_GetNumPetitionItems(lua_State* L) { - lua_pushnumber(L, s_numPetitionItems); + lua_pushnumber(L, CGPetitionVendorInfo::m_numPetitionItems); return 1; } diff --git a/WoW/Source/Ui/QuestFrame.cpp b/WoW/Source/Ui/QuestFrame.cpp index 2bf10a0..a397811 100644 --- a/WoW/Source/Ui/QuestFrame.cpp +++ b/WoW/Source/Ui/QuestFrame.cpp @@ -883,3 +883,19 @@ int32_t CGQuestInfo::QuestItemInfo(const char* type, uint32_t index, char* name, return 1; } + +// VERIFY: 1981b73a auto +// OFFSET: 0x0058B940 +void CGQuestInfo::EnterWorld() { + CGQuestInfo::m_npc = WOWGUID{ 0 }; + CGQuestInfo::m_npcInform = WOWGUID{ 0 }; + CGQuestInfo::m_state = 0; + CGQuestInfo::m_currentQuest = 0; + CGQuestInfo::m_canComplete = 0; + CGQuestInfo::m_autoLaunched = 0; + CGQuestInfo::m_requiredMoney = 0; + CGQuestInfo::m_lastChosenItem = 0; + CGQuestInfo::m_questFlags = 0; + CGQuestInfo::ClearState(); + CGQuestInfo::ClearQuestItems(); +} diff --git a/WoW/Source/Ui/QuestLog.cpp b/WoW/Source/Ui/QuestLog.cpp index d45ddcd..3194523 100644 --- a/WoW/Source/Ui/QuestLog.cpp +++ b/WoW/Source/Ui/QuestLog.cpp @@ -181,6 +181,26 @@ int32_t CGQuestLog::GetSelectedLogEntry() { return index; } +// VERIFY: 17b653c2 auto +// OFFSET: 0x005DFF40 +void CGQuestLog::SetServerTime(int32_t serverTime, int32_t resetTime) { + int32_t now = static_cast(time(nullptr)); + CGQuestLog::m_timeOffset = now - serverTime; + + if (now == serverTime) { + CGQuestLog::m_timeOffset = 1; + } + + CGQuestLog::m_questResetTime = now + resetTime; + CGQuestLog::m_nextQuestUpdate = now + 3600; + + if (now + 3600 >= now + resetTime) { + CGQuestLog::m_nextQuestUpdate = now + resetTime; + } + + Script_SendUniqueSignal(SCRIPT_EVENT_QUEST_LOG_UPDATE); +} + // VERIFY: 98372535 manual // OFFSET: 0x005DFFA0 void CGQuestLog::SetSelectedQuest(int32_t index) { @@ -733,6 +753,17 @@ int32_t CGQuestLog::IsSelectedQuestExpired() { return index < static_cast(CGQuestLog::m_numQuest) && !CGQuestLog::m_quests[index].m_isHeader && CGQuestLog::m_quests[index].m_expired; } +// VERIFY: e7d44bdf auto +// OFFSET: 0x005E08A0 +int32_t Packet_SMSG_QUERY_TIME_RESPONSE(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { + uint32_t serverTime = 0; + uint32_t resetTime; + msg->Get(serverTime); + msg->Get(resetTime); + CGQuestLog::SetServerTime(serverTime, resetTime); + return 1; +} + // VERIFY: f903a683 manual // OFFSET: 0x005E08F0 static int32_t QSortQuestLogEntries(const void* a, const void* b) { @@ -1726,3 +1757,67 @@ int32_t CGQuestLog::IsQuestExpiredByID(int32_t questId) { return 0; } + +// VERIFY: f75725e2 auto +// OFFSET: 0x005DFEF0 +void CGQuestLog::UpdateWatchTimers() { + for (uint32_t i = 0; i < CGQuestLog::m_numQuestWatches; i++) { + if (CGQuestLog::m_questWatches[i].m_expireTime > 0 && static_cast(time(nullptr)) >= CGQuestLog::m_questWatches[i].m_expireTime) { + CGQuestLog::RemoveQuestWatch(CGQuestLog::m_questWatches[i].m_questId); + Script_SendUniqueSignal(SCRIPT_EVENT_QUEST_LOG_UPDATE); + } + } +} + +// VERIFY: 993444bb manual +// OFFSET: 0x005E1250 +void CGQuestLog::UpdateQuestItem(int32_t itemId) { + for (int32_t i = 0; i < CGQuestLog::m_numQuest; i++) { + WOWGUID none = WOWGUID(); + QuestCache* quest = g_questDBCache.GetRecord(CGQuestLog::m_quests[i].m_questId, none, nullptr, nullptr, false); + + if (!quest) { + continue; + } + + for (uint32_t j = 0; j < 6; j++) { + if (static_cast(quest->m_collectItemId[j]) == itemId) { + Script_SendUniqueSignal(SCRIPT_EVENT_QUEST_LOG_UPDATE); + + if (ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)) { + CGPlayer_C::QueryQuestGiverStatusMultiple(); + } + + return; + } + } + } +} + +// VERIFY: 4d319090 manual +// OFFSET: 0x005E5840 +int32_t CGQuestLog::SetQuestExpiredByID(int32_t questId) { + uint32_t index = 0; + + if (!CGQuestLog::m_numQuest) { + return 0; + } + + while (CGQuestLog::m_quests[index].m_questId != questId) { + if (++index >= static_cast(CGQuestLog::m_numQuest)) { + return 0; + } + } + + if (index >= static_cast(CGQuestLog::m_numQuest) || CGQuestLog::IsQuestCompleteEx(index, 1)) { + return 0; + } + + CGQuestLog::m_quests[index].m_expired = 1; + + if (ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)) { + CGPlayer_C::QueryQuestGiverStatusMultiple(); + } + + return 1; +} diff --git a/WoW/Source/Ui/QuestLog.h b/WoW/Source/Ui/QuestLog.h index 43403a9..a8f4212 100644 --- a/WoW/Source/Ui/QuestLog.h +++ b/WoW/Source/Ui/QuestLog.h @@ -110,6 +110,7 @@ class CGQuestLog { static int32_t m_nextQuestUpdate; static int32_t GetSelectedLogEntry(); static void SetSelectedQuest(int32_t index); + static void SetServerTime(int32_t serverTime, int32_t resetTime); static int32_t SetQuestExpired(uint32_t index); static void UpdateQuestPOIFromUserServer(); static QuestWatch m_questWatches[25]; @@ -127,6 +128,7 @@ class CGQuestLog { static int32_t GetQuestAt(int32_t index); static int32_t GetQuestLeaderBoardForItem(int32_t questId, int32_t itemId, QuestLogLeaderBoardParams* params); static int32_t IsQuestCompleteEx(uint32_t index, int32_t a2); + static int32_t SetQuestExpiredByID(int32_t questId); static void UpdateWatchTimers(); static void UpdateQuestItem(int32_t itemId); static void HandlePOIQueryResponse(CDataStore* msg); diff --git a/WoW/Source/Ui/RaidInfo.cpp b/WoW/Source/Ui/RaidInfo.cpp index ecf8b16..fe727f7 100644 --- a/WoW/Source/Ui/RaidInfo.cpp +++ b/WoW/Source/Ui/RaidInfo.cpp @@ -39,6 +39,12 @@ WOWGUID CGRaidInfo::m_readyCheckInitiator; // STATIC: 0x00BEB628 uint32_t CGRaidInfo::m_readyCheckTimer; +// STATIC: 0x00BD0CE0 +int32_t CGRaidInfo::m_partyReadyCheckReady[4]; + +// STATIC: 0x00BD0CF0 +int32_t CGRaidInfo::m_partyReadyCheckPending[4]; + // STATIC: 0x00ACE788 uint8_t CGRaidInfo::m_rosterCounter = 0xFF; @@ -282,3 +288,27 @@ int32_t CGRaidInfo::IsPlayerOrPetInRaid(const WOWGUID& guid) { return 0; } + +// VERIFY: 2ceb7b94 manual +// OFFSET: 0x005723E0 +int32_t CGRaidInfo::GetPartyMemberIndex(WOWGUID guid) { + for (int32_t i = 0; i < 4; i++) { + if (CGPartyInfo::m_members[i] == guid) { + return i; + } + } + + return -1; +} + +// VERIFY: 7ec85a21 manual +// OFFSET: 0x00572450 +int32_t CGRaidInfo::IsPartyMemberReadyCheckPending(uint32_t index) { + return index < 4 ? CGRaidInfo::m_partyReadyCheckPending[index] : 0; +} + +// VERIFY: 1c65956c manual +// OFFSET: 0x00572470 +int32_t CGRaidInfo::IsPartyMemberReadyCheckReady(uint32_t index) { + return index < 4 ? CGRaidInfo::m_partyReadyCheckReady[index] : 0; +} diff --git a/WoW/Source/Ui/RaidInfo.h b/WoW/Source/Ui/RaidInfo.h index 2e715b7..bc2158c 100644 --- a/WoW/Source/Ui/RaidInfo.h +++ b/WoW/Source/Ui/RaidInfo.h @@ -19,7 +19,9 @@ class CGRaidMember { /* 0008 */ uint32_t unk_0008; /* 000C */ int32_t m_rank; /* 0010 */ CGPartyMemberState m_stats; - /* 0320 */ uint32_t unk_0320[3]; + /* 0320 */ int32_t m_readyCheckPending; + /* 0324 */ int32_t m_readyCheckReady; + /* 0328 */ uint32_t unk_0328; /* 032C */ uint32_t m_groupRole; }; @@ -36,9 +38,14 @@ class CGRaidInfo { static WOWGUID m_readyCheckInitiator; static uint32_t m_readyCheckTimer; static uint8_t m_rosterCounter; + static int32_t m_partyReadyCheckReady[4]; + static int32_t m_partyReadyCheckPending[4]; static void EnterWorld(); static void InitializeGame(); + static int32_t GetPartyMemberIndex(WOWGUID guid); + static int32_t IsPartyMemberReadyCheckPending(uint32_t index); + static int32_t IsPartyMemberReadyCheckReady(uint32_t index); static CGPartyMemberState* GetRemoteStats(const WOWGUID& guid); static CGRaidMember* FindMemberByGuid(WOWGUID guid); static CGPartyPetState* GetRemotePetStats(const WOWGUID& guid); @@ -60,9 +67,7 @@ int32_t Script_PromoteToLeader(lua_State* L); int32_t Script_PromoteToAssistant(lua_State* L); int32_t Script_DemoteAssistant(lua_State* L); int32_t Script_SetRaidTarget(lua_State* L); -int32_t Script_GetRaidTargetIndex(lua_State* L); int32_t Script_DoReadyCheck(lua_State* L); -int32_t Script_GetReadyCheckStatus(lua_State* L); void RaidInfoRegisterScriptFunctions(); void RaidRosterNameCallback(int32_t id, const WOWGUID& guid, void* param, bool success); diff --git a/WoW/Source/Ui/RaidInfo_Scripts.cpp b/WoW/Source/Ui/RaidInfo_Scripts.cpp index 40adaaf..2455b07 100644 --- a/WoW/Source/Ui/RaidInfo_Scripts.cpp +++ b/WoW/Source/Ui/RaidInfo_Scripts.cpp @@ -7,11 +7,13 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "Engine/Source/lua-5.1/src/lauxlib.h" #include "Engine/Source/Os/Time.h" +#include "Engine/Source/Os/TimeManager.h" #include "Engine/Source/Base/CDataStore.h" #include "WoW/Source/Net/Types.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "Engine/Source/FrameXML/LoadXML.h" +#include "WoW/Source/Ui/ScriptEvents.h" // VERIFY: 3ff51581 manual // OFFSET: 0x00572B40 @@ -147,7 +149,102 @@ static int32_t Script_IsRaidOfficer(lua_State* L) { return 1; } +// VERIFY: 9510fc76 manual +// OFFSET: 0x00574180 +static int32_t Script_GetReadyCheckStatus(lua_State* L) { + WOWGUID guid = GetGuidByKeyword(lua_tolstring(L, 1, nullptr)); + const char* status = nullptr; + + if (!CGRaidInfo::m_numMembers) { + if (!CGPartyInfo::m_members[0] || CGPartyInfo::m_leader != ClntObjMgrGetActivePlayer()) { + lua_pushstring(L, status); + return 1; + } + + int32_t index = CGRaidInfo::GetPartyMemberIndex(guid); + uint32_t now = OsGetAsyncTimeMs(); + + if (!CGRaidInfo::m_readyCheckTime || static_cast(now - CGRaidInfo::m_readyCheckTime) >= 0 || CGRaidInfo::m_readyCheckTime == now) { + lua_pushstring(L, status); + return 1; + } + + if (index == -1) { + if (guid == CGRaidInfo::m_readyCheckInitiator) { + status = "ready"; + } + + lua_pushstring(L, status); + return 1; + } + + if (CGRaidInfo::IsPartyMemberReadyCheckPending(index)) { + lua_pushstring(L, "waiting"); + return 1; + } + + if (CGRaidInfo::IsPartyMemberReadyCheckReady(index)) { + lua_pushstring(L, "ready"); + return 1; + } + + lua_pushstring(L, "notready"); + return 1; + } + + CGRaidMember* self = CGRaidInfo::FindMemberByGuid(ClntObjMgrGetActivePlayer()); + + if (!self || self->m_rank <= 0) { + lua_pushstring(L, status); + return 1; + } + + CGRaidMember* member = CGRaidInfo::FindMemberByGuid(guid); + uint32_t now = OsGetAsyncTimeMs(); + + if (!CGRaidInfo::m_readyCheckTime || static_cast(now - CGRaidInfo::m_readyCheckTime) >= 0 || CGRaidInfo::m_readyCheckTime == now || !member) { + lua_pushstring(L, status); + return 1; + } + + if (guid == CGRaidInfo::m_readyCheckInitiator) { + lua_pushstring(L, "ready"); + return 1; + } + + if (member->m_readyCheckPending) { + lua_pushstring(L, "waiting"); + return 1; + } + + if (member->m_readyCheckReady) { + lua_pushstring(L, "ready"); + return 1; + } + + lua_pushstring(L, "notready"); + return 1; +} + // STATIC: 0x00ACE790 +// VERIFY: 86d61574 auto +// OFFSET: 0x00572AB0 +static int32_t Script_GetRaidTargetIndex(lua_State* L) { + if (!lua_isstring(L, 1)) { + luaL_error(L, "Usage: GetRaidTargetIndex(unit)"); + } + + uint32_t index = GetRaidTargetIndexFromGuid(GetGuidByKeyword(lua_tolstring(L, 1, nullptr))); + + if (index == 8) { + lua_pushnil(L); + } else { + lua_pushnumber(L, index + 1); + } + + return 1; +} + static FrameScript_Method s_ScriptFunctions[] = { { "GetNumRaidMembers", &Script_GetNumRaidMembers }, { "GetRealNumRaidMembers", &Script_GetRealNumRaidMembers }, diff --git a/WoW/Source/Ui/RuneInfo.h b/WoW/Source/Ui/RuneInfo.h index bde75ab..5e829a9 100644 --- a/WoW/Source/Ui/RuneInfo.h +++ b/WoW/Source/Ui/RuneInfo.h @@ -3,11 +3,15 @@ #include +class CDataStore; class SpellRec; class CGRuneInfo { public: static int32_t m_runes[8]; + static void ConvertRune(uint8_t rune, uint8_t type); + static void ResyncRunes(CDataStore* msg); + static void AddRunePower(CDataStore* msg); static int32_t m_baseRunes[8]; static uint32_t m_runeCooldowns[8]; static uint32_t m_runeLastUsed[8]; @@ -21,6 +25,7 @@ class CGRuneInfo { static bool ComputeRuneSpellCooldown(const SpellRec* spell, uint32_t* cooldown); static bool IsRuneIndexValid(int32_t index); static int32_t GetRuneTypeByIndex(int32_t index, bool base); + static uint32_t GetRuneLastUsedTime(int32_t index); }; #endif diff --git a/WoW/Source/Ui/ScriptEvents.cpp b/WoW/Source/Ui/ScriptEvents.cpp index 03265ad..251f0dd 100644 --- a/WoW/Source/Ui/ScriptEvents.cpp +++ b/WoW/Source/Ui/ScriptEvents.cpp @@ -17,6 +17,12 @@ #include "WoW/Source/Ui/CommentatorFrame.h" #include "WoW/Source/Ui/InstanceEncounter_C.h" #include "WoW/Source/Ui/QuestFrame.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Ui/SpellBookFrame.h" +#include "WoW/Source/DB/Rec/SpellDispelTypeRec.h" +#include "WoW/Source/DB/Rec/SpellIconRec.h" +#include "WoW/Source/Object/ObjectClient/AuraData.h" +#include "WoW/Source/DB/DBClient/DBClient.h" // STATIC: 0x00C24EB0 const char* g_scriptEvents[NUM_SCRIPT_EVENTS]; @@ -575,6 +581,194 @@ bool Script_GetGUIDFromString(const char** name, WOWGUID& guid) { return guid != WOWGUID(); } +// STATIC: 0x00C25B7C +static char s_auraToken[32]; + +// VERIFY: 4748d1fc manual +// OFFSET: 0x0060B420 +const char* Script_GetAuraTokenFromGUID(const WOWGUID* guid) { + if (!*guid) { + return nullptr; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return nullptr; + } + + if (*guid == player->m_obj->m_guid) { + return "player"; + } + + if (player->IsSeatedInVehicle() && guid->m_guid == player->GetTransportGUID()) { + return "vehicle"; + } + + if (*guid == (player->m_unit->m_unitFieldCharm ? player->m_unit->m_unitFieldCharm : player->m_unit->m_unitFieldSummon)) { + return "pet"; + } + + for (uint32_t i = 0; i < CGPartyInfo::GetNumPartyMembers(); i++) { + if (*guid == CGGameUI::GetPartyMember(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "party%d", i + 1); + return s_auraToken; + } + + if (*guid == CGGameUI::GetPartyMemberPet(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "partypet%d", i + 1); + return s_auraToken; + } + } + + for (uint32_t i = 0; i < CGRaidInfo::m_numMembers; i++) { + if (*guid == GetRaidMemberGUID(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "raid%d", i + 1); + return s_auraToken; + } + + if (*guid == CGGameUI::GetRaidMemberPet(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "raidpet%d", i + 1); + return s_auraToken; + } + } + + for (uint32_t i = 0; i < GetArenaPetGUIDCount(); i++) { + if (*guid == CGBattlefieldInfo::GetArenaOpponent(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "arena%d", i + 1); + return s_auraToken; + } + + if (*guid == CGBattlefieldInfo::GetArenaOpponentPet(i)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "arenapet%d", i + 1); + return s_auraToken; + } + } + + if (*guid == CGGameUI::m_lockedTarget) { + return "target"; + } + + if (*guid == CGGameUI::unk_BD07D0) { + return "focus"; + } + + if (*guid == CGGameUI::m_interactTarget) { + return "npc"; + } + + if (*guid == CGGameUI::m_currentObjectTrack) { + return "mouseover"; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return nullptr; + } + + WOWGUID owner = unit->m_unit->m_unitFieldCharmedby ? unit->m_unit->m_unitFieldCharmedby : unit->m_unit->m_unitFieldCreatedby; + WOWGUID charm = unit->m_unit->m_unitFieldCharm ? unit->m_unit->m_unitFieldCharm : unit->m_unit->m_unitFieldSummon; + + if (owner) { + if (owner == player->m_obj->m_guid) { + return "player"; + } + } else if (!charm) { + return nullptr; + } + + if (charm && charm == player->m_obj->m_guid) { + return "player"; + } + + if (player->IsSeatedInVehicle()) { + if (owner && owner.m_guid == player->GetTransportGUID()) { + return "vehicle"; + } + + if (charm && charm.m_guid == player->GetTransportGUID()) { + return "vehicle"; + } + } + + WOWGUID playerPet = player->m_unit->m_unitFieldCharm ? player->m_unit->m_unitFieldCharm : player->m_unit->m_unitFieldSummon; + + if (owner && owner == playerPet) { + return "pet"; + } + + if (charm && charm == playerPet) { + return "pet"; + } + + for (uint32_t i = 0; i < CGPartyInfo::GetNumPartyMembers(); i++) { + WOWGUID member = CGGameUI::GetPartyMember(i); + + if ((owner && owner == member) || (charm && charm == member)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "party%d", i + 1); + return s_auraToken; + } + + WOWGUID memberPet = CGGameUI::GetPartyMemberPet(i); + + if ((owner && owner == memberPet) || (charm && charm == memberPet)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "partypet%d", i + 1); + return s_auraToken; + } + } + + for (uint32_t i = 0; i < CGRaidInfo::m_numMembers; i++) { + WOWGUID member = GetRaidMemberGUID(i); + + if ((owner && owner == member) || (charm && charm == member)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "raid%d", i + 1); + return s_auraToken; + } + + WOWGUID memberPet = CGGameUI::GetRaidMemberPet(i); + + if ((owner && owner == memberPet) || (charm && charm == memberPet)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "raidpet%d", i + 1); + return s_auraToken; + } + } + + for (uint32_t i = 0; i < GetArenaPetGUIDCount(); i++) { + WOWGUID opponent = CGBattlefieldInfo::GetArenaOpponent(i); + + if ((owner && owner == opponent) || (charm && charm == opponent)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "arena%d", i + 1); + return s_auraToken; + } + + WOWGUID opponentPet = CGBattlefieldInfo::GetArenaOpponentPet(i); + + if ((owner && owner == opponentPet) || (charm && charm == opponentPet)) { + SStrPrintf(s_auraToken, sizeof(s_auraToken), "arenapet%d", i + 1); + return s_auraToken; + } + } + + if ((owner && owner == CGGameUI::m_lockedTarget) || (charm && charm == CGGameUI::m_lockedTarget)) { + return "target"; + } + + if ((owner && owner == CGGameUI::unk_BD07D0) || (charm && charm == CGGameUI::unk_BD07D0)) { + return "focus"; + } + + if ((owner && owner == CGGameUI::m_interactTarget) || (charm && charm == CGGameUI::m_interactTarget)) { + return "npc"; + } + + if ((owner && owner == CGGameUI::m_currentObjectTrack) || (charm && charm == CGGameUI::m_currentObjectTrack)) { + return "mouseover"; + } + + return nullptr; +} + // VERIFY: fba1c703 manual // OFFSET: 0x0060BB70 char** Script_GetTokenIDsFromGUID(const WOWGUID& guid, int32_t* count) { @@ -671,6 +865,22 @@ void Script_SendUnitSignal(const WOWGUID& guid, int32_t signal) { } } +// VERIFY: b717b06c manual +// OFFSET: 0x0060BF60 +void Script_SendUnitSpellSignal(const WOWGUID& guid, uint8_t castCount, const SpellRec* spell, int32_t signal) { + if (!spell) { + Script_SendUnitSignal(guid, signal); + return; + } + + int32_t count; + char** tokens = Script_GetTokenIDsFromGUID(guid, &count); + + for (int32_t i = 0; i < count; i++) { + FrameScript_SignalEvent(signal, "%s%s%s%d", tokens[i], spell->m_name, spell->m_nameSubtext, castCount); + } +} + // VERIFY: 3289c731 auto // OFFSET: 0x00608390 static int32_t Script_GetAuraInfo(lua_State* L, int32_t index, ScriptAuraInfo* info) { @@ -736,3 +946,150 @@ int32_t Script_GetUnitAuraInfo(lua_State* L, int32_t index, ScriptAuraInfo* info info->m_guid = guid; return Script_GetAuraInfo(L, index + 1, info); } + +// VERIFY: f63fded5 manual +// OFFSET: 0x006147C0 +int32_t PushUnitAura(lua_State* L, ScriptAuraInfo* info) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(info->m_guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + if ((unit->m_auraEffectMask[36] & 0x80) && ClntObjMgrGetActivePlayer() && !unit->IsFriendly(ClntObjMgrGetActivePlayerObj())) { + return 0; + } + + if (!(unit->m_modelFlags & 0x10000)) { + uint32_t slot = unit->GetSortedAuraSlot(info->m_index, info->m_name, info->m_rank, info->m_filter); + SpellRec spell; + + if (static_cast(slot) < 0 || !g_spellDB.GetRecord(unit->GetAuraSpellId(slot), &spell)) { + return 0; + } + + AuraData* aura = unit->GetAura(slot); + const char* debuffType = nullptr; + + if (spell.m_dispelType) { + SpellDispelTypeRec* dispel = g_spellDispelTypeDB.GetRecord(spell.m_dispelType); + + if (dispel && dispel->m_immunityPossible) { + debuffType = dispel->m_internalName; + } + } + + SpellIconRec* icon = g_spellIconDB.GetRecord(spell.m_spellIconID); + lua_pushstring(L, spell.m_name); + lua_pushstring(L, spell.m_nameSubtext); + lua_pushstring(L, icon ? icon->m_textureFilename : nullptr); + lua_pushnumber(L, aura->m_stackCount); + lua_pushstring(L, debuffType); + + if (aura->m_duration > 0) { + lua_pushnumber(L, aura->m_duration * 0.001); + lua_pushnumber(L, aura->m_endTime * 0.001); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + } + + lua_pushstring(L, Script_GetAuraTokenFromGUID(&aura->m_creator)); + + if (CGSpellBook::CanStealAura(unit, aura, &spell)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (spell.m_attributesExG & 0x10000000) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, spell.m_id); + return 11; + } + } + + int32_t* auras; + uint8_t* auraFlags; + + if (CGPartyMemberState* state = CGPartyMemberStateRepository::GetState(info->m_guid)) { + if (!(state->m_flags & 0x1)) { + return 0; + } + + auras = state->m_auras; + auraFlags = state->m_auraFlags; + } else if (CGPartyPetState* petState = CGPartyMemberStateRepository::FindPetState(info->m_guid)) { + auras = petState->m_auras; + auraFlags = petState->m_auraFlags; + } else { + return 0; + } + + bool helpful = info->m_filter & 0x1; + bool raid = (info->m_filter & 0x8) != 0; + int32_t found = 0; + + for (uint32_t i = 0; i < 64 && auras[i]; i++) { + if (helpful != !(auraFlags[i] & 0x80)) { + continue; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(auras[i], &spell)) { + continue; + } + + WOWGUID caster = { 0 }; + + if (!CGSpellBook::CanShowAura(&spell, &caster, (auraFlags[i] & 0x8) != 0)) { + continue; + } + + if (raid && !(helpful ? CGSpellBook::FindRaidBuff(auras[i]) : CGSpellBook::FindRaidDispel(spell.m_dispelType))) { + continue; + } + + if ((auraFlags[i] & 0x10) ? (info->m_filter & 0x20) : (info->m_filter & 0x10)) { + continue; + } + + if ((info->m_index >= 0 && info->m_index == found) || (info->m_name && !SStrCmpUTF8I(info->m_name, spell.m_name, STORM_MAX_STR) && (!info->m_rank || !SStrCmpUTF8I(info->m_rank, spell.m_nameSubtext, STORM_MAX_STR)))) { + const char* debuffType = nullptr; + + if (spell.m_dispelType) { + SpellDispelTypeRec* dispel = g_spellDispelTypeDB.GetRecord(spell.m_dispelType); + + if (dispel && dispel->m_immunityPossible) { + debuffType = dispel->m_internalName; + } + } + + SpellIconRec* icon = g_spellIconDB.GetRecord(spell.m_spellIconID); + lua_pushstring(L, spell.m_name); + lua_pushstring(L, spell.m_nameSubtext); + lua_pushstring(L, icon ? icon->m_textureFilename : nullptr); + lua_pushnumber(L, 1.0); + lua_pushstring(L, debuffType); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnil(L); + lua_pushnil(L); + + if (spell.m_attributesExG & 0x10000000) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, spell.m_id); + return 11; + } + + found++; + } + + return 0; +} diff --git a/WoW/Source/Ui/ScriptEvents.h b/WoW/Source/Ui/ScriptEvents.h index 6adb03e..8ef7b8b 100644 --- a/WoW/Source/Ui/ScriptEvents.h +++ b/WoW/Source/Ui/ScriptEvents.h @@ -31,6 +31,7 @@ WOWGUID GetGuidByKeyword(const char* token); bool GetUnitByKeyword(const char* token, CGUnit_C** unit, bool defaultToTarget); int32_t Script_GetUnitAuraInfo(lua_State* L, int32_t index, ScriptAuraInfo* info); int32_t PushUnitAura(lua_State* L, ScriptAuraInfo* info); +const char* Script_GetAuraTokenFromGUID(const WOWGUID* guid); VehicleSeatRec* GetVehicleSeatRecAsPassengerFromLua(lua_State* L); void UnitNameQueryCallback(int32_t id, const WOWGUID& guid, void* param, bool success); bool Script_GetGUIDFromString(const char** name, WOWGUID& guid); diff --git a/WoW/Source/Ui/ScriptEvents_Scripts.cpp b/WoW/Source/Ui/ScriptEvents_Scripts.cpp index 15f3539..925c65c 100644 --- a/WoW/Source/Ui/ScriptEvents_Scripts.cpp +++ b/WoW/Source/Ui/ScriptEvents_Scripts.cpp @@ -50,13 +50,11 @@ int32_t Script_UnitInRaid(lua_State* L); int32_t Script_UnitPlayerOrPetInRaid(lua_State* L); int32_t Script_UnitIsAFK(lua_State* L); int32_t Script_UnitIsDND(lua_State* L); -int32_t Script_UnitIsPVP(lua_State* L); int32_t Script_UnitIsPVPSanctuary(lua_State* L); int32_t Script_UnitIsPVPFreeForAll(lua_State* L); int32_t Script_UnitFactionGroup(lua_State* L); int32_t Script_UnitReaction(lua_State* L); int32_t Script_UnitIsEnemy(lua_State* L); -int32_t Script_UnitIsFriend(lua_State* L); int32_t Script_UnitCanAssist(lua_State* L); int32_t Script_UnitCanAttack(lua_State* L); int32_t Script_PlayerCanTeleport(lua_State* L); @@ -81,8 +79,6 @@ int32_t Script_UnitAttackPower(lua_State* L); int32_t Script_UnitRangedAttackPower(lua_State* L); int32_t Script_UnitDefense(lua_State* L); int32_t Script_UnitArmor(lua_State* L); -int32_t Script_UnitBuff(lua_State* L); -int32_t Script_UnitAura(lua_State* L); int32_t Script_UnitIsTapped(lua_State* L); int32_t Script_UnitIsTappedByPlayer(lua_State* L); int32_t Script_UnitIsTappedByAllThreatList(lua_State* L); @@ -104,11 +100,9 @@ int32_t Script_GetBlockChance(lua_State* L); int32_t Script_GetShieldBlock(lua_State* L); int32_t Script_GetParryChance(lua_State* L); int32_t Script_GetCritChanceFromAgility(lua_State* L); -int32_t Script_GetSpellCritChanceFromIntellect(lua_State* L); int32_t Script_GetCritChance(lua_State* L); int32_t Script_GetRangedCritChance(lua_State* L); int32_t Script_GetSpellCritChance(lua_State* L); -int32_t Script_GetSpellBonusDamage(lua_State* L); int32_t Script_GetSpellBonusHealing(lua_State* L); int32_t Script_GetPetSpellBonusDamage(lua_State* L); int32_t Script_GetSpellPenetration(lua_State* L); @@ -142,7 +136,6 @@ int32_t Script_GetUnitHealthRegenRateFromSpirit(lua_State* L); int32_t Script_GetUnitManaRegenRateFromSpirit(lua_State* L); int32_t Script_GetManaRegen(lua_State* L); int32_t Script_GetPowerRegen(lua_State* L); -int32_t Script_GetRuneCooldown(lua_State* L); int32_t Script_GetRuneCount(lua_State* L); int32_t Script_ReportPlayerIsPVPAFK(lua_State* L); int32_t Script_PlayerIsPVPInactive(lua_State* L); @@ -2634,6 +2627,20 @@ static int32_t Script_UnitThreatSituation(lua_State* L) { return 1; } +// VERIFY: 4231ad42 auto +// OFFSET: 0x00614CA0 +static int32_t Script_UnitBuff(lua_State* L) { + ScriptAuraInfo info; + + if (!Script_GetUnitAuraInfo(L, 1, &info)) { + luaL_error(L, "Usage: UnitBuff(\"unit\", [index] or [\"name\", \"rank\"][, \"filter\"])"); + return 0; + } + + info.m_filter = (info.m_filter & ~0x3) | 0x1; + return PushUnitAura(L, &info); +} + // VERIFY: 81f01547 auto // OFFSET: 0x00614CF0 static int32_t Script_UnitDebuff(lua_State* L) { @@ -2648,6 +2655,19 @@ static int32_t Script_UnitDebuff(lua_State* L) { return PushUnitAura(L, &info); } +// VERIFY: 2c76197b auto +// OFFSET: 0x00614D40 +static int32_t Script_UnitAura(lua_State* L) { + ScriptAuraInfo info; + + if (!Script_GetUnitAuraInfo(L, 1, &info)) { + luaL_error(L, "Usage: UnitAura(\"unit\", [index] or [\"name\", \"rank\"][, \"filter\"])"); + return 0; + } + + return PushUnitAura(L, &info); +} + // VERIFY: 2717e6ac auto // OFFSET: 0x00613740 static int32_t Script_UnitHasVehicleUI(lua_State* L) { @@ -2874,7 +2894,133 @@ static int32_t Script_GetRuneType(lua_State* L) { return 1; } +// VERIFY: a37de20f auto +// OFFSET: 0x0060E1B0 +static int32_t Script_GetSpellCritChanceFromIntellect(lua_State* L) { + if (!lua_isstring(L, 1)) { + luaL_error(L, "Usage: GetSpellCritChanceFromIntellect(\"unit\")"); + } + + CGUnit_C* unit = GetUnitFromName(lua_tolstring(L, 1, nullptr)); + + if (unit && (unit->IsActivePlayer() || unit->m_unit->m_unitFieldPetnumber)) { + lua_pushnumber(L, unit->GetSpellChanceToCrit()); + } else { + lua_pushnumber(L, 0.0); + } + + return 1; +} + +// VERIFY: 7b6edbe8 manual +// OFFSET: 0x0060E310 +static int32_t Script_GetSpellBonusDamage(lua_State* L) { + uint32_t school = static_cast(lua_tonumber(L, 1)) - 1; + + if (school > 6) { + luaL_error(L, "Usage: GetSpellBonusDamage(school)"); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + int32_t positive = player->GetModDamageDonePos(school); + lua_pushnumber(L, player->GetModDamageDoneNeg(school) + positive); + } else { + lua_pushnumber(L, 0.0); + } + + return 1; +} + +// VERIFY: 5e857cf7 manual +// OFFSET: 0x00613020 +static int32_t Script_GetRuneCooldown(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetRuneCooldown(slot)"); + } + + uint32_t slot = static_cast(lua_tonumber(L, 1)) - 1; + + if (slot > 7) { + luaL_error(L, "Invalid slot"); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return 0; + } + + uint32_t lastUsed = CGRuneInfo::GetRuneLastUsedTime(slot); + float regen = player->m_player->m_playerRuneRegen1[CGRuneInfo::GetRuneTypeByIndex(slot, false)]; + float duration = regen > 0.01f ? 1.0f / regen : 0.0f; + lua_pushnumber(L, lastUsed * 0.001); + lua_pushnumber(L, duration); + lua_pushboolean(L, lastUsed == 0); + return 3; +} + // STATIC: 0x00AD2184 +// VERIFY: cabd9576 manual +// OFFSET: 0x0060CE20 +static int32_t Script_UnitIsPVP(lua_State* L) { + if (!lua_isstring(L, 1)) { + luaL_error(L, "Usage: UnitIsPVP(\"unit\")"); + } + + const char* token = lua_tolstring(L, 1, nullptr); + WOWGUID guid = WOWGUID(); + Script_GetGUIDFromToken(token, guid, false); + WOWGUID stateGuid = guid; + CGObject_C* object = ClntObjMgrObjectPtr(guid, TYPEMASK_OBJECT, __FILE__, __LINE__); + bool pvp; + + if (object && (object->m_obj->m_type & TYPEMASK_UNIT)) { + pvp = static_cast(object)->m_unit->m_unitFieldBytes2[1] & 1; + } else if (object && (object->m_obj->m_type & TYPEMASK_CORPSE)) { + pvp = static_cast(object)->m_corpse->m_corpseFieldFlags & 4; + } else { + CGPartyMemberState* state = CGPartyMemberStateRepository::GetState(stateGuid); + pvp = state && (state->m_flags & 2); + } + + if (pvp) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: cffb18d2 manual +// OFFSET: 0x0060D3D0 +static int32_t Script_UnitIsFriend(lua_State* L) { + if (!lua_isstring(L, 1) || !lua_isstring(L, 2)) { + luaL_error(L, "Usage: UnitIsFriend(\"unit\", \"otherUnit\")"); + } + + const char* token = lua_tolstring(L, 1, nullptr); + const char* otherToken = lua_tolstring(L, 2, nullptr); + WOWGUID guid = WOWGUID(); + Script_GetGUIDFromToken(token, guid, false); + WOWGUID unitGuid = guid; + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + guid = WOWGUID(); + Script_GetGUIDFromToken(otherToken, guid, false); + WOWGUID otherGuid = guid; + CGUnit_C* other = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if ((unit && other && unit->IsFriendly(other)) || (!SStrCmpI(token, "player", STORM_MAX_STR) && CGGameUI::IsRaidMemberOrPet(otherGuid)) || (!SStrCmpI(otherToken, "player", STORM_MAX_STR) && CGGameUI::IsRaidMemberOrPet(unitGuid))) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + static FrameScript_Method s_SystemFunctions[] = { { "GetTime", &Script_GetTime }, { "GetGameTime", &Script_GetGameTime }, diff --git a/WoW/Source/Ui/SkillInfo.cpp b/WoW/Source/Ui/SkillInfo.cpp index b0dbf63..a46fa4f 100644 --- a/WoW/Source/Ui/SkillInfo.cpp +++ b/WoW/Source/Ui/SkillInfo.cpp @@ -1,6 +1,13 @@ #include "SkillInfo.h" #include "Engine/Source/Storm/H/storm.h" #include "WoW/Source/DB/DBClient/DBClient.h" +#include +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/Magic/MagicClient/SpellTable.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/Types.h" // STATIC: 0x00C22AE8 uint32_t CGSkillInfo::m_numLines; @@ -17,6 +24,9 @@ int32_t CGSkillInfo::m_selectedSkill; // STATIC: 0x00C22AF8 int32_t CGSkillInfo::unk_C22AF8; +// STATIC: 0x00C22AFC +int32_t CGSkillInfo::unk_C22AFC; + // STATIC: 0x00C22B00 int32_t CGSkillInfo::m_skillUpPoints; @@ -72,3 +82,170 @@ int32_t CGSkillInfo::GetSelectedIndex() { return -1; } + +// VERIFY: 3729603c manual +// OFFSET: 0x005CD430 +static int32_t SortSkillTypes(const void* a, const void* b) { + const SkillTypeInfo* typeA = *static_cast(a); + const SkillTypeInfo* typeB = *static_cast(b); + SkillLineCategoryRec* recA = g_skillLineCategoryDB.GetRecord(typeA->m_categoryID); + SkillLineCategoryRec* recB = g_skillLineCategoryDB.GetRecord(typeB->m_categoryID); + return 2 * (recA->m_sortIndex >= recB->m_sortIndex) - 1; +} + +// VERIFY: 4448ea95 manual +// OFFSET: 0x005CD4A0 +static int32_t SortSkillLines(const void* a, const void* b) { + const SkillLineInfo* lineA = *static_cast(a); + const SkillLineInfo* lineB = *static_cast(b); + + if (!lineA->m_expanded || !lineB->m_expanded) { + if (!lineA->m_expanded && !lineB->m_expanded) { + return 0; + } + + return 2 * (lineA->m_expanded == 0) - 1; + } + + uint32_t typeA = 0; + uint32_t typeB = 0; + + for (uint32_t i = 0; i < CGSkillInfo::m_numTypes; i++) { + if (CGSkillInfo::m_types.m_data[i]->m_categoryID == lineA->m_categoryID) { + typeA = i; + } + + if (CGSkillInfo::m_types.m_data[i]->m_categoryID == lineB->m_categoryID) { + typeB = i; + } + } + + if (typeA != typeB) { + return 2 * (static_cast(typeA) >= static_cast(typeB)) - 1; + } + + if (!lineA->m_skillLineID) { + return -1; + } + + if (!lineB->m_skillLineID) { + return 1; + } + + if (lineA->unk_000C != lineB->unk_000C) { + return 2 * (lineA->unk_000C != 0) - 1; + } + + SkillLineRec* recA = g_skillLineDB.GetRecord(lineA->m_skillLineID); + SkillLineRec* recB = g_skillLineDB.GetRecord(lineB->m_skillLineID); + + if (!recA || !recB) { + return 0; + } + + return SStrSortUTF8I(recA->m_displayName, recB->m_displayName, STORM_MAX_STR); +} + +// VERIFY: 243b4cba auto +// OFFSET: 0x005CD5E0 +void CGSkillInfo::UpdateSkillLines() { + CGSkillInfo::m_numSkillLines = CGSkillInfo::m_numLines; + + for (uint32_t i = 0; i < CGSkillInfo::m_numTypes; i++) { + CGSkillInfo::m_types.m_data[i]->unk_0004 = !(CGSkillInfo::unk_C22AF8 & (1 << i)); + } + + for (uint32_t i = 0; i < CGSkillInfo::m_numLines; i++) { + SkillLineInfo* line = CGSkillInfo::m_lines.m_data[i]; + + if (!line->m_skillLineID) { + line->m_expanded = 1; + continue; + } + + uint32_t type; + + for (type = 0; type < CGSkillInfo::m_numTypes; type++) { + if (CGSkillInfo::m_types.m_data[type]->m_categoryID == line->m_categoryID) { + break; + } + } + + if (type == CGSkillInfo::m_numTypes) { + continue; + } + + line->m_expanded = !CGSkillInfo::m_types.m_data[type]->unk_0004 && (!CGSkillInfo::unk_C22AFC || !line->unk_000C); + + if (!CGSkillInfo::m_lines.m_data[i]->m_expanded) { + CGSkillInfo::m_numSkillLines--; + } + } + + qsort(CGSkillInfo::m_types.m_data, CGSkillInfo::m_numTypes, sizeof(SkillTypeInfo*), SortSkillTypes); + qsort(CGSkillInfo::m_lines.m_data, CGSkillInfo::m_numLines, sizeof(SkillLineInfo*), SortSkillLines); + FrameScript_SignalEvent(SCRIPT_EVENT_SKILL_LINES_CHANGED, nullptr); +} + +// VERIFY: 4f4bdc99 manual +// OFFSET: 0x005CD9B0 +void PlayerSignalSkillStatChanges() { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return; + } + + CGSkillInfo::unk_C22AF8 = -1; + CGSkillInfo::m_numLines = 0; + CGSkillInfo::m_numTypes = 0; + CGSkillInfo::m_numSkillLines = 0; + CGSkillInfo::m_skillUpPoints = 0; + + for (uint32_t i = 0; i < 128; i++) { + CGPlayerLocalData* data = static_cast(player->m_player); + uint16_t skillId = player->m_obj->m_guid == ClntObjMgrGetActivePlayer() ? data->m_playerSkillInfo[i].m_skillId : 0; + + if (!skillId) { + continue; + } + + SkillLineRec* rec = g_skillLineDB.GetRecord(skillId); + const SkillRaceClassInfoRec* info = SpellTableLookupInfo(player->m_unit->m_unitFieldBytes0[0], player->m_unit->m_unitFieldBytes0[1], skillId); + + if (!rec || !info || !g_skillLineCategoryDB.GetRecord(rec->m_categoryID) || (info->m_flags & 2)) { + continue; + } + + uint16_t rank = data->m_playerSkillInfo[i].m_rank; + + if (!(info->m_flags & 1) && !rank && (!(info->m_flags & 4) || static_cast(player->m_unit->m_unitFieldLevel) < info->m_minLevel)) { + continue; + } + + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->m_skillLineID = skillId; + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->m_categoryID = rec->m_categoryID; + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->unk_000C = rank == 0; + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->m_skillUps = 0; + CGSkillInfo::m_numLines++; + + uint32_t type; + + for (type = 0; type < CGSkillInfo::m_numTypes; type++) { + if (CGSkillInfo::m_types.m_data[type]->m_categoryID == rec->m_categoryID) { + break; + } + } + + if (type != CGSkillInfo::m_numTypes) { + continue; + } + + CGSkillInfo::m_types.m_data[CGSkillInfo::m_numTypes++]->m_categoryID = rec->m_categoryID; + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->m_skillLineID = 0; + CGSkillInfo::m_lines.m_data[CGSkillInfo::m_numLines]->m_categoryID = rec->m_categoryID; + CGSkillInfo::m_numLines++; + } + + CGSkillInfo::UpdateSkillLines(); +} diff --git a/WoW/Source/Ui/SkillInfo.h b/WoW/Source/Ui/SkillInfo.h index 90b7f4b..8ff42b5 100644 --- a/WoW/Source/Ui/SkillInfo.h +++ b/WoW/Source/Ui/SkillInfo.h @@ -27,11 +27,13 @@ class CGSkillInfo { static uint32_t m_numSkillLines; static int32_t m_selectedSkill; static int32_t unk_C22AF8; + static int32_t unk_C22AFC; static int32_t m_skillUpPoints; static TSFixedArray m_lines; static TSFixedArray m_types; static void InitializeGame(); static int32_t GetSelectedIndex(); + static void UpdateSkillLines(); }; int32_t Script_GetSkillLineInfo(lua_State* L); diff --git a/WoW/Source/Ui/SpellBookFrame.cpp b/WoW/Source/Ui/SpellBookFrame.cpp index f49e80b..111601d 100644 --- a/WoW/Source/Ui/SpellBookFrame.cpp +++ b/WoW/Source/Ui/SpellBookFrame.cpp @@ -27,6 +27,10 @@ #include "WoW/Source/Ui/Tutorial.h" #include "WoW/Source/Ui/Types.h" #include "WoW/Source/Ui/UIMacros.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/Magic/Spell.h" +#include "WoW/Source/Object/ObjectClient/AuraData.h" +#include "WoW/Source/DB/Rec/SkillRaceClassInfoRec.h" // STATIC: 0x00BE8E24 TSGrowableArray s_shapeshiftSpells; @@ -1391,3 +1395,767 @@ bool HasSpell(int32_t spellId, int32_t petSpell) { return false; } + +// VERIFY: 346d7716 auto +// OFFSET: 0x0053BAC0 +void CGSpellBook::UpdateCooldowns() { + CGActionBar::SignalUpdateCooldown(); + + if (s_shapeshiftSpells.Count()) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_SHAPESHIFT_COOLDOWN, nullptr); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_SPELL_UPDATE_COOLDOWN, nullptr); +} + +// VERIFY: 47f87173 auto +// OFFSET: 0x0053BD10 +int32_t CGSpellBook::IsTrackingSpell(int32_t spellId) { + for (uint32_t i = s_trackingSpells.Count(); i; ) { + i--; + + if (spellId == s_trackingSpells.m_data[i]) { + return 1; + } + } + + return 0; +} + +// VERIFY: 5e582599 auto +// OFFSET: 0x0053B3F0 +void ClearPetSpellInfo() { + memset(s_petSpellList, 0, sizeof(s_petSpellList)); + CGSpellBook::m_numPetSpells = 0; +} + +// VERIFY: 0870e37a auto +// OFFSET: 0x0053B440 +void CGSpellBook::SendCompanionUpdate(int32_t type) { + if (type == 2) { + FrameScript_SignalEvent(SCRIPT_EVENT_COMPANION_UPDATE, nullptr); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_COMPANION_UPDATE, "%s", s_companionTypes[type]); + } +} + +// VERIFY: 99fbc6c2 auto +// OFFSET: 0x0053B5A0 +int32_t CGSpellBook::GetSpellRankOrLevel(const SpellRec* spell) { + int32_t rank = CGSpellBook::GetSpellProgressionRank(spell); + + if (!rank) { + return spell->m_spellLevel; + } + + return rank; +} + +// VERIFY: 97097f8a manual +// OFFSET: 0x0053BAF0 +void CGSpellBook::PickupSpell(int32_t slot, int32_t petSpell) { + if (!CGGameUI::CanPerformAction(14)) { + return; + } + + int32_t spellId; + + if (slot < 0) { + spellId = 0; + } else if (petSpell) { + spellId = slot < 1024 ? s_petSpellList[slot] : 0; + } else { + spellId = static_cast(slot) < s_numSpells ? s_spellList[slot] : 0; + } + + int32_t cursorSpell = CGGameUI::GetCursorSpell(); + CGGameUI::ClearCursor(1, 1); + + if (spellId == cursorSpell) { + if (spellId) { + SI2::PlaySoundKit("igSpellBookSpellIconDrop", nullptr, nullptr, nullptr); + } + } else if (cursorSpell <= 0 && spellId) { + if (petSpell) { + CGGameUI::SetCursorPetAction(CGPetInfo::GetPetSpellAction(spellId)); + } else { + CGGameUI::SetCursorSpell(spellId); + } + + SI2::PlaySoundKit("igSpellBookSpellIconPickup", nullptr, nullptr, nullptr); + } +} + +// VERIFY: e86b1382 auto +// OFFSET: 0x0053BBC0 +void CGSpellBook::PickupCompanion(int32_t type, uint32_t index) { + if (!CGGameUI::CanPerformAction(14) || index >= CGSpellBook::m_companions[type].m_count) { + return; + } + + int32_t spellId = CGSpellBook::m_companions[type].m_data[index]; + int32_t cursorSpell = CGGameUI::GetCursorSpell(); + CGGameUI::ClearCursor(1, 1); + + if (spellId == cursorSpell) { + SI2::PlaySoundKit("igSpellBookSpellIconDrop", nullptr, nullptr, nullptr); + } else if (cursorSpell <= 0) { + CGGameUI::SetCursorSpell(spellId); + SI2::PlaySoundKit("igSpellBookSpellIconPickup", nullptr, nullptr, nullptr); + } +} + +// VERIFY: 6f493db6 manual +// OFFSET: 0x0053BC40 +void CGSpellBook::CastSpell(int32_t slot, int32_t petSpell, WOWGUID target) { + if (CGGameUI::GetCursorSpell() > 0) { + CGSpellBook::PickupSpell(slot, petSpell); + return; + } + + CGGameUI::ClearCursor(1, 1); + + int32_t spellId; + + if (slot < 0) { + spellId = 0; + } else if (petSpell) { + spellId = slot < 1024 ? s_petSpellList[slot] : 0; + } else { + spellId = static_cast(slot) < s_numSpells ? s_spellList[slot] : 0; + } + + if (!petSpell) { + Spell_C_ClickSpell(spellId, nullptr, target); + return; + } + + uint32_t action = spellId | 0x1000000; + CGPetInfo::SendPetAction(action, target, 0); +} + +// VERIFY: cb3b2a4b manual +// OFFSET: 0x0053BD70 +int32_t CGSpellBook::IsAuraCaster(WOWGUID guid, const WOWGUID* caster) { + if (!guid.m_guid || !caster || !caster->m_guid) { + return 0; + } + + if (guid == *caster) { + return 1; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(*caster, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit) { + return 0; + } + + const WOWGUID& pet = unit->m_unit->m_unitFieldCharm.m_guid ? unit->m_unit->m_unitFieldCharm : unit->m_unit->m_unitFieldSummon; + + return guid == pet || guid == *unit->GetCharmerOrCreatorGuid(); +} + +// VERIFY: 586419fd auto +// OFFSET: 0x0053BDF0 +int32_t CGSpellBook::FindRaidDispel(int32_t dispelType) { + for (uint32_t i = 0; i < s_dispelTypes.m_count; i++) { + if (s_dispelTypes.m_data[i] == dispelType) { + return 1; + } + } + + return 0; +} + +// VERIFY: 53ad8165 auto +// OFFSET: 0x0053BE30 +bool CGSpellBook::IsUnlearnedSpell(int32_t spellId) { + for (uint32_t i = 0; i < CGSpellBook::m_unlearnedSpells.m_count; i++) { + if (CGSpellBook::m_unlearnedSpells.m_data[i] == spellId) { + return true; + } + } + + return false; +} + +// VERIFY: 64002cc0 manual +// OFFSET: 0x0053C5B0 +bool HasSpell(uint32_t spellId) { + return spellId <= static_cast(g_spellDB.m_maxID) && (s_knownSpellBits.m_bits.m_data[spellId >> 5] & (1 << (spellId & 0x1F))); +} + +// VERIFY: 230462f8 manual +// OFFSET: 0x0053F550 +void CGSpellBook::DelSpellFromNameCache(int32_t spellId, int32_t petSpell) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return; + } + + SPELLSBYNAME* entry = s_spellsByName.Ptr(spell.m_name); + + if (!entry) { + return; + } + + for (SPELLRANKNODE* node = entry->m_spells.Head(); node; node = node->m_link.Next()) { + if (node->m_spellId == spellId && node->m_petSpell == petSpell) { + entry->m_spells.DeleteNode(node); + break; + } + } +} + +// VERIFY: e855f5ff auto +// OFFSET: 0x00540650 +int32_t IsValidSpell(const char* name, int32_t* petSpell) { + return GetSpellSlot(GetSpellIdByName(name, petSpell), *petSpell); +} + +// VERIFY: 5b1aa4c6 auto +// OFFSET: 0x00542EB0 +void CGSpellBook::ReplaceSpell(int32_t oldSpell, int32_t newSpell) { + CGSpellBook::DelKnownSpell(oldSpell, 1); + CGSpellBook::AddKnownSpell(newSpell, 1, oldSpell); +} + +// VERIFY: bd1e6229 auto +// OFFSET: 0x00542EE0 +void CGSpellBook::AddPetSpell(int32_t spellId) { + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && !(spell.m_attributes & 0x80) && !(spell.m_attributesExD & 0x8000)) { + CGSpellBook::AddSpellToNameCache(spellId, 1); + s_petSpellList[CGSpellBook::m_numPetSpells++] = spellId; + } +} + +// VERIFY: 415a64e8 manual +// OFFSET: 0x0053D1B0 +void CGSpellBook::UpdateUsablePower() { + CGActionBar::UpdateUsablePower(); + + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + SpellRec spell; + + for (uint32_t i = 0; i < s_knownSpells.m_count; i++) { + SpellUsableInfo* info = &s_knownSpells.m_data[i]; + + if (!info->m_usable) { + continue; + } + + g_spellDB.GetRecord(info->m_spellId, &spell); + bool havePower = Spell_C_HaveSpellPower(player, &spell); + + if (!havePower != info->m_noMana) { + if (havePower) { + SendToCombatText(35, spell.m_name); + } + + info->m_noMana = !havePower; + } + } + + int32_t changed = 0; + + for (uint32_t i = 0; i < s_shapeshiftSpells.m_count; i++) { + SpellUsableInfo* info = &s_shapeshiftSpells.m_data[i]; + + if (!info->m_usable) { + continue; + } + + g_spellDB.GetRecord(info->m_spellId, &spell); + uint8_t noMana = !Spell_C_HaveSpellPower(player, &spell); + + if (noMana != info->m_noMana) { + changed = 1; + info->m_noMana = noMana; + } + } + + if (s_shapeshiftSpells.m_count && changed) { + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_SHAPESHIFT_USABLE, nullptr); + } +} + +// VERIFY: 29941820 manual +// OFFSET: 0x0053D4B0 +uint32_t CGSpellBook::GetShapeshiftForm(int32_t requireForm) { + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || (requireForm && !player->GetShapeshiftForm())) { + return 0; + } + + SpellRec spell; + uint32_t form = s_shapeshiftSpells.m_count; + + for (; form; form--) { + if (g_spellDB.GetRecord(s_shapeshiftSpells.m_data[form - 1].m_spellId, &spell) && Spell_C_IsActiveSpell(&spell, player)) { + break; + } + } + + if (!form && player->GetShapeshiftForm()) { + form = s_shapeshiftSpells.m_count + 1; + } + + return form; +} + +// VERIFY: cfe23c3b manual +// OFFSET: 0x0053D580 +int32_t CGSpellBook::CanShowAura(const SpellRec* spell, const WOWGUID* caster, bool helpful) { + if ((spell->m_attributes & 0x80) || (spell->m_attributesEx & 0x10000000)) { + return 0; + } + + if (spell->m_attributes & 0x40) { + uint32_t i = 0; + + while (!Spell_IsAreaAuraEffect(spell->m_effect[i])) { + if (++i >= 3) { + return 0; + } + } + } + + bool hidden = helpful ? (spell->m_attributesExE & 0x8000000) != 0 : (spell->m_attributesExE & 0x10000000) != 0; + + if (hidden) { + return 0; + } + + if ((spell->m_attributesExF & 0x100000) && !(caster->m_guid && (*caster == ClntObjMgrGetActivePlayer() || *caster == CGPetInfo::GetPet(0)))) { + return 0; + } + + if (!spell->m_requiredAuraVision) { + return 1; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->HasAuraVision(spell->m_requiredAuraVision)) { + return 1; + } + + return 0; +} + +// VERIFY: ce8605b3 manual +// OFFSET: 0x0053D750 +int32_t CGSpellBook::CanApplyAura(const AuraData* aura) { + if (!aura) { + return 0; + } + + int32_t spellId = aura->m_spellId; + + if (HasSpell(static_cast(spellId)) || HasPetSpell(spellId)) { + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return 0; + } + + for (uint32_t i = 0; i < 3; i++) { + if (Spell_IsAuraEffect(spell.m_effect[i])) { + return 1; + } + } + } + + if (!aura->m_creator.m_guid) { + return 0; + } + + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(aura->m_creator, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!unit || !unit->m_creatureCacheEntry) { + return 0; + } + + const WOWGUID& owner = unit->m_unit->m_unitFieldCharmedby.m_guid ? unit->m_unit->m_unitFieldCharmedby : unit->m_unit->m_unitFieldCreatedby; + + if (!owner.m_guid) { + return 0; + } + + uint32_t entry = unit->m_obj->m_entryID; + + for (uint32_t i = 0; i < s_summonCreatures.m_count; i++) { + if (entry == static_cast(s_summonCreatures.m_data[i])) { + return 1; + } + } + + return 0; +} + +// VERIFY: 51d10eb7 manual +// OFFSET: 0x0053D8A0 +int32_t CGSpellBook::FindRaidBuff(int32_t spellId) { + if (!HasSpell(static_cast(spellId)) && !HasPetSpell(spellId)) { + return 0; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell) || (spell.m_attributesExC & 0x4000) || spell.m_implicitTargetA[0] == 1) { + return 0; + } + + for (uint32_t i = 0; i < 3; i++) { + int32_t effect = spell.m_effect[i]; + + if (effect == 35 || effect == 65 || effect == 119 || effect == 143 || effect == 128 || effect == 129 || effect == 27) { + return 0; + } + } + + return 1; +} + +// VERIFY: 66b38b26 manual +// OFFSET: 0x0053D9D0 +void CGSpellBook::GetAppropriateSpellRank(uint32_t* spellId, CGUnit_C* caster, CGUnit_C* target) { + SpellRec spell; + + if (!g_spellDB.GetRecord(*spellId, &spell) || (spell.m_attributes & 0x4000000) || (spell.m_attributesExB & 0x8)) { + return; + } + + uint32_t i = 0; + + while (!spell.m_effectAura[i]) { + if (++i >= 3) { + return; + } + } + + if (!caster) { + return; + } + + if (!caster->IsActivePlayer() && caster->m_obj->m_guid != CGPetInfo::GetPet(0)) { + return; + } + + if (!target || !caster->CanAssist(target, false)) { + return; + } + + uint32_t level = target->m_unit->m_unitFieldLevel; + + if (target->m_unit->m_unitFieldSummonedby.m_guid) { + CGUnit_C* summoner = static_cast(ClntObjMgrObjectPtr(target->m_unit->m_unitFieldSummonedby, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (summoner) { + level = summoner->m_unit->m_unitFieldLevel; + } + } + + int32_t maxLevel = level + 10; + + if (spell.m_spellLevel <= maxLevel) { + return; + } + + int32_t bestLevel = 0; + SpellRec other; + + if (!caster->IsActivePlayer()) { + for (uint32_t slot = CGSpellBook::m_numPetSpells; slot; ) { + slot--; + + if (g_spellDB.GetRecord(s_petSpellList[slot], &other) && !SStrCmp(spell.m_name, other.m_name, STORM_MAX_STR)) { + if (other.m_spellLevel <= maxLevel && other.m_spellLevel > bestLevel) { + *spellId = other.m_id; + bestLevel = other.m_spellLevel; + } + } + } + + return; + } + + for (uint32_t slot = s_numSpells; slot; ) { + slot--; + + if (g_spellDB.GetRecord(s_spellList[slot], &other) && !SStrCmp(spell.m_name, other.m_name, STORM_MAX_STR)) { + if (other.m_spellLevel <= maxLevel && other.m_spellLevel > bestLevel) { + *spellId = other.m_id; + bestLevel = other.m_spellLevel; + } + } + } +} + +// VERIFY: a1eaf271 manual +// OFFSET: 0x0053D680 +int32_t CGSpellBook::CanStealAura(const CGUnit_C* unit, const AuraData* aura, const SpellRec* spell) { + if (!s_dispelMask) { + return 0; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || !player->CanAttack(unit) || (aura->m_flags & 0x80)) { + return 0; + } + + if (spell->m_attributes & 0x40) { + return 0; + } + + for (uint32_t i = 0; i < 3; i++) { + if (((1 << i) & aura->m_flags) && Spell_IsAreaAuraEffect(spell->m_effect[i])) { + return 0; + } + } + + if ((spell->m_attributesEx & 0x44) || (spell->m_attributesExD & 0x40)) { + return 0; + } + + return (s_dispelMask & (1 << spell->m_dispelType)) != 0; +} + +// VERIFY: 88e8003e auto +// OFFSET: 0x0053BD40 +int32_t CGSpellBook::IsShapeshiftSpell(int32_t spellId) { + for (uint32_t i = s_shapeshiftSpells.m_count; i; ) { + i--; + + if (spellId == s_shapeshiftSpells.m_data[i].m_spellId) { + return 1; + } + } + + return 0; +} + +// VERIFY: f3047ba9 manual +// OFFSET: 0x0053FAD0 +void CGSpellBook::DelKnownSpell(int32_t spellId, int32_t notify) { + s_knownSpellBits.m_bits.m_data[spellId >> 5] &= ~(1 << (spellId & 0x1F)); + + if (spellId == CGSpellBook::m_duelSpell) { + CGSpellBook::m_duelSpell = 0; + } + + if (spellId == CGSpellBook::m_stuckSpell) { + CGSpellBook::m_stuckSpell = 0; + } + + if (spellId == CGSpellBook::m_summonFriendSpell) { + CGSpellBook::m_summonFriendSpell = 0; + } + + if (spellId == CGSpellBook::m_autoRangedSpell) { + CGSpellBook::m_autoRangedSpell = 0; + } + + for (uint32_t i = 0; i < 4; i++) { + if (spellId == s_skinningSpells[i]) { + s_skinningSpells[i] = 0; + } + } + + if (spellId == s_skinPlayerCorpseSpell) { + s_skinPlayerCorpseSpell = 0; + } + + CGSpellBook::DelSpellFromNameCache(spellId, 0); + + int32_t removed = 0; + + for (uint32_t i = 0; i < 1024; i++) { + if (s_spellList[i] != spellId) { + continue; + } + + uint32_t last = s_numSpells - 1; + + if (i < last) { + memcpy(&s_spellList[i], &s_spellList[i + 1], sizeof(s_spellList[0]) * (s_numSpells - i) - sizeof(s_spellList[0])); + } + + s_numSpells = last; + s_spellList[last] = 0; + removed = 1; + break; + } + + for (uint32_t i = CGSpellBook::m_languageSpells.m_count; i; ) { + i--; + + if (CGSpellBook::m_languageSpells.m_data[i] == spellId) { + CGSpellBook::m_languageSpells.m_data[i] = 0; + } + } + + for (uint32_t i = s_trackingSpells.m_count; i; ) { + i--; + + if (s_trackingSpells.m_data[i] == spellId) { + uint32_t last = s_trackingSpells.m_count - 1; + + if (i < last) { + memcpy(&s_trackingSpells.m_data[i], &s_trackingSpells.m_data[i + 1], sizeof(int32_t) * (last - i)); + } + + s_trackingSpells.SetCount(last); + break; + } + } + + for (uint32_t i = s_openLockSpells.m_count; i; ) { + i--; + + if (s_openLockSpells.m_data[i] == spellId) { + uint32_t last = s_openLockSpells.m_count - 1; + + if (i < last) { + memcpy(&s_openLockSpells.m_data[i], &s_openLockSpells.m_data[i + 1], sizeof(int32_t) * (last - i)); + } + + s_openLockSpells.SetCount(last); + break; + } + } + + if (!notify) { + for (uint32_t i = s_shapeshiftSpells.m_count; i; ) { + i--; + + if (s_shapeshiftSpells.m_data[i].m_spellId == spellId) { + uint32_t last = s_shapeshiftSpells.m_count - 1; + + if (i < last) { + memcpy(&s_shapeshiftSpells.m_data[i], &s_shapeshiftSpells.m_data[i + 1], sizeof(SpellUsableInfo) * (last - i)); + } + + s_shapeshiftSpells.SetCount(last); + Script_SendUniqueSignal(SCRIPT_EVENT_UPDATE_SHAPESHIFT_FORMS); + break; + } + } + } + + bool totemsEmptied = false; + + for (uint32_t t = 0; t < 4; t++) { + TSGrowableArray& totems = CGSpellBook::m_totemSpells[t]; + + for (uint32_t i = totems.m_count; i; ) { + i--; + + if (totems.m_data[i] == spellId) { + uint32_t last = totems.m_count - 1; + + if (i < last) { + memcpy(&totems.m_data[i], &totems.m_data[i + 1], sizeof(int32_t) * (last - i)); + } + + totems.SetCount(last); + + if (!last) { + totemsEmptied = true; + } + + break; + } + } + } + + uint32_t multiCast; + + for (multiCast = 0; multiCast < 4; multiCast++) { + if (spellId == s_multiCastSpells[multiCast]) { + break; + } + } + + if (multiCast < 4 || totemsEmptied) { + CGActionBar::UpdateMultiCastBar(); + } + + if (removed) { + int32_t skillLine = 0; + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + SkillLineAbilityRec* ability = player->LookupAbility(spellId); + + if (ability) { + const SkillRaceClassInfoRec* info = SpellTableLookupInfo(player->m_unit->m_unitFieldBytes0[0], player->m_unit->m_unitFieldBytes0[1], ability->m_skillLine); + + if (info && info->m_flags >= 0) { + skillLine = info->m_skillID; + } + } + } + + for (uint32_t i = 0; i < s_numSkillInfos; i++) { + SpellBookSkillInfo* skill = s_skillInfos.m_data[i]; + + if (skill->m_skillLine != skillLine) { + continue; + } + + skill->m_count--; + + if (!s_skillInfos.m_data[i]->m_count && i < --s_numSkillInfos) { + for (; i < s_numSkillInfos; i++) { + *s_skillInfos.m_data[i] = *s_skillInfos.m_data[i + 1]; + } + } + + break; + } + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && SpellRec::WillSummonCritter(&spell)) { + uint32_t type = 0; + + if (spell.m_effect[0] != 28) { + type = (spell.m_effectAura[0] != 78) + 1; + } + + TSGrowableArray& companions = (&CGSpellBook::m_companions[0])[type]; + int32_t count = companions.m_count; + bool found = false; + + for (int32_t i = 0; i < count; i++) { + if (companions.m_data[i] == spellId) { + found = true; + } else if (!found) { + continue; + } + + companions.m_data[i] = i == count - 1 ? 0 : companions.m_data[i + 1]; + } + + if (found) { + companions.SetCount(count - 1); + CGSpellBook::UpdateCompanions(); + FrameScript_SignalEvent(SCRIPT_EVENT_COMPANION_UNLEARNED, nullptr); + } + } + + CGSpellBook::UpdateSpells(removed, 0, 1); +} diff --git a/WoW/Source/Ui/SpellBookFrame.h b/WoW/Source/Ui/SpellBookFrame.h index ffee7dc..d3ef5a7 100644 --- a/WoW/Source/Ui/SpellBookFrame.h +++ b/WoW/Source/Ui/SpellBookFrame.h @@ -8,6 +8,7 @@ struct lua_State; class CGUnit_C; +class AuraData; struct SpellUsableInfo { /* 0000 */ int32_t m_spellId; @@ -38,6 +39,7 @@ class SpellRec; class CGSpellBook { public: + static void GetAppropriateSpellRank(uint32_t* spellId, CGUnit_C* caster, CGUnit_C* target); static const char* GetSpellTexture(int32_t slot, int32_t petSpell); static int32_t IsSelectedSlot(int32_t slot, int32_t petSpell); static int32_t FindSpellByName(const char* name, const char* subtext, int32_t* petSpell); @@ -75,12 +77,31 @@ class CGSpellBook { static void MakeKnownSpellModelsLocal(); static int32_t GetSkinningSpell(const CGUnit_C* unit); static void ReplaceSpell(int32_t oldSpell, int32_t newSpell); + static void DelKnownSpell(int32_t spellId, int32_t notify); + static void SendCompanionUpdate(int32_t type); + static int32_t GetSpellRankOrLevel(const SpellRec* spell); + static void PickupSpell(int32_t slot, int32_t petSpell); + static void PickupCompanion(int32_t type, uint32_t index); + static int32_t IsAuraCaster(WOWGUID guid, const WOWGUID* caster); + static int32_t FindRaidDispel(int32_t dispelType); + static bool IsUnlearnedSpell(int32_t spellId); + static void AddPetSpell(int32_t spellId); + static void DelSpellFromNameCache(int32_t spellId, int32_t petSpell); + static uint32_t GetShapeshiftForm(int32_t requireForm); + static int32_t CanShowAura(const SpellRec* spell, const WOWGUID* caster, bool helpful); + static int32_t CanApplyAura(const AuraData* aura); + static int32_t FindRaidBuff(int32_t spellId); + static int32_t IsShapeshiftSpell(int32_t spellId); + static int32_t CanStealAura(const CGUnit_C* unit, const AuraData* aura, const SpellRec* spell); }; int32_t IsValidSpell(const char* name, int32_t* petSpell); int32_t GetSpellSlot(int32_t spellId, int32_t petSpell); int32_t GetSpellIdBySlot(int32_t slot, int32_t petSpell); bool HasSpell(int32_t spellId, int32_t petSpell); +bool HasSpell(uint32_t spellId); +void ClearPetSpellInfo(); +extern const char* s_companionTypes[2]; extern TSGrowableArray s_shapeshiftSpells; extern uint32_t s_numSkillInfos; extern uint32_t s_unkBE5D88[1024]; @@ -90,31 +111,8 @@ extern uint32_t s_unkBE8D9C; extern TSGrowableArray s_skillInfos; void PrefetchSpellVisuals(int32_t spellId); -int32_t Script_GetSpellLink(lua_State* L); -int32_t Script_GetSpellInfo(lua_State* L); -int32_t Script_GetSpellAutocast(lua_State* L); -int32_t Script_ToggleSpellAutocast(lua_State* L); -int32_t Script_EnableSpellAutocast(lua_State* L); -int32_t Script_DisableSpellAutocast(lua_State* L); -int32_t Script_PickupSpell(lua_State* L); -int32_t Script_CastSpell(lua_State* L); -int32_t Script_IsCurrentSpell(lua_State* L); -int32_t Script_IsUsableSpell(lua_State* L); -int32_t Script_SpellHasRange(lua_State* L); -int32_t Script_IsSpellInRange(lua_State* L); -int32_t Script_GetShapeshiftForm(lua_State* L); -int32_t Script_CancelShapeshiftForm(lua_State* L); -int32_t Script_GetShapeshiftFormInfo(lua_State* L); -int32_t Script_CastShapeshiftForm(lua_State* L); -int32_t Script_GetShapeshiftFormCooldown(lua_State* L); -int32_t Script_CastSpellByName(lua_State* L); -int32_t Script_CastSpellByID(lua_State* L); -int32_t Script_GetCompanionCooldown(lua_State* L); -int32_t Script_PickupCompanion(lua_State* L); -int32_t Script_CallCompanion(lua_State* L); -int32_t Script_DismissCompanion(lua_State* L); -int32_t Script_SummonRandomCritter(lua_State* L); void SpellBookRegisterScriptFunctions(); +void SpellBookUnregisterScriptFunctions(); int32_t GetActionBarPageOffset(const CGPlayer_C* player, const SpellRec* spell); int __cdecl SortSpellUsableInfo(const void* a, const void* b); diff --git a/WoW/Source/Ui/SpellBookFrame_Scripts.cpp b/WoW/Source/Ui/SpellBookFrame_Scripts.cpp index bea1d40..8e4d9ea 100644 --- a/WoW/Source/Ui/SpellBookFrame_Scripts.cpp +++ b/WoW/Source/Ui/SpellBookFrame_Scripts.cpp @@ -16,9 +16,19 @@ #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/Magic/MagicClient/Spell_C.h" #include "WoW/Source/Ui/PetInfo.h" +#include "Engine/Source/Tempest/CMath.h" +#include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "WoW/Source/Ui/TradeSkillFrame.h" +#include "WoW/Source/UIUtil/Tooltip.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/Net/Types.h" +#include "Engine/Source/Base/CDataStore.h" // STATIC: 0x00ACCCC4 -static const char* s_companionTypes[2] = { "CRITTER", "MOUNT" }; +const char* s_companionTypes[2] = { "CRITTER", "MOUNT" }; // VERIFY: d9335da2 manual // OFFSET: 0x0053C0B0 @@ -519,6 +529,738 @@ static int32_t Script_GetSpellCooldown(lua_State* L) { return 3; } +// VERIFY: 14043ab6 manual +// OFFSET: 0x00541010 +static int32_t Script_GetSpellAutocast(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + uint32_t* action = nullptr; + int32_t spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + + if (petSpell && (action = CGPetInfo::GetPetSpellAction(spellId)) && (*action & 0x80000000)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (action && (*action & 0x40000000)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 2; +} + +// VERIFY: f7b499fd auto +// OFFSET: 0x005410E0 +static int32_t Script_ToggleSpellAutocast(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (GetSlotFromLua(L, &slot, &petSpell, nullptr, 1) && petSpell && slot < 1024 && s_petSpellList[slot]) { + CGPetInfo::SetSpellAutocast(s_petSpellList[slot], -1); + } + + return 0; +} + +// VERIFY: 7ac0a6a3 auto +// OFFSET: 0x00541140 +static int32_t Script_EnableSpellAutocast(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (GetSlotFromLua(L, &slot, &petSpell, nullptr, 1) && petSpell && slot < 1024 && s_petSpellList[slot]) { + CGPetInfo::SetSpellAutocast(s_petSpellList[slot], 1); + } + + return 0; +} + +// VERIFY: e8d81005 auto +// OFFSET: 0x005411A0 +static int32_t Script_DisableSpellAutocast(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (GetSlotFromLua(L, &slot, &petSpell, nullptr, 1) && petSpell && slot < 1024 && s_petSpellList[slot]) { + CGPetInfo::SetSpellAutocast(s_petSpellList[slot], 0); + } + + return 0; +} + +// VERIFY: 155d2aba auto +// OFFSET: 0x00541200 +static int32_t Script_PickupSpell(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + CGSpellBook::PickupSpell(slot, petSpell); + } + + return 0; +} + +// VERIFY: 73de6661 auto +// OFFSET: 0x00541250 +static int32_t Script_CastSpell(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (GetSlotFromLua(L, &slot, &petSpell, nullptr, 0)) { + WOWGUID target = CGGameUI::m_lockedTarget; + + if (StringToBOOL(L, 3, 0)) { + target = ClntObjMgrGetActivePlayer(); + } + + CGSpellBook::CastSpell(slot, petSpell, target); + } + + return 0; +} + +// VERIFY: 37a181ff manual +// OFFSET: 0x00541500 +static int32_t Script_IsCurrentSpell(lua_State* L) { + int32_t spellId; + + if (lua_isnumber(L, 1) && lua_gettop(L) == 1) { + spellId = lua_tointeger(L, 1); + } else { + uint32_t slot = 0; + int32_t petSpell; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + } + + if (Spell_C_IsCurrentSpell(spellId)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: 6c00b0fc manual +// OFFSET: 0x00541680 +static int32_t Script_IsUsableSpell(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + bool noMana = false; + SpellRec spell; + int32_t spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + CGUnit_C* caster; + + if (g_spellDB.GetRecord(spellId, &spell) + && (caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : static_cast(ClntObjMgrGetActivePlayerObj())) + && Spell_C_IsUsableAction(caster, &spell, WOWGUID{ 0 }, nullptr, false) + && !(noMana = !Spell_C_HaveSpellPower(caster, &spell))) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (noMana) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 2; +} + +// VERIFY: c550d244 manual +// OFFSET: 0x00541AF0 +static int32_t Script_SpellHasRange(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + SpellRec spell; + int32_t spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + CGUnit_C* caster; + float minRange; + float maxRange; + + if (g_spellDB.GetRecord(spellId, &spell) + && (caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : static_cast(ClntObjMgrGetActivePlayerObj()))) { + Spell_C_GetMinMaxRange(caster, &spell, &minRange, &maxRange, nullptr); + + if (fnotequal(minRange, 0.0f) || fnotequal(maxRange, 0.0f)) { + lua_pushnumber(L, 1.0); + return 1; + } + } + + lua_pushnil(L); + return 1; +} + +// VERIFY: 3ecc20db manual +// OFFSET: 0x00541C60 +static int32_t Script_IsSpellInRange(lua_State* L) { + uint32_t slot = 0; + int32_t petSpell; + int32_t unitIndex; + + if (!GetSlotFromLua(L, &slot, &petSpell, &unitIndex, 1)) { + return 0; + } + + SpellRec spell; + int32_t spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + CGUnit_C* caster; + WOWGUID target; + uint8_t inRange; + + if (g_spellDB.GetRecord(spellId, &spell) + && (caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : static_cast(ClntObjMgrGetActivePlayerObj())) + && Script_GetGUIDFromToken(lua_tolstring(L, unitIndex, nullptr), target, true) + && Spell_C_RangeCheckSelected(caster, &spell, target, &inRange, false, nullptr)) { + lua_pushnumber(L, inRange ? 1.0 : 0.0); + return 1; + } + + lua_pushnil(L); + return 1; +} + +// VERIFY: 6fbd2312 manual +// OFFSET: 0x0053C0F0 +static int32_t Script_CastShapeshiftForm(lua_State* L) { + if (lua_tonumber(L, 1) == 0.0) { + luaL_error(L, "Usage: CastShapeshiftForm(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + + if (index < s_shapeshiftSpells.m_count) { + Spell_C_ClickSpell(s_shapeshiftSpells.m_data[index].m_spellId, nullptr, WOWGUID{ 0 }); + } + + return 0; +} + +// VERIFY: f541320c manual +// OFFSET: 0x0053C180 +static int32_t Script_GetShapeshiftFormCooldown(lua_State* L) { + if (lua_tonumber(L, 1) == 0.0) { + luaL_error(L, "Usage: GetShapeshiftFormCooldown(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + + if (index >= s_shapeshiftSpells.m_count) { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 1.0); + return 3; + } + + uint32_t start = 0; + uint32_t duration = 0; + uint32_t enable = 0; + Spell_C_GetSpellCooldown(s_shapeshiftSpells.m_data[index].m_spellId, 0, &duration, &start, &enable); + lua_pushnumber(L, start * 0.001); + lua_pushnumber(L, duration * 0.001); + lua_pushnumber(L, enable); + return 3; +} + +// VERIFY: e1e722df manual +// OFFSET: 0x0053C310 +static int32_t Script_PickupCompanion(lua_State* L) { + int32_t type; + + if (!GetLuaCompanionType(L, &type) || lua_tonumber(L, 2) == 0.0) { + luaL_error(L, "Usage: PickupCompanion(type, index)"); + } + + CGSpellBook::PickupCompanion(type, static_cast(lua_tonumber(L, 2)) - 1); + return 0; +} + +// VERIFY: a881f31c manual +// OFFSET: 0x0053DE10 +static int32_t Script_GetShapeshiftForm(lua_State* L) { + lua_pushnumber(L, CGSpellBook::GetShapeshiftForm(StringToBOOL(L, 1, 0))); + return 1; +} + +// VERIFY: 0cf3162e manual +// OFFSET: 0x0053DE60 +static int32_t Script_CancelShapeshiftForm(lua_State* L) { + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->CancelShapeshift(); + } + + return 0; +} + +// VERIFY: a14701fb manual +// OFFSET: 0x0053DE90 +static int32_t Script_GetShapeshiftFormInfo(lua_State* L) { + if (lua_tonumber(L, 1) == 0.0) { + luaL_error(L, "Usage: GetShapeshiftFormInfo(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if (index >= s_shapeshiftSpells.m_count || !player) { + return 0; + } + + SpellRec spell; + SpellUsableInfo* info = &s_shapeshiftSpells.m_data[index]; + + if (!g_spellDB.GetRecord(info->m_spellId, &spell)) { + return 0; + } + + bool active = Spell_C_IsActiveSpell(&spell, player); + bool castable; + int32_t iconId; + + if (!active && (!info->m_usable || info->m_noMana)) { + castable = false; + iconId = spell.m_spellIconID; + } else { + castable = true; + iconId = active && spell.m_activeIconID ? spell.m_activeIconID : spell.m_spellIconID; + } + + SpellIconRec* icon = g_spellIconDB.GetRecord(iconId); + + if (icon) { + lua_pushstring(L, icon->m_textureFilename); + } else { + lua_pushnil(L); + } + + lua_pushstring(L, spell.m_name); + + if (active) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (castable) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 4; +} + +// VERIFY: 6ea2bbc3 manual +// OFFSET: 0x0053E490 +static int32_t Script_GetCompanionCooldown(lua_State* L) { + int32_t type; + + if (!GetLuaCompanionType(L, &type) || lua_tonumber(L, 2) == 0.0) { + luaL_error(L, "Usage: GetCompanionCooldown(type, index)"); + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return 0; + } + + uint32_t index = static_cast(lua_tonumber(L, 2)) - 1; + + if (index >= CGSpellBook::m_companions[type].m_count) { + return 0; + } + + uint32_t start = 0; + uint32_t duration = 0; + uint32_t enable = 0; + Spell_C_GetSpellCooldown(CGSpellBook::m_companions[type].m_data[index], 0, &duration, &start, &enable); + lua_pushnumber(L, start * 0.001); + lua_pushnumber(L, duration * 0.001); + lua_pushnumber(L, enable); + return 3; +} + +// VERIFY: 49d0349b manual +// OFFSET: 0x0053E5E0 +static int32_t Script_CallCompanion(lua_State* L) { + int32_t type; + + if (!GetLuaCompanionType(L, &type) || lua_tonumber(L, 2) == 0.0) { + luaL_error(L, "Usage: CallCompanion(type, index)"); + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return 0; + } + + uint32_t index = static_cast(lua_tonumber(L, 2)) - 1; + + if (index >= CGSpellBook::m_companions[type].m_count) { + return 0; + } + + Spell_C::CastSpell(CGSpellBook::m_companions[type].m_data[index], nullptr, WOWGUID{ 0 }, false); + return 0; +} + +// VERIFY: 88b08790 manual +// OFFSET: 0x0053E6B0 +static int32_t Script_DismissCompanion(lua_State* L) { + int32_t type; + + if (!GetLuaCompanionType(L, &type)) { + luaL_error(L, "Usage: DismissCompanion(type)"); + } + + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + for (uint32_t i = 0; i < CGSpellBook::m_companions[type].m_count; i++) { + SpellRec spell; + + if (g_spellDB.GetRecord(CGSpellBook::m_companions[type].m_data[i], &spell) && Spell_C_IsActiveSpell(&spell, player)) { + Spell_C_CancelAura(&spell, player, -1); + } + } + + return 0; +} + +// VERIFY: d79d2bf4 manual +// OFFSET: 0x0053E7E0 +static int32_t Script_SummonRandomCritter(lua_State* L) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + player->CastRandomCritter(); + } + + return 1; +} + +// VERIFY: 23b3df80 manual +// OFFSET: 0x0053E060 +static int32_t Script_CastSpellByID(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CastSpellByID(spellID[, target])"); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return 0; + } + + WOWGUID target; + + if (!Script_GetGUIDFromToken(lua_tolstring(L, 2, nullptr), target, true)) { + return 0; + } + + int32_t spellId = lua_tointeger(L, 1); + + if (!spellId) { + return 0; + } + + if (GetSpellSlot(spellId, 0) >= 0) { + Spell_C::CastSpell(spellId, nullptr, target, false); + return 0; + } + + if (!CGPetInfo::PetActionsUsable(false)) { + return 0; + } + + uint32_t petAction = 0; + uint32_t* action = CGPetInfo::FindSpellByID(spellId); + + if (!action) { + if (GetSpellSlot(spellId, 1) < 0) { + return 0; + } + + petAction = spellId | 0x1000000; + action = &petAction; + } + + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!pet) { + return 0; + } + + SpellRec spell; + g_spellDB.GetRecord(spellId, &spell); + + if (!(spell.m_attributesExD & 0x20) && player->GetPossessedUnit() != pet) { + Spell_C_StartSpellCooldown(&spell, pet); + + CDataStore msg; + msg.Put(static_cast(CMSG_PET_ACTION)); + msg.Put(CGPetInfo::GetPet(0).m_guid); + msg.Put(*action); + msg.Put(target.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + return 0; + } + + Spell_C_CastSpell(pet, spell.m_id, nullptr, target, nullptr, false); + return 0; +} + +// VERIFY: 067d4c88 manual +// OFFSET: 0x00540310 +static int32_t Script_CastSpellByName(lua_State* L) { + if (!lua_isstring(L, 1)) { + luaL_error(L, "Usage: CastSpellByName(name[, target])"); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return 0; + } + + WOWGUID target; + + if (!Script_GetGUIDFromToken(lua_tolstring(L, 2, nullptr), target, true)) { + return 0; + } + + const char* name = lua_tolstring(L, 1, nullptr); + int32_t petSpell; + int32_t spellId = GetSpellIdByName(name, &petSpell); + + if (!spellId) { + return 0; + } + + if (*name != '!') { + int32_t slot = GetSpellSlot(spellId, petSpell); + + if (slot >= 0) { + CGSpellBook::CastSpell(slot, petSpell, target); + return 0; + } + + uint32_t* action = CGPetInfo::FindSpellByID(spellId); + + if (action) { + CGPetInfo::SendPetAction(*action, target, 0); + return 0; + } + + if (!petSpell) { + Spell_C_ClickSpell(spellId, nullptr, target); + } + + return 0; + } + + if (!petSpell) { + Spell_C::CastSpell(spellId, nullptr, target, false); + return 0; + } + + if (!CGPetInfo::PetActionsUsable(false)) { + return 0; + } + + uint32_t petAction = 0; + uint32_t* action = CGPetInfo::FindSpellByID(spellId); + + if (!action) { + if (GetSpellSlot(spellId, petSpell) < 0) { + return 0; + } + + petAction = spellId | 0x1000000; + action = &petAction; + } + + CGUnit_C* pet = static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (!pet) { + return 0; + } + + SpellRec spell; + g_spellDB.GetRecord(spellId, &spell); + + if ((spell.m_attributesExD & 0x20) || player->GetPossessedUnit() == pet) { + Spell_C_CastSpell(pet, spell.m_id, nullptr, target, nullptr, false); + return 0; + } + + Spell_C_StartSpellCooldown(&spell, pet); + + CDataStore msg; + msg.Put(static_cast(CMSG_PET_ACTION)); + msg.Put(CGPetInfo::GetPet(0).m_guid); + msg.Put(*action); + msg.Put(target.m_guid); + msg.Finalize(); + ClientServices::Send2(&msg); + return 0; +} + +// VERIFY: cfe51b8e manual +// OFFSET: 0x005408E0 +static int32_t Script_GetSpellLink(lua_State* L) { + int32_t spellId; + + if (lua_isnumber(L, 1) && lua_gettop(L) == 1) { + spellId = static_cast(lua_tonumber(L, 1)); + } else { + uint32_t slot = 0; + int32_t petSpell; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + } + + SpellRec spell; + char link[256]; + + if (!g_spellDB.GetRecord(spellId, &spell) || ((spell.m_attributes & 0x80) && (spell.m_attributes & 0x100))) { + lua_pushnil(L); + lua_pushnil(L); + return 2; + } + + lua_pushstring(L, CGTooltip::GetSpellLink(spellId)); + + if (!CGTradeSkillInfo::GetTradeSkillListLink(spellId, link, sizeof(link))) { + lua_pushnil(L); + return 2; + } + + lua_pushstring(L, link); + return 2; +} + +// VERIFY: 2db217bf manual +// OFFSET: 0x00540A30 +static int32_t Script_GetSpellInfo(lua_State* L) { + int32_t petSpell = 0; + int32_t spellId; + + if (lua_isnumber(L, 1) && lua_gettop(L) == 1) { + spellId = static_cast(lua_tonumber(L, 1)); + } else { + uint32_t slot = 0; + + if (!GetSlotFromLua(L, &slot, &petSpell, nullptr, 1)) { + return 0; + } + + spellId = static_cast(slot) < 0 ? 0 : petSpell ? (slot < 1024 ? s_petSpellList[slot] : 0) : (slot < s_numSpells ? s_spellList[slot] : 0); + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(spellId, &spell)) { + return 0; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + CGUnit_C* caster = petSpell ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : player; + + lua_pushstring(L, spell.m_name); + lua_pushstring(L, spell.m_nameSubtext); + + const char* texture = ""; + + if (spell.m_effect[0] == 78) { + texture = CGActionBar::GetAttackTexture(); + } else if ((spell.m_attributes & 0x2) && (spell.m_attributesExB & 0x20)) { + texture = CGActionBar::GetRangedTexture(); + } else { + SpellIconRec* icon = g_spellIconDB.GetRecord(spell.m_spellIconID); + + if (icon) { + texture = icon->m_textureFilename; + } + } + + lua_pushstring(L, texture); + + uint32_t powerCost = Spell_C_GetPowerCost(&spell, caster); + uint32_t powerCostPerSecond = Spell_C_GetPowerCostPerSecond(&spell, caster); + uint32_t cost = powerCost / Spell_C_GetPowerDisplayMod(spell.m_powerType); + int32_t costPerSecond = powerCostPerSecond / Spell_C_GetPowerDisplayMod(spell.m_powerType); + + if (costPerSecond <= 0) { + lua_pushnumber(L, cost); + lua_pushboolean(L, 0); + } else { + lua_pushnumber(L, costPerSecond); + lua_pushboolean(L, 1); + } + + lua_pushnumber(L, spell.m_powerType); + + if (spell.m_attributes & 0x40) { + lua_pushnumber(L, 0.0); + } else { + lua_pushnumber(L, static_cast(SpellRec::GetCastTime(&spell, petSpell, 0, 1))); + } + + if (!player || !caster) { + return 7; + } + + if (SpellRec::IsMeleeRange(&spell)) { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + return 9; + } + + float minRange = 0.0f; + float maxRange = 0.0f; + Spell_C_GetMinMaxRange(caster, &spell, &minRange, &maxRange, nullptr); + + if (SpellRec::IsMinimumRange(&spell)) { + SpellRec::GetMinRange(&spell, &minRange); + } + + lua_pushnumber(L, minRange); + lua_pushnumber(L, maxRange); + return 9; +} + // STATIC: 0x00ACCCE0 static FrameScript_Method s_ScriptFunctions[] = { { "GetNumSpellTabs", &Script_GetNumSpellTabs }, @@ -575,3 +1317,11 @@ void SpellBookRegisterScriptFunctions() { FrameScript_RegisterFunction(s_ScriptFunctions[i].m_name, s_ScriptFunctions[i].m_method); } } + +// VERIFY: c614d7c6 auto +// OFFSET: 0x0053B770 +void SpellBookUnregisterScriptFunctions() { + for (uint32_t i = 0; i < sizeof(s_ScriptFunctions) / sizeof(s_ScriptFunctions[0]); i++) { + FrameScript_UnregisterFunction(s_ScriptFunctions[i].m_name); + } +} diff --git a/WoW/Source/Ui/StableInfo.cpp b/WoW/Source/Ui/StableInfo.cpp index c7cd839..59099df 100644 --- a/WoW/Source/Ui/StableInfo.cpp +++ b/WoW/Source/Ui/StableInfo.cpp @@ -1,12 +1,25 @@ #include "StableInfo.h" +#include #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/GameUI.h" #include "WoW/Source/Ui/Types.h" +// STATIC: 0x00C0F480 +StablePetInfo CGStableInfo::m_pets[6]; + // STATIC: 0x00C0F6C0 WOWGUID CGStableInfo::m_stableMaster; +// STATIC: 0x00C0F6C8 +int32_t CGStableInfo::unk_C0F6C8; + +// STATIC: 0x00C0F6CC +int32_t CGStableInfo::unk_C0F6CC; + +// STATIC: 0x00C0F6D0 +int32_t CGStableInfo::unk_C0F6D0; + // VERIFY: da4c52c5 auto // OFFSET: 0x005A1ED0 void CGStableInfo::InitializeGame() { @@ -25,3 +38,13 @@ void CGStableInfo::CloseStables(bool force) { CGStableInfo::m_stableMaster = WOWGUID(); FrameScript_SignalEvent(SCRIPT_EVENT_PET_STABLE_CLOSED, nullptr); } + +// VERIFY: 8f51bf00 auto +// OFFSET: 0x005A0EC0 +void CGStableInfo::EnterWorld() { + CGStableInfo::m_stableMaster = WOWGUID{ 0 }; + CGStableInfo::unk_C0F6C8 = 0; + CGStableInfo::unk_C0F6CC = 0; + CGStableInfo::unk_C0F6D0 = 0; + memset(&CGStableInfo::m_pets[0], 0, sizeof(CGStableInfo::m_pets[0])); +} diff --git a/WoW/Source/Ui/StableInfo.h b/WoW/Source/Ui/StableInfo.h index 311e8cd..8480034 100644 --- a/WoW/Source/Ui/StableInfo.h +++ b/WoW/Source/Ui/StableInfo.h @@ -7,9 +7,23 @@ struct lua_State; +struct StablePetInfo { + /* 0000 */ int32_t unk_0000; + /* 0004 */ int32_t unk_0004; + /* 0008 */ int32_t unk_0008; + /* 000C */ char m_name[80]; + /* 005C */ uint8_t unk_005C; + /* 005D */ uint8_t unk_005D[3]; +}; + class CGStableInfo { public: + static StablePetInfo m_pets[6]; static WOWGUID m_stableMaster; + static int32_t unk_C0F6C8; + static int32_t unk_C0F6CC; + static int32_t unk_C0F6D0; + static void CloseStables(bool force); static void EnterWorld(); static void InitializeGame(); diff --git a/WoW/Source/Ui/TalentInfo.cpp b/WoW/Source/Ui/TalentInfo.cpp index 860ff28..a162802 100644 --- a/WoW/Source/Ui/TalentInfo.cpp +++ b/WoW/Source/Ui/TalentInfo.cpp @@ -2,6 +2,17 @@ #include "WoW/Source/Object/ObjectClient/Unit_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/PetInfo.h" +#include +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/TalentRec.h" +#include "WoW/Source/DB/Rec/TalentTabRec.h" +#include "WoW/Source/DB/Rec/CreatureFamilyRec.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Ui/Types.h" +#include "Engine/Source/lua-5.1/src/lua.h" // STATIC: 0x00C21008 WOWGUID CGTalentInfo_Inspect::m_inspectTarget; @@ -30,6 +41,24 @@ CGTalentGroup_C CGTalentInfo::m_talentGroups[2]; // STATIC: 0x00C210D8 CGTalentGroup_C CGTalentInfo::m_petTalentGroup; +// STATIC: 0x00C20FF0 +int32_t CGTalentInfo::m_tabsInitialized; + +// STATIC: 0x00C20FFC +int32_t CGTalentInfo::m_unspentTalentPoints; + +// STATIC: 0x00C21010 +uint32_t CGTalentInfo_Inspect::m_numTalentGroups; + +// STATIC: 0x00C21014 +int32_t CGTalentInfo_Inspect::m_unspentTalentPoints; + +// STATIC: 0x00C2112C +TSFixedArray CGTalentInfo_Inspect::m_tabs; + +// STATIC: 0x00C21138 +CGTalentGroup_C CGTalentInfo_Inspect::m_talentGroups[2]; + // VERIFY: 05fa25fb auto // OFFSET: 0x005C57C0 void CGTalentInfo_Inspect::EnterWorld() { @@ -82,9 +111,9 @@ uint32_t CGTalentInfo::GetActiveTalentGroup(int32_t pet) { return pet == 0 ? CGTalentInfo::m_activeTalentGroup : 0; } -// VERIFY: 9f283c28 auto +// VERIFY: 34afe472 auto // OFFSET: 0x005C5B30 -TalentGroupTab* CGTalentGroup_C::GetTabFromID(int32_t tabId) { +TalentGroupTab_C* CGTalentGroup_C::GetTabFromID(int32_t tabId) { for (uint32_t i = 0; i < this->m_tabs.m_count; i++) { if (this->m_tabs.m_data[i].m_tabId == tabId) { return &this->m_tabs.m_data[i]; @@ -166,3 +195,1027 @@ int32_t TalentInfoIsSpellKnown(int32_t spellId, int32_t isInspect, int32_t isPet return unit->IsSpellKnown(spellId) || unit->IsSpellSuperceded(spellId); } + +// VERIFY: 7cbaa1c1 auto +// OFFSET: 0x005C5750 +static int TierCompare(const void* a, const void* b) { + return (*static_cast(a))->m_tier - (*static_cast(b))->m_tier; +} + +// VERIFY: 2584c2bc auto +// OFFSET: 0x005C5770 +uint32_t CGTalentGroup_C::GetGlyph(uint32_t index) { + return index < 6 ? this->m_glyphs[index] : 6; +} + +// VERIFY: 577e032d auto +// OFFSET: 0x005C5790 +void CGTalentInfo::LeaveWorld() { + CGTalentInfo::m_tabsInitialized = 0; + CGTalentInfo::m_petTalentTab = 0; +} + +// VERIFY: 0d3d49d3 auto +// OFFSET: 0x005C57D0 +uint32_t TalentInfoGetScriptGroupIndex(lua_State* L, int32_t index) { + if (lua_isnumber(L, index)) { + return lua_tointeger(L, index) - 1; + } + + return CGTalentInfo::m_activeTalentGroup; +} + +// VERIFY: 09a769af manual +// OFFSET: 0x005C5A20 +int32_t CGTalentInfo::IsTalentAvailableForPet(CGUnit_C* pet, const TalentRec* talent) { + if (!pet || !talent) { + return 0; + } + + CreatureFamilyRec* family = g_creatureFamilyDB.GetRecord(pet->GetCreatureFamily()); + + if (!family) { + return 0; + } + + int32_t category = family->m_categoryEnumID; + uint32_t word = 0; + uint8_t bit = 0; + + if (category >= 0) { + word = category / 32; + + if (word > 2) { + return 0; + } + + bit = category % 32; + } + + for (uint32_t i = 0; !talent->m_categoryMask[i]; i++) { + if (i + 1 >= 2) { + return 1; + } + } + + return category < 0 || (talent->m_categoryMask[word] & (1 << bit)) != 0; +} + +// VERIFY: 6d864da3 manual +// OFFSET: 0x005C5AC0 +TalentGroupTier_C* TalentGroupTab_C::FindTier(int32_t tier) { + int32_t low = 0; + int32_t high = this->m_tiers.m_count - 1; + + while (low <= high) { + uint32_t mid = static_cast(low + high) >> 1; + TalentGroupTier_C* entry = this->m_tiers.m_data[mid]; + + if (entry) { + if (entry->m_tier < tier) { + low = mid + 1; + } else if (entry->m_tier > tier) { + high = mid - 1; + } else { + return entry; + } + } + } + + return nullptr; +} + +// VERIFY: af668ec5 auto +// OFFSET: 0x005C5B00 +TalentGroupTab_C* CGTalentGroup_C::GetTab(uint32_t index) { + return index < this->m_tabs.m_count ? &this->m_tabs.m_data[index] : nullptr; +} + +// VERIFY: 70c6be1a auto +// OFFSET: 0x005C5B70 +TalentGroupTab_C* CGTalentGroup_C::GetTabFromTalentID(int32_t talentId) { + TalentRec* talent = g_talentDB.GetRecord(talentId); + + if (!talent) { + return nullptr; + } + + return this->GetTabFromID(talent->m_tabID); +} + +// VERIFY: 9f0c24f3 auto +// OFFSET: 0x005C5C60 +TalentTabInfo* CGTalentInfo::GetTab(uint32_t index, int32_t inspect, int32_t pet) { + if (inspect) { + if (!pet && index < CGTalentInfo_Inspect::m_tabs.m_count) { + return CGTalentInfo_Inspect::m_tabs.m_data[index]; + } + } else if (pet) { + if (index < CGTalentInfo::m_petTabs.m_count) { + return CGTalentInfo::m_petTabs.m_data[index]; + } + } else if (index < CGTalentInfo::m_tabs.m_count) { + return CGTalentInfo::m_tabs.m_data[index]; + } + + return nullptr; +} + +// VERIFY: 9f151dec manual +// OFFSET: 0x005C6010 +int32_t CGTalentInfo::GetPreviewPointsSpent(uint32_t group, int32_t pet) { + CGTalentGroup_C* talentGroup = CGTalentInfo::GetTalentGroup(group, pet); + + if (!talentGroup) { + return 0; + } + + int32_t total = 0; + + for (uint32_t i = 0; i < talentGroup->m_tabs.m_count; i++) { + total += talentGroup->m_tabs.m_data[i].m_previewPointsSpent; + } + + return total; +} + +// VERIFY: ccdc02e4 manual +// OFFSET: 0x005C6080 +CGTalentGroup_C* TalentInfoGetTalentGroup(uint32_t index, int32_t inspect, int32_t pet) { + if (!inspect) { + return CGTalentInfo::GetTalentGroup(index, pet); + } + + if (pet || index >= CGTalentInfo_Inspect::m_numTalentGroups) { + return nullptr; + } + + return &CGTalentInfo_Inspect::m_talentGroups[index]; +} + +// VERIFY: f000d43c manual +// OFFSET: 0x005C64D0 +static void BuildTabInfo(CGPlayer_C* player, TSFixedArray* tabs, int32_t family) { + if (!tabs) { + return; + } + + int32_t petTalentType = -1; + + if (!player) { + CreatureFamilyRec* familyRec = g_creatureFamilyDB.GetRecord(family); + + if (!familyRec) { + return; + } + + petTalentType = familyRec->m_petTalentType; + + if (petTalentType < 0) { + return; + } + } + + uint32_t numTabs = g_talentTabDB.m_numRecords; + uint32_t count = 0; + + for (uint32_t i = 0; i < numTabs; i++) { + TalentTabRec* tab = g_talentTabDB.GetRecordByIndex(i); + + if (player) { + if (tab->m_raceMask) { + if (!(tab->m_raceMask & (1 << (player->m_unit->m_unitFieldBytes0[0] - 1)))) { + continue; + } + + if (tab->m_classMask && !(tab->m_classMask & (1 << (player->m_unit->m_unitFieldBytes0[1] - 1)))) { + continue; + } + } else if (!tab->m_classMask || !(tab->m_classMask & (1 << (player->m_unit->m_unitFieldBytes0[1] - 1)))) { + continue; + } + } else if (!tab->m_categoryEnumID || petTalentType < 0 || !(tab->m_categoryEnumID & (1 << petTalentType))) { + continue; + } + + count++; + } + + for (uint32_t i = 0; i < tabs->m_count; i++) { + if (tabs->m_data[i]) { + delete tabs->m_data[i]; + } + + tabs->m_data[i] = nullptr; + } + + tabs->SetCount(count); + + uint32_t index = 0; + + for (uint32_t i = 0; i < numTabs; i++) { + TalentTabRec* tab = g_talentTabDB.GetRecordByIndex(i); + + if (player) { + if (tab->m_raceMask) { + if (!(tab->m_raceMask & (1 << (player->m_unit->m_unitFieldBytes0[0] - 1)))) { + continue; + } + + if (tab->m_classMask && !(tab->m_classMask & (1 << (player->m_unit->m_unitFieldBytes0[1] - 1)))) { + continue; + } + } else if (!tab->m_classMask || !(tab->m_classMask & (1 << (player->m_unit->m_unitFieldBytes0[1] - 1)))) { + continue; + } + } else if (!tab->m_categoryEnumID || petTalentType < 0 || !(tab->m_categoryEnumID & (1 << petTalentType))) { + continue; + } + + tabs->m_data[index] = static_cast(SMemAlloc(sizeof(TalentTabInfo), __FILE__, __LINE__, 0)); + tabs->m_data[index]->m_tabId = tab->m_id; + tabs->m_data[index]->m_numTalents = 0; + tabs->m_data[index]->m_talents = nullptr; + index++; + + if (index == count) { + break; + } + } + + int32_t lastTabId = -1; + TalentTabInfo* info = nullptr; + int32_t numTalents = g_talentDB.m_numRecords; + + for (int32_t i = 0; i < numTalents; i++) { + TalentRec* talent = g_talentDB.GetRecordByIndex(i); + int32_t tabId = talent->m_tabID; + + if (tabId == lastTabId) { + if (info) { + info->m_numTalents++; + } + + continue; + } + + info = nullptr; + lastTabId = tabId; + + for (uint32_t j = 0; j < count; j++) { + if (tabs->m_data[j]->m_tabId == tabId) { + info = tabs->m_data[j]; + info->m_talents = talent; + info->m_numTalents = 1; + break; + } + } + } +} + +// VERIFY: 7e295b15 manual +// OFFSET: 0x005C6880 +void CGTalentInfo::ResetTabInfo(int32_t pet) { + if (pet) { + for (uint32_t i = 0; i < CGTalentInfo::m_petTabs.m_count; i++) { + if (CGTalentInfo::m_petTabs.m_data[i]) { + delete CGTalentInfo::m_petTabs.m_data[i]; + } + + CGTalentInfo::m_petTabs.m_data[i] = nullptr; + } + + CGTalentInfo::m_petTabs.Clear(); + } else { + for (uint32_t i = 0; i < CGTalentInfo::m_tabs.m_count; i++) { + if (CGTalentInfo::m_tabs.m_data[i]) { + delete CGTalentInfo::m_tabs.m_data[i]; + } + + CGTalentInfo::m_tabs.m_data[i] = nullptr; + } + + CGTalentInfo::m_tabs.Clear(); + } +} + +// VERIFY: 4ade9896 manual +// OFFSET: 0x005C6980 +void CGTalentInfo_Inspect::ResetTabInfo() { + for (uint32_t i = 0; i < CGTalentInfo_Inspect::m_tabs.m_count; i++) { + if (CGTalentInfo_Inspect::m_tabs.m_data[i]) { + delete CGTalentInfo_Inspect::m_tabs.m_data[i]; + } + + CGTalentInfo_Inspect::m_tabs.m_data[i] = nullptr; + } + + CGTalentInfo_Inspect::m_tabs.Clear(); +} + +// VERIFY: 8281146a manual +// OFFSET: 0x005C6F20 +void CGTalentGroup_C::ResetPreviewTalentPoints(uint32_t tabIndex) { + if (tabIndex >= this->m_tabs.m_count) { + return; + } + + for (uint32_t i = 0; i < this->m_tabs.m_data[tabIndex].m_tiers.m_count; i++) { + TalentGroupTier_C* tier = this->m_tabs.m_data[tabIndex].m_tiers.m_data[i]; + + for (TalentGroupTierItem_C* node = tier->m_items.m_fulllist.Head(); node; node = tier->m_items.Next(node)) { + node->m_item->m_previewRank = node->m_item->m_rank; + } + } + + this->m_tabs.m_data[tabIndex].m_previewPointsSpent = 0; +} + +// VERIFY: a371eed5 manual +// OFFSET: 0x005C6FB0 +void CGTalentGroup_C::ResetAllPreviewTalentPoints() { + for (TalentGroupItem_C* item = this->m_items.m_fulllist.Head(); item; item = this->m_items.Next(item)) { + item->m_previewRank = item->m_rank; + } + + for (uint32_t i = 0; i < this->m_tabs.m_count; i++) { + this->m_tabs.m_data[i].m_previewPointsSpent = 0; + } +} + +// VERIFY: 7ec3d912 manual +// OFFSET: 0x005C7010 +void CGTalentInfo::ResetPreviewTalentPoints(uint32_t group, uint32_t tab, int32_t pet) { + CGTalentGroup_C* talentGroup = CGTalentInfo::GetTalentGroup(group, pet); + + if (talentGroup) { + talentGroup->ResetPreviewTalentPoints(tab); + } +} + +// VERIFY: 4a3205f0 auto +// OFFSET: 0x005C7070 +void CGTalentInfo::ResetGroupPreviewTalentPoints(uint32_t group, int32_t pet) { + CGTalentGroup_C* talentGroup = CGTalentInfo::GetTalentGroup(group, pet); + + if (talentGroup) { + talentGroup->ResetAllPreviewTalentPoints(); + } +} + +// VERIFY: 45900bce auto +// OFFSET: 0x005C73B0 +TalentGroupItem_C* CGTalentGroup_C::GetTalentItem(int32_t talentId) { + HASHKEY_NONE key; + return this->m_items.Ptr(talentId, key); +} + +// VERIFY: be725aca manual +// OFFSET: 0x005C73D0 +int32_t CGTalentGroup_C::ValidatePreviewTalentPoints(uint32_t tabIndex, const TalentRec* talent, int32_t points, int32_t* delta, int32_t pet) { + *delta = 0; + + if (!points) { + return 1; + } + + if (!talent || tabIndex >= this->m_tabs.m_count) { + return 0; + } + + int32_t previewSpent = 0; + + for (uint32_t i = 0; i < this->m_tabs.m_count; i++) { + previewSpent += this->m_tabs.m_data[i].m_previewPointsSpent; + } + + if (static_cast(this->m_unspentPoints - previewSpent) <= 0 && points > 0) { + return 0; + } + + TalentGroupTab_C* tab = &this->m_tabs.m_data[tabIndex]; + + if (!tab) { + return 0; + } + + int32_t talentId = talent->m_id; + int32_t tierId = talent->m_tierID; + int32_t pointsPerTier = 2 * (pet == 0) + 3; + + if (tab->m_pointsSpent + tab->m_previewPointsSpent < static_cast(tierId * pointsPerTier)) { + return 0; + } + + TalentGroupItem_C* item = this->GetTalentItem(talent->m_id); + int32_t rank = item ? item->m_rank : -1; + int32_t previewRank = item ? item->m_previewRank : -1; + + for (uint32_t i = 0; i < 3; i++) { + int32_t prereqId = talent->m_prereqTalent[i]; + + if (prereqId && g_talentDB.GetRecord(prereqId)) { + TalentGroupItem_C* prereq = this->GetTalentItem(prereqId); + + if (!prereq || prereq->m_previewRank < talent->m_prereqRank[i]) { + return 0; + } + } + } + + int32_t maxRank = rank; + + for (int32_t i = 8; i >= 0; i--) { + if (talent->m_spellRank[i]) { + maxRank = i; + break; + } + } + + int32_t room = maxRank - rank; + int32_t wanted = previewRank + points - rank; + int32_t newRank = rank + (wanted < 0 ? 0 : wanted > room ? room : wanted); + int32_t change = newRank - previewRank; + *delta = change; + + if (!change) { + return 0; + } + + if (change >= 0) { + return 1; + } + + for (TalentGroupItem_C* other = this->m_items.m_fulllist.Head(); other; other = this->m_items.Next(other)) { + if (other->m_previewRank < 0) { + continue; + } + + TalentRec* otherTalent = g_talentDB.GetRecord(other->m_talentId); + + if (!otherTalent) { + continue; + } + + for (uint32_t i = 0; i < 3; i++) { + int32_t prereqId = otherTalent->m_prereqTalent[i]; + + if (prereqId && g_talentDB.GetRecord(prereqId) == talent && item && change + item->m_previewRank < otherTalent->m_prereqRank[i]) { + return 0; + } + } + } + + uint32_t numTiers = tab->m_tiers.m_count; + + if (numTiers <= 1) { + return 1; + } + + int32_t total = 0; + + for (uint32_t i = 0; i < numTiers; i++) { + TalentGroupTier_C* tier = tab->m_tiers.m_data[i]; + int32_t tierSpent = 0; + + for (TalentGroupTierItem_C* node = tier->m_items.m_fulllist.Head(); node; node = tier->m_items.Next(node)) { + int32_t spent = node->m_item->m_previewRank + 1; + tierSpent += spent; + total += spent + (node->m_item->m_talentId != talentId ? 0 : change); + } + + if (tierSpent > 0 && tier->m_tier > tierId && total - tierSpent < pointsPerTier * tier->m_tier) { + return 0; + } + } + + return 1; +} + +// VERIFY: ed5f15fd auto +// OFFSET: 0x005C76E0 +int32_t CGTalentGroup_C::CanAddPreviewTalentPoints(const TalentRec* talent, int32_t points, int32_t* delta, int32_t pet) { + *delta = 0; + + if (!points) { + return 1; + } + + if (!talent) { + return 0; + } + + for (uint32_t i = 0; i < this->m_tabs.m_count; i++) { + if (this->m_tabs.m_data[i].m_tabId == talent->m_tabID) { + return this->ValidatePreviewTalentPoints(i, talent, points, delta, pet); + } + } + + return 0; +} + +// VERIFY: b579a45c manual +// OFFSET: 0x005C7750 +TalentGroupItem_C* CGTalentInfo::GetTalentItem(uint32_t group, int32_t talentId, int32_t pet) { + CGTalentGroup_C* talentGroup = CGTalentInfo::GetTalentGroup(group, pet); + + if (!talentGroup) { + return nullptr; + } + + return talentGroup->GetTalentItem(talentId); +} + +// VERIFY: bd3e004d manual +// OFFSET: 0x005C77B0 +TalentGroupItem_C* TalentInfoGetTalentItem(uint32_t group, int32_t talentId, int32_t inspect, int32_t pet) { + if (!inspect) { + return CGTalentInfo::GetTalentItem(group, talentId, pet); + } + + CGTalentGroup_C* talentGroup = TalentInfoGetTalentGroup(group, inspect, pet); + + if (!talentGroup) { + return nullptr; + } + + return talentGroup->GetTalentItem(talentId); +} + +// VERIFY: ebac1df8 auto +// OFFSET: 0x005C8DE0 +TalentGroupTier_C::TalentGroupTier_C() : m_tier(-1) { + this->m_items.Clear(); +} + +// VERIFY: e3c846a1 manual +// OFFSET: 0x005C8E10 +TalentGroupTier_C::~TalentGroupTier_C() { + this->m_items.Clear(); +} + +// INLINED +TalentGroupTab_C::TalentGroupTab_C() : m_tabId(0), m_pointsSpent(0), m_previewPointsSpent(0) { +} + +// VERIFY: 6fcfa30a manual +// OFFSET: 0x005C8F90 +TalentGroupTab_C::~TalentGroupTab_C() { + for (uint32_t i = 0; i < this->m_tiers.m_count; i++) { + if (this->m_tiers.m_data[i]) { + delete this->m_tiers.m_data[i]; + } + } + + this->m_tiers.Clear(); +} + +// VERIFY: ecdccebe manual +// OFFSET: 0x005C9230 +int32_t TalentGroupTab_C::AddItem(const TalentRec* talent, TalentGroupItem_C* item) { + if (!talent || !item) { + return 0; + } + + HASHKEY_NONE key; + TalentGroupTier_C* tier = this->FindTier(talent->m_tierID); + + if (tier) { + tier->m_items.New(talent->m_columnIndex, key, 0, 0)->m_item = item; + return 1; + } + + tier = new (SMemAlloc(sizeof(TalentGroupTier_C), __FILE__, __LINE__, 0)) TalentGroupTier_C(); + + if (tier) { + TalentGroupTier_C** slot = this->m_tiers.New(); + + if (slot) { + *slot = tier; + tier->m_tier = talent->m_tierID; + tier->m_items.New(talent->m_columnIndex, key, 0, 0)->m_item = item; + qsort(this->m_tiers.m_data, this->m_tiers.m_count, sizeof(TalentGroupTier_C*), TierCompare); + return 1; + } + + delete tier; + } + + return 1; +} + +// VERIFY: 7b121db1 manual +// OFFSET: 0x005C9310 +void CGTalentGroup_C::AddTalentItem(int32_t talentId, int32_t rank) { + if (rank < 0) { + return; + } + + TalentRec* talent = g_talentDB.GetRecord(talentId); + + if (!talent || static_cast(rank) >= 9 || !talent->m_spellRank[rank]) { + return; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(talent->m_spellRank[rank], &spell)) { + return; + } + + HASHKEY_NONE key; + TalentGroupItem_C* item = this->m_items.Ptr(talentId, key); + + if (item) { + TalentGroupTab_C* tab = this->GetTabFromTalentID(item->m_talentId); + + if (tab) { + tab->m_previewPointsSpent += item->m_rank - item->m_previewRank; + } + + item->m_rank = rank; + item->m_previewRank = rank; + } else { + item = this->m_items.New(talentId, key, 0, 0); + item->m_talentId = talentId; + item->m_rank = rank; + item->m_previewRank = rank; + } +} + +// VERIFY: 45a90b6c manual +// OFFSET: 0x005C9450 +void CGTalentGroup_C::AddPreviewTalentPoints(uint32_t tabIndex, const TalentRec* talent, int32_t points, int32_t pet) { + int32_t delta; + + if (!this->ValidatePreviewTalentPoints(tabIndex, talent, points, &delta, pet)) { + return; + } + + int32_t talentId = talent->m_id; + HASHKEY_NONE key; + TalentGroupItem_C* item = this->m_items.Ptr(talentId, key); + + if (!item) { + item = this->m_items.New(talentId, key, 0, 0); + item->m_talentId = talentId; + this->m_tabs.m_data[tabIndex].AddItem(talent, item); + } + + item->m_previewRank += delta; + this->m_tabs.m_data[tabIndex].m_previewPointsSpent += delta; +} + +// VERIFY: 709c5981 manual +// OFFSET: 0x005C94F0 +void CGTalentInfo::AddPreviewTalentPoints(uint32_t group, uint32_t tab, uint32_t talentIndex, int32_t points, int32_t pet) { + CGTalentGroup_C* talentGroup = CGTalentInfo::GetTalentGroup(group, pet); + + if (!talentGroup) { + return; + } + + TalentTabInfo* info = CGTalentInfo::GetTab(tab, 0, pet); + + if (info && talentIndex < info->m_numTalents) { + const TalentRec* talent = &info->m_talents[talentIndex]; + + if (talent) { + talentGroup->AddPreviewTalentPoints(tab, talent, points, pet); + } + } +} + +// VERIFY: cf0844b0 auto +// OFFSET: 0x005C9740 +static void ReadTalentGroups(CDataStore* msg, uint32_t* activeGroup, int32_t* unspent, CGTalentGroup_C* groups, uint32_t count, uint32_t* numGroups) { + if (activeGroup) { + *activeGroup = 0; + } + + if (numGroups) { + *numGroups = 0; + } + + if (unspent) { + *unspent = 0; + } + + if (!msg || !groups) { + return; + } + + uint32_t points; + msg->Get(points); + + if (unspent) { + *unspent = static_cast(points) < 0 ? 0 : points; + } + + uint8_t num; + msg->Get(num); + + if (numGroups) { + *numGroups = num; + } + + uint8_t active; + msg->Get(active); + + if (activeGroup) { + *activeGroup = active; + } + + for (uint8_t i = 0; i < num; i++) { + CGTalentGroup_C* group = i < count ? &groups[i] : nullptr; + uint8_t numTalents; + msg->Get(numTalents); + + for (uint8_t j = 0; j < numTalents; j++) { + uint32_t talentId; + msg->Get(talentId); + uint8_t rank; + msg->Get(rank); + + if (group) { + group->AddTalentItem(talentId, rank); + } + } + + uint8_t numGlyphs; + msg->Get(numGlyphs); + + for (uint8_t j = 0; j < numGlyphs; j++) { + uint16_t glyph; + msg->Get(glyph); + + if (group && j < 6) { + group->m_glyphs[j] = glyph; + } + } + } +} + +// VERIFY: 8694975f auto +// OFFSET: 0x005C98A0 +static void ReadPetTalents(CDataStore* msg, CGTalentGroup_C* group) { + if (!msg || !group) { + return; + } + + uint32_t points; + msg->Get(points); + group->m_unspentPoints = points; + uint8_t count; + msg->Get(count); + + for (uint16_t i = 0; i < count; i++) { + uint32_t talentId; + msg->Get(talentId); + uint8_t rank; + msg->Get(rank); + group->AddTalentItem(talentId, rank); + } +} + +// VERIFY: 4b149495 manual +// OFFSET: 0x005C9910 +void CGTalentGroup_C::Reset() { + this->m_items.Clear(); + this->m_tabs.Clear(); + this->m_unspentPoints = 0; + + for (uint32_t i = 0; i < 6; i++) { + this->m_glyphs[i] = 0; + } +} + +// VERIFY: 26ee2dd9 manual +// OFFSET: 0x005C9960 +void CGTalentGroup_C::UpdateTabs(const TSFixedArray* tabs) { + uint32_t count = tabs->m_count; + this->m_tabs.SetCount(count); + + for (uint32_t i = 0; i < count; i++) { + this->m_tabs.m_data[i].m_tabId = tabs->m_data[i]->m_tabId; + this->m_tabs.m_data[i].m_pointsSpent = 0; + + for (uint32_t j = 0; j < tabs->m_data[i]->m_numTalents; j++) { + const TalentRec* talent = &tabs->m_data[i]->m_talents[j]; + + if (!talent) { + continue; + } + + HASHKEY_NONE key; + TalentGroupItem_C* item = this->m_items.Ptr(talent->m_id, key); + + if (item) { + this->m_tabs.m_data[i].m_pointsSpent += item->m_rank + 1; + this->m_tabs.m_data[i].AddItem(talent, item); + } + } + } +} + +// VERIFY: 0108b1fc manual +// OFFSET: 0x005C9A30 +void CGTalentInfo::ResetTalentGroups(int32_t pet) { + if (pet) { + CGTalentInfo::m_petTalentGroup.Reset(); + return; + } + + for (uint32_t i = 0; i < 2; i++) { + CGTalentInfo::m_talentGroups[i].Reset(); + } + + CGTalentInfo::m_activeTalentGroup = 0; + CGTalentInfo::m_numTalentGroups = 0; + CGTalentInfo::m_unspentTalentPoints = 0; +} + +// VERIFY: b1d0ceef manual +// OFFSET: 0x005C9AD0 +void CGTalentInfo_Inspect::Reset() { + for (uint32_t i = 0; i < 2; i++) { + CGTalentInfo_Inspect::m_talentGroups[i].Reset(); + } + + CGTalentInfo_Inspect::m_activeTalentGroup = 0; + CGTalentInfo_Inspect::m_numTalentGroups = 0; + CGTalentInfo_Inspect::m_unspentTalentPoints = 0; +} + +// VERIFY: e22bac27 manual +// OFFSET: 0x005C9BB0 +CGTalentGroup_C::CGTalentGroup_C() { + this->Reset(); +} + +// VERIFY: 4ce05bcd manual +// OFFSET: 0x005C9C10 +CGTalentGroup_C::~CGTalentGroup_C() { + this->Reset(); +} + +// VERIFY: fbf3b704 manual +// OFFSET: 0x005C9CA0 +static void UpdateTalentGroups(const TSFixedArray* tabs, CGTalentGroup_C* groups, uint32_t count, uint32_t activeGroup, uint32_t numGroups, int32_t unspent) { + if (!numGroups) { + return; + } + + for (uint32_t i = 0; i < count; i++) { + groups[i].UpdateTabs(tabs); + } + + int32_t total = unspent; + + if (activeGroup < numGroups) { + CGTalentGroup_C* group = &groups[activeGroup]; + int32_t spent = 0; + + for (uint32_t i = 0; i < group->m_tabs.m_count; i++) { + spent += group->m_tabs.m_data[i].m_pointsSpent; + } + + total = spent + unspent; + group->m_unspentPoints = unspent; + } + + for (uint32_t i = 0; i < count; i++) { + if (i == activeGroup) { + continue; + } + + int32_t spent = 0; + + for (uint32_t j = 0; j < groups[i].m_tabs.m_count; j++) { + spent += groups[i].m_tabs.m_data[j].m_pointsSpent; + } + + int32_t left = total - spent; + + if (left < 0) { + left = 0; + } + + groups[i].m_unspentPoints = left; + } +} + +// VERIFY: 0219faf4 manual +// OFFSET: 0x005C9D50 +void CGTalentInfo::EnterWorld() { + if (CGTalentInfo::m_tabsInitialized) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + BuildTabInfo(player, &CGTalentInfo::m_tabs, 0); + CGTalentInfo::m_tabsInitialized = 1; + UpdateTalentGroups(&CGTalentInfo::m_tabs, CGTalentInfo::m_talentGroups, 2, CGTalentInfo::m_activeTalentGroup, CGTalentInfo::m_numTalentGroups, CGTalentInfo::m_unspentTalentPoints); +} + +// VERIFY: 62894563 auto +// OFFSET: 0x005C9DC0 +void CGTalentInfo::ShutdownGame() { + CGTalentInfo::ResetTabInfo(0); + CGTalentInfo::ResetTabInfo(1); + CGTalentInfo::ResetTalentGroups(0); + CGTalentInfo::m_petTalentGroup.Reset(); +} + +// VERIFY: 3c64c384 auto +// OFFSET: 0x005C9DF0 +void CGTalentInfo::UpdatePetTabInfo(int32_t family) { + if (family) { + if (CGTalentInfo::m_petTalentTab != family) { + BuildTabInfo(nullptr, &CGTalentInfo::m_petTabs, family); + CGTalentInfo::m_petTalentGroup.UpdateTabs(&CGTalentInfo::m_petTabs); + } + } else { + CGTalentInfo::ResetTabInfo(1); + CGTalentInfo::m_petTalentGroup.Reset(); + } + + CGTalentInfo::m_petTalentTab = family; +} + +// VERIFY: fd8c0d16 manual +// OFFSET: 0x005C9E50 +void CGTalentInfo::UpdateTalentData(CDataStore* msg) { + if (!msg) { + return; + } + + uint32_t oldNumGroups = CGTalentInfo::m_numTalentGroups; + uint32_t oldActiveGroup = CGTalentInfo::m_activeTalentGroup; + CGTalentInfo::ResetTalentGroups(0); + ReadTalentGroups(msg, &CGTalentInfo::m_activeTalentGroup, &CGTalentInfo::m_unspentTalentPoints, CGTalentInfo::m_talentGroups, 2, &CGTalentInfo::m_numTalentGroups); + + if (CGTalentInfo::m_tabsInitialized) { + UpdateTalentGroups(&CGTalentInfo::m_tabs, CGTalentInfo::m_talentGroups, 2, CGTalentInfo::m_activeTalentGroup, CGTalentInfo::m_numTalentGroups, CGTalentInfo::m_unspentTalentPoints); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_PLAYER_TALENT_UPDATE, nullptr); + + if (oldActiveGroup != CGTalentInfo::m_activeTalentGroup) { + uint32_t newActive = CGTalentInfo::m_numTalentGroups ? CGTalentInfo::m_activeTalentGroup : -1; + uint32_t oldActive = oldNumGroups ? oldActiveGroup : -1; + FrameScript_SignalEvent(SCRIPT_EVENT_ACTIVE_TALENT_GROUP_CHANGED, "%d%d", newActive + 1, oldActive + 1); + } +} + +// VERIFY: f51325dc auto +// OFFSET: 0x005C9F10 +void CGTalentInfo::UpdatePetTalentData(CDataStore* msg) { + if (!msg) { + return; + } + + CGTalentInfo::m_petTalentGroup.Reset(); + ReadPetTalents(msg, &CGTalentInfo::m_petTalentGroup); + + if (CGTalentInfo::m_petTalentTab) { + CGTalentInfo::m_petTalentGroup.UpdateTabs(&CGTalentInfo::m_petTabs); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_PET_TALENT_UPDATE, nullptr); +} + +// VERIFY: 8688bf1f auto +// OFFSET: 0x005C9F60 +void CGTalentInfo_Inspect::ShutdownGame() { + CGTalentInfo_Inspect::ResetTabInfo(); + CGTalentInfo_Inspect::Reset(); +} + +// VERIFY: a8bdf404 manual +// OFFSET: 0x005C9F70 +void CGTalentInfo_Inspect::SetInspectTarget(const WOWGUID& guid) { + CGTalentInfo_Inspect::ResetTabInfo(); + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(guid, TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + BuildTabInfo(player, &CGTalentInfo_Inspect::m_tabs, 0); + CGTalentInfo_Inspect::m_inspectTarget = guid; + UpdateTalentGroups(&CGTalentInfo_Inspect::m_tabs, CGTalentInfo_Inspect::m_talentGroups, 2, CGTalentInfo_Inspect::m_activeTalentGroup, CGTalentInfo_Inspect::m_numTalentGroups, CGTalentInfo_Inspect::m_unspentTalentPoints); + } +} + +// VERIFY: 7870c364 auto +// OFFSET: 0x005C9FF0 +void CGTalentInfo_Inspect::UpdateTalentData(CDataStore* msg) { + if (!msg) { + return; + } + + CGTalentInfo_Inspect::Reset(); + ReadTalentGroups(msg, &CGTalentInfo_Inspect::m_activeTalentGroup, &CGTalentInfo_Inspect::m_unspentTalentPoints, CGTalentInfo_Inspect::m_talentGroups, 2, &CGTalentInfo_Inspect::m_numTalentGroups); + + if (CGTalentInfo_Inspect::m_inspectTarget.m_guid) { + UpdateTalentGroups(&CGTalentInfo_Inspect::m_tabs, CGTalentInfo_Inspect::m_talentGroups, 2, CGTalentInfo_Inspect::m_activeTalentGroup, CGTalentInfo_Inspect::m_numTalentGroups, CGTalentInfo_Inspect::m_unspentTalentPoints); + } +} diff --git a/WoW/Source/Ui/TalentInfo.h b/WoW/Source/Ui/TalentInfo.h index 5796f64..dc076a5 100644 --- a/WoW/Source/Ui/TalentInfo.h +++ b/WoW/Source/Ui/TalentInfo.h @@ -10,92 +10,124 @@ class CDataStore; struct lua_State; -struct TalentTabInfo; +class TalentRec; +class CGPlayer_C; +class CGUnit_C; -struct TalentGroupTab { +struct TalentTabInfo { /* 0000 */ int32_t m_tabId; - /* 0004 */ uint32_t m_pointsSpent; - /* 0008 */ int32_t m_previewPointsSpent; - /* 000C */ uint32_t unk_000C; - /* 0010 */ uint32_t unk_0010; - /* 0014 */ uint32_t unk_0014; - /* 0018 */ uint32_t unk_0018; + /* 0004 */ uint32_t m_numTalents; + /* 0008 */ const TalentRec* m_talents; }; -struct CGTalentItem { - /* 0000 */ uint8_t unk_0000[24]; +struct TalentGroupItem_C : public TSHashObject { /* 0018 */ int32_t m_talentId; /* 001C */ int32_t m_rank; /* 0020 */ int32_t m_previewRank; }; -class TalentRec; +struct TalentGroupTierItem_C : public TSHashObject { + /* 0018 */ TalentGroupItem_C* m_item; +}; + +struct TalentGroupTier_C { + /* 0000 */ int32_t m_tier; + /* 0004 */ TSHashTable m_items; + + TalentGroupTier_C(); + ~TalentGroupTier_C(); +}; + +struct TalentGroupTab_C { + /* 0000 */ int32_t m_tabId; + /* 0004 */ uint32_t m_pointsSpent; + /* 0008 */ int32_t m_previewPointsSpent; + /* 000C */ TSGrowableArray m_tiers; + + TalentGroupTab_C(); + ~TalentGroupTab_C(); + TalentGroupTier_C* FindTier(int32_t tier); + int32_t AddItem(const TalentRec* talent, TalentGroupItem_C* item); +}; class CGTalentGroup_C { public: - /* 0000 */ uint8_t unk_0000[8]; - /* 0008 */ uint32_t unk_0008; - /* 000C */ uint8_t unk_000C[4]; - /* 0010 */ uint32_t unk_0010; - /* 0014 */ uint8_t unk_0014[24]; - /* 002C */ TSFixedArray m_tabs; + /* 0004 */ TSHashTable m_items; + /* 002C */ TSFixedArray m_tabs; /* 0038 */ uint32_t m_unspentPoints; - /* 003C */ uint32_t unk_003C; - /* 0040 */ uint32_t unk_0040; - /* 0044 */ uint32_t unk_0044; - /* 0048 */ uint32_t unk_0048; - /* 004C */ uint32_t unk_004C; - /* 0050 */ uint32_t unk_0050; + /* 003C */ uint32_t m_glyphs[6]; + CGTalentGroup_C(); + virtual ~CGTalentGroup_C(); + void Reset(); + uint32_t GetGlyph(uint32_t index); + TalentGroupTab_C* GetTab(uint32_t index); + TalentGroupTab_C* GetTabFromID(int32_t tabId); + TalentGroupTab_C* GetTabFromTalentID(int32_t talentId); + TalentGroupItem_C* GetTalentItem(int32_t talentId); + void AddTalentItem(int32_t talentId, int32_t rank); + void UpdateTabs(const TSFixedArray* tabs); + void ResetPreviewTalentPoints(uint32_t tabIndex); void ResetAllPreviewTalentPoints(); - TalentGroupTab* GetTabFromID(int32_t tabId); - CGTalentItem* GetTalentItem(int32_t talentId); - int32_t CanAddPreviewTalentPoints(const TalentRec* talent, int32_t delta, int32_t* count, int32_t pet); + int32_t ValidatePreviewTalentPoints(uint32_t tabIndex, const TalentRec* talent, int32_t points, int32_t* delta, int32_t pet); + int32_t CanAddPreviewTalentPoints(const TalentRec* talent, int32_t points, int32_t* delta, int32_t pet); + void AddPreviewTalentPoints(uint32_t tabIndex, const TalentRec* talent, int32_t points, int32_t pet); }; class CGTalentInfo { public: static uint32_t m_activeTalentGroup; static uint32_t m_numTalentGroups; + static int32_t m_tabsInitialized; + static int32_t m_unspentTalentPoints; static int32_t m_petTalentTab; static TSFixedArray m_tabs; static TSFixedArray m_petTabs; static CGTalentGroup_C m_talentGroups[2]; static CGTalentGroup_C m_petTalentGroup; static void EnterWorld(); + static void LeaveWorld(); + static void ShutdownGame(); static uint32_t GetActiveTalentGroup(int32_t pet); static uint32_t GetUnspentTalentPoints(uint32_t index, int32_t pet); static CGTalentGroup_C* GetTalentGroup(uint32_t index, int32_t pet); + static TalentTabInfo* GetTab(uint32_t index, int32_t inspect, int32_t pet); + static int32_t IsTalentAvailableForPet(CGUnit_C* pet, const TalentRec* talent); + static TalentGroupItem_C* GetTalentItem(uint32_t group, int32_t talentId, int32_t pet); + static int32_t GetPreviewPointsSpent(uint32_t group, int32_t pet); + static void AddPreviewTalentPoints(uint32_t group, uint32_t tab, uint32_t talentIndex, int32_t points, int32_t pet); + static void ResetPreviewTalentPoints(uint32_t group, uint32_t tab, int32_t pet); + static void ResetGroupPreviewTalentPoints(uint32_t group, int32_t pet); static void RecalculatePreviewPoints(int32_t pet); static int32_t SumPreviewPointsSpent(int32_t pet); + static void ResetTabInfo(int32_t pet); + static void ResetTalentGroups(int32_t pet); + static void UpdatePetTabInfo(int32_t family); static void UpdateTalentData(CDataStore* msg); static void UpdatePetTalentData(CDataStore* msg); }; - -int32_t Script_GetNumTalentTabs(lua_State* L); -int32_t Script_GetTalentTabInfo(lua_State* L); -int32_t Script_GetNumTalents(lua_State* L); -int32_t Script_GetTalentInfo(lua_State* L); -int32_t Script_GetTalentLink(lua_State* L); -int32_t Script_GetTalentPrereqs(lua_State* L); -int32_t Script_LearnTalent(lua_State* L); -int32_t Script_GetUnspentTalentPoints(lua_State* L); -int32_t Script_GetNumTalentGroups(lua_State* L); -int32_t Script_SetActiveTalentGroup(lua_State* L); -int32_t Script_GetGroupPreviewTalentPointsSpent(lua_State* L); -int32_t Script_AddPreviewTalentPoints(lua_State* L); -int32_t Script_ResetPreviewTalentPoints(lua_State* L); -int32_t Script_ResetGroupPreviewTalentPoints(lua_State* L); -int32_t Script_LearnPreviewTalents(lua_State* L); void TalentInfoRegisterScriptFunctions(); +void TalentInfoUnregisterScriptFunctions(); int32_t TalentInfoIsSpellKnown(int32_t spellId, int32_t isInspect, int32_t isPet); +uint32_t TalentInfoGetScriptGroupIndex(lua_State* L, int32_t index); +CGTalentGroup_C* TalentInfoGetTalentGroup(uint32_t index, int32_t inspect, int32_t pet); +TalentGroupItem_C* TalentInfoGetTalentItem(uint32_t group, int32_t talentId, int32_t inspect, int32_t pet); class CGTalentInfo_Inspect { public: static uint32_t m_activeTalentGroup; - static void EnterWorld(); static WOWGUID m_inspectTarget; + static uint32_t m_numTalentGroups; + static int32_t m_unspentTalentPoints; + static TSFixedArray m_tabs; + static CGTalentGroup_C m_talentGroups[2]; + static void EnterWorld(); + static void ShutdownGame(); + static void Reset(); + static void ResetTabInfo(); + static void SetInspectTarget(const WOWGUID& guid); + static void UpdateTalentData(CDataStore* msg); }; #endif diff --git a/WoW/Source/Ui/TalentInfo_Scripts.cpp b/WoW/Source/Ui/TalentInfo_Scripts.cpp index 5edc410..15fb10c 100644 --- a/WoW/Source/Ui/TalentInfo_Scripts.cpp +++ b/WoW/Source/Ui/TalentInfo_Scripts.cpp @@ -3,6 +3,571 @@ #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" #include "Engine/Source/FrameXML/LoadXML.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/lua-5.1/src/lauxlib.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/DB/Rec/SpellIconRec.h" +#include "WoW/Source/DB/Rec/TalentRec.h" +#include "WoW/Source/DB/Rec/TalentTabRec.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/PetInfo.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/UIUtil/Tooltip.h" + +// STATIC: 0x00AD05E8 +static int32_t s_activateTalentGroupSpells[2] = { 63645, 63644 }; + +// VERIFY: 29096ec7 manual +// OFFSET: 0x005C5CC0 +static int32_t Script_GetNumTalentTabs(lua_State* L) { + int32_t inspect = StringToBOOL(L, 1, 0); + int32_t pet = StringToBOOL(L, 2, 0); + uint32_t count; + + if (inspect) { + if (pet) { + lua_pushnumber(L, 0.0); + return 1; + } + + count = CGTalentInfo_Inspect::m_tabs.m_count; + } else { + count = pet ? CGTalentInfo::m_petTabs.m_count : CGTalentInfo::m_tabs.m_count; + } + + lua_pushnumber(L, count); + return 1; +} + +// VERIFY: c6674563 manual +// OFFSET: 0x005C5D40 +static int32_t Script_GetNumTalents(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetNumTalents(tabIndex[, isInspect[, isPet]])"); + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + int32_t inspect = StringToBOOL(L, 2, 0); + int32_t pet = StringToBOOL(L, 3, 0); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, inspect, pet); + lua_pushnumber(L, tab ? static_cast(tab->m_numTalents) : 0); + return 1; +} + +// VERIFY: a4b3fa55 manual +// OFFSET: 0x005C5DF0 +static int32_t Script_GetNumTalentGroups(lua_State* L) { + int32_t inspect = StringToBOOL(L, 1, 0); + int32_t pet = StringToBOOL(L, 2, 0); + uint32_t count; + + if (inspect) { + count = CGTalentInfo_Inspect::m_numTalentGroups; + } else if (pet) { + count = CGTalentInfo::m_petTalentTab && CGTalentInfo::m_petTabs.m_count; + } else { + count = CGTalentInfo::m_numTalentGroups; + } + + lua_pushnumber(L, count); + return 1; +} + +// VERIFY: 7ce5456f manual +// OFFSET: 0x005C5E70 +static int32_t Script_SetActiveTalentGroup(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: SetActiveTalentGroup(groupIndex)"); + } + + uint32_t group = static_cast(lua_tonumber(L, 1)) - 1; + + if (group != CGTalentInfo::m_activeTalentGroup && group < CGTalentInfo::m_numTalentGroups && group < 2) { + Spell_C_ClickSpell(s_activateTalentGroupSpells[group], nullptr, ClntObjMgrGetActivePlayer()); + } + + return 0; +} + +// VERIFY: b82d80eb manual +// OFFSET: 0x005C6150 +static int32_t Script_GetTalentTabInfo(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: GetTalentTabInfo(tabIndex[, isInspect[, isPet[, groupIndex]]])"); + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + int32_t pet = StringToBOOL(L, 3, 0); + int32_t inspect = StringToBOOL(L, 2, 0); + TalentTabInfo* info = CGTalentInfo::GetTab(tabIndex, inspect, pet); + TalentTabRec* tab; + + if (!info || !(tab = g_talentTabDB.GetRecord(info->m_tabId))) { + lua_pushnil(L); + lua_pushnil(L); + lua_pushinteger(L, 0); + lua_pushnil(L); + lua_pushinteger(L, 0); + return 5; + } + + lua_pushstring(L, tab->m_name); + SpellIconRec* icon = g_spellIconDB.GetRecord(tab->m_spellIconID); + + if (icon) { + lua_pushstring(L, icon->m_textureFilename); + } else { + lua_pushnil(L); + } + + CGTalentGroup_C* group = TalentInfoGetTalentGroup(TalentInfoGetScriptGroupIndex(L, 4), inspect, pet); + TalentGroupTab_C* groupTab; + + if (group && (groupTab = group->GetTab(tabIndex))) { + lua_pushinteger(L, groupTab->m_pointsSpent); + lua_pushstring(L, tab->m_backgroundFile); + lua_pushinteger(L, groupTab->m_previewPointsSpent); + } else { + lua_pushinteger(L, 0); + lua_pushstring(L, tab->m_backgroundFile); + lua_pushinteger(L, 0); + } + + return 5; +} + +// VERIFY: bf0a4c25 manual +// OFFSET: 0x005C6310 +static int32_t Script_GetUnspentTalentPoints(lua_State* L) { + int32_t inspect = StringToBOOL(L, 1, 0); + int32_t pet = StringToBOOL(L, 2, 0); + CGTalentGroup_C* group = TalentInfoGetTalentGroup(TalentInfoGetScriptGroupIndex(L, 3), inspect, pet); + lua_pushinteger(L, group ? group->m_unspentPoints : 0); + return 1; +} + +// VERIFY: 2177362a manual +// OFFSET: 0x005C6420 +static int32_t Script_GetGroupPreviewTalentPointsSpent(lua_State* L) { + int32_t pet = StringToBOOL(L, 1, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 2); + lua_pushinteger(L, CGTalentInfo::GetPreviewPointsSpent(group, pet)); + return 1; +} + +// VERIFY: 45eacd6e manual +// OFFSET: 0x005C6A10 +static int32_t Script_LearnPreviewTalents(lua_State* L) { + int32_t pet = StringToBOOL(L, 1, 0); + CGTalentGroup_C* group = CGTalentInfo::GetTalentGroup(CGTalentInfo::GetActiveTalentGroup(pet), pet); + + if (!group) { + return 0; + } + + int32_t spent = 0; + + for (uint32_t i = 0; i < group->m_tabs.m_count; i++) { + spent += group->m_tabs.m_data[i].m_previewPointsSpent; + } + + if (spent <= 0) { + return 0; + } + + CGUnit_C* unit = pet ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : ClntObjMgrGetActivePlayerObj(); + + if (!unit) { + return 0; + } + + CDataStore msg; + + if (pet) { + msg.Put(static_cast(CMSG_LEARN_PREVIEW_TALENTS_PET)); + msg.Put(unit->m_obj->m_guid.m_guid); + } else { + msg.Put(static_cast(CMSG_LEARN_PREVIEW_TALENTS)); + } + + uint32_t count = 0; + uint32_t countPos = msg.m_size; + msg.Put(0u); + + for (uint32_t i = 0; i < group->m_tabs.m_count; i++) { + TalentGroupTab_C* tab = &group->m_tabs.m_data[i]; + + for (uint32_t j = 0; j < tab->m_tiers.m_count; j++) { + TalentGroupTier_C* tier = tab->m_tiers.m_data[j]; + + for (TalentGroupTierItem_C* node = tier->m_items.m_fulllist.Head(); node; node = tier->m_items.Next(node)) { + TalentGroupItem_C* item = node->m_item; + + if (item && item->m_previewRank > item->m_rank) { + msg.Put(static_cast(item->m_talentId)); + msg.Put(static_cast(item->m_previewRank)); + count++; + } + } + } + } + + if (count) { + msg.Set(countPos, count); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + return 0; +} + +// VERIFY: f4e23c59 manual +// OFFSET: 0x005C7130 +static int32_t Script_ResetPreviewTalentPoints(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: ResetPreviewTalentPoints(tabIndex[, isPet[, groupIndex]])"); + } + + uint32_t tab = lua_tointeger(L, 1) - 1; + int32_t pet = StringToBOOL(L, 2, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 3); + int32_t before = CGTalentInfo::GetPreviewPointsSpent(group, pet); + CGTalentInfo::ResetPreviewTalentPoints(group, tab, pet); + int32_t after = CGTalentInfo::GetPreviewPointsSpent(group, pet); + + if (after != before) { + FrameScript_SignalEvent(pet ? SCRIPT_EVENT_PREVIEW_PET_TALENT_POINTS_CHANGED : SCRIPT_EVENT_PREVIEW_TALENT_POINTS_CHANGED, "%d%d%d%d", 0, tab + 1, group + 1, after - before); + } + + return 0; +} + +// VERIFY: 50931f10 auto +// OFFSET: 0x005C7200 +static int32_t Script_ResetGroupPreviewTalentPoints(lua_State* L) { + int32_t pet = StringToBOOL(L, 1, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 2); + int32_t before = CGTalentInfo::GetPreviewPointsSpent(group, pet); + CGTalentInfo::ResetGroupPreviewTalentPoints(group, pet); + int32_t after = CGTalentInfo::GetPreviewPointsSpent(group, pet); + + if (after != before) { + FrameScript_SignalEvent(pet ? SCRIPT_EVENT_PREVIEW_PET_TALENT_POINTS_CHANGED : SCRIPT_EVENT_PREVIEW_TALENT_POINTS_CHANGED, "%d%d%d%d", 0, 0, group + 1, after - before); + } + + return 0; +} + +// VERIFY: ec497201 manual +// OFFSET: 0x005C7800 +static int32_t Script_GetTalentInfo(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: GetTalentInfo(tabIndex, talentIndex[, isInspect[, isPet[, groupIndex]]])"); + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t talentIndex = static_cast(lua_tonumber(L, 2)) - 1; + int32_t inspect = StringToBOOL(L, 3, 0); + int32_t pet = StringToBOOL(L, 4, 0); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, inspect, pet); + + if (tab && talentIndex < tab->m_numTalents) { + CGUnit_C* unit = pet ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : ClntObjMgrGetActivePlayerObj(); + const TalentRec* talent = &tab->m_talents[talentIndex]; + + if (talent && (!pet || CGTalentInfo::IsTalentAvailableForPet(unit, talent))) { + int32_t maxRank = -1; + + for (int32_t i = 8; i >= 0; i--) { + if (talent->m_spellRank[i] && maxRank < 0) { + maxRank = i; + } + } + + int32_t rank = -1; + int32_t previewRank = -1; + TalentGroupItem_C* item = TalentInfoGetTalentItem(TalentInfoGetScriptGroupIndex(L, 5), talent->m_id, inspect, pet); + + if (item) { + rank = item->m_rank; + previewRank = item->m_previewRank; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(rank < 0 ? talent->m_spellRank[0] : talent->m_spellRank[rank], &spell)) { + lua_pushstring(L, spell.m_name); + SpellIconRec* icon = g_spellIconDB.GetRecord(spell.m_spellIconID); + + if (icon) { + lua_pushstring(L, icon->m_textureFilename); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, talent->m_tierID + 1); + lua_pushnumber(L, talent->m_columnIndex + 1); + lua_pushnumber(L, rank + 1); + lua_pushnumber(L, maxRank + 1); + + if (talent->m_flags & 1) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + int32_t available = 0; + + if (inspect) { + available = !pet && rank >= 0; + } else if (unit) { + int32_t requiredSpell = talent->m_requiredSpellID; + available = 1; + + if (requiredSpell && !pet) { + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if ((!player || (!player->IsSpellKnown(requiredSpell) && !player->IsSpellSuperceded(requiredSpell))) && !unit->IsSpellSuperceded(talent->m_requiredSpellID)) { + available = 0; + } + } + } + + if (available) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, previewRank + 1); + + int32_t previewAvailable = 0; + + if (inspect) { + previewAvailable = !pet && previewRank >= 0; + } else if (unit) { + int32_t requiredSpell = talent->m_requiredSpellID; + previewAvailable = 1; + + if (requiredSpell && !pet) { + CGUnit_C* player = ClntObjMgrGetActivePlayerObj(); + + if ((!player || (!player->IsSpellKnown(requiredSpell) && !player->IsSpellSuperceded(requiredSpell))) && !unit->IsSpellSuperceded(talent->m_requiredSpellID)) { + previewAvailable = 0; + } + } + } + + if (previewAvailable) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 10; + } + } + } + + lua_pushnil(L); + lua_pushnil(L); + lua_pushnumber(L, 1.0); + lua_pushnumber(L, 1.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnil(L); + lua_pushnumber(L, 0.0); + lua_pushnil(L); + return 10; +} + +// VERIFY: b2a1c929 manual +// OFFSET: 0x005C7ED0 +static int32_t Script_GetTalentPrereqs(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: GetTalentPrereqs(tabIndex, talentIndex[, isInspect[, isPet[, groupIndex]]])"); + } + + int32_t count = 0; + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t talentIndex = static_cast(lua_tonumber(L, 2)) - 1; + int32_t inspect = StringToBOOL(L, 3, 0); + int32_t pet = StringToBOOL(L, 4, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 5); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, inspect, pet); + + if (tab && talentIndex < tab->m_numTalents) { + const TalentRec* talent = &tab->m_talents[talentIndex]; + + if (talent) { + for (uint32_t i = 0; i < 3; i++) { + int32_t prereqId = talent->m_prereqTalent[i]; + + if (!prereqId) { + continue; + } + + TalentRec* prereq = g_talentDB.GetRecord(prereqId); + + if (!prereq) { + continue; + } + + lua_checkstack(L, 4); + lua_pushnumber(L, prereq->m_tierID + 1); + lua_pushnumber(L, prereq->m_columnIndex + 1); + TalentGroupItem_C* item = TalentInfoGetTalentItem(group, prereqId, inspect, pet); + + if (item) { + if (item->m_rank < talent->m_prereqRank[i]) { + lua_pushnil(L); + } else { + lua_pushnumber(L, 1.0); + } + + if (item->m_previewRank < talent->m_prereqRank[i]) { + lua_pushnil(L); + } else { + lua_pushnumber(L, 1.0); + } + } else { + lua_pushnil(L); + lua_pushnil(L); + } + + count++; + } + } + } + + return 4 * count; +} + +// VERIFY: e016f005 manual +// OFFSET: 0x005C7CE0 +static int32_t Script_GetTalentLink(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: GetTalentLink(tabIndex, talentIndex[, isInspect[, isPet[, groupIndex[, isPreview]]]])"); + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t talentIndex = static_cast(lua_tonumber(L, 2)) - 1; + int32_t inspect = StringToBOOL(L, 3, 0); + int32_t pet = StringToBOOL(L, 4, 0); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, inspect, pet); + + if (tab && talentIndex < tab->m_numTalents) { + CGUnit_C* unit = pet ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : nullptr; + const TalentRec* talent = &tab->m_talents[talentIndex]; + + if (talent && (!pet || CGTalentInfo::IsTalentAvailableForPet(unit, talent))) { + int32_t rank = -1; + TalentGroupItem_C* item = TalentInfoGetTalentItem(TalentInfoGetScriptGroupIndex(L, 5), talent->m_id, inspect, pet); + + if (item) { + rank = StringToBOOL(L, 5, 0) ? item->m_previewRank : item->m_rank; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(talent->m_spellRank[rank < 0 ? 0 : rank], &spell)) { + lua_pushstring(L, CGTooltip::GetTalentHyperlinkString(talent, spell.m_name, rank)); + return 1; + } + } + } + + lua_pushnil(L); + return 1; +} + +// VERIFY: 241f5249 manual +// OFFSET: 0x005C80E0 +static int32_t Script_LearnTalent(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: LearnTalent(tabIndex, talentIndex[, isPet])"); + } + + uint32_t tabIndex = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t talentIndex = static_cast(lua_tonumber(L, 2)) - 1; + int32_t pet = StringToBOOL(L, 3, 0); + CGUnit_C* unit = pet ? static_cast(ClntObjMgrObjectPtr(CGPetInfo::GetPet(0), TYPEMASK_UNIT, __FILE__, __LINE__)) : ClntObjMgrGetActivePlayerObj(); + TalentTabInfo* tab = CGTalentInfo::GetTab(tabIndex, 0, pet); + + if (!unit || !tab || talentIndex >= tab->m_numTalents) { + return 0; + } + + const TalentRec* talent = &tab->m_talents[talentIndex]; + + if (!talent || (pet && !CGTalentInfo::IsTalentAvailableForPet(unit, talent))) { + return 0; + } + + int32_t rank = -1; + int32_t maxRank = -1; + + for (int32_t i = 8; i >= 0; i--) { + if (talent->m_spellRank[i]) { + maxRank = i; + break; + } + } + + TalentGroupItem_C* item = CGTalentInfo::GetTalentItem(CGTalentInfo::GetActiveTalentGroup(pet), talent->m_id, pet); + + if (item) { + rank = item->m_rank; + } + + if (rank < maxRank) { + CDataStore msg; + + if (pet) { + msg.Put(static_cast(CMSG_PET_LEARN_TALENT)); + msg.Put(unit->m_obj->m_guid.m_guid); + } else { + msg.Put(static_cast(CMSG_LEARN_TALENT)); + } + + msg.Put(static_cast(talent->m_id)); + msg.Put(static_cast(rank + 1)); + msg.Finalize(); + ClientServices::Send2(&msg); + } + + return 0; +} + +// VERIFY: b2a1239e manual +// OFFSET: 0x005C9590 +static int32_t Script_AddPreviewTalentPoints(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: AddPreviewTalentPoints(tabIndex, talentIndex, points[, isPet[, groupIndex]])"); + } + + uint32_t tab = lua_tointeger(L, 1) - 1; + uint32_t talent = lua_tointeger(L, 2) - 1; + int32_t points = lua_tointeger(L, 3); + int32_t pet = StringToBOOL(L, 4, 0); + uint32_t group = TalentInfoGetScriptGroupIndex(L, 5); + int32_t before = CGTalentInfo::GetPreviewPointsSpent(group, pet); + CGTalentInfo::AddPreviewTalentPoints(group, tab, talent, points, pet); + int32_t after = CGTalentInfo::GetPreviewPointsSpent(group, pet); + + if (after != before) { + FrameScript_SignalEvent(pet ? SCRIPT_EVENT_PREVIEW_PET_TALENT_POINTS_CHANGED : SCRIPT_EVENT_PREVIEW_TALENT_POINTS_CHANGED, "%d%d%d%d", talent + 1, tab + 1, group + 1, after - before); + } + + return 0; +} // VERIFY: 3e3b2c80 auto // OFFSET: 0x005C5810 @@ -67,3 +632,11 @@ void TalentInfoRegisterScriptFunctions() { FrameScript_RegisterFunction(s_ScriptFunctions[i].m_name, s_ScriptFunctions[i].m_method); } } + +// VERIFY: 3367c21b auto +// OFFSET: 0x005C58B0 +void TalentInfoUnregisterScriptFunctions() { + for (uint32_t i = 0; i < sizeof(s_ScriptFunctions) / sizeof(s_ScriptFunctions[0]); i++) { + FrameScript_UnregisterFunction(s_ScriptFunctions[i].m_name); + } +} diff --git a/WoW/Source/Ui/TotemInfo.h b/WoW/Source/Ui/TotemInfo.h index f17e699..cdfdba9 100644 --- a/WoW/Source/Ui/TotemInfo.h +++ b/WoW/Source/Ui/TotemInfo.h @@ -14,6 +14,8 @@ class TotemInfo { /* 0014 */ int32_t m_duration; /* 0018 */ uint32_t m_startTime; /* 001C */ const char* m_icon; + + uint32_t GetSpawnTimeLeft(); }; #endif diff --git a/WoW/Source/Ui/TradeFrame.cpp b/WoW/Source/Ui/TradeFrame.cpp index eef47aa..fab5ab3 100644 --- a/WoW/Source/Ui/TradeFrame.cpp +++ b/WoW/Source/Ui/TradeFrame.cpp @@ -3,6 +3,9 @@ #include "Engine/Source/FrameScript/FrameScript.h" #include "WoW/Source/Ui/Types.h" +// STATIC: 0x00BFA680 +WOWGUID CGTradeInfo::m_enchantingItem; + // STATIC: 0x00BFA658 WOWGUID CGTradeInfo::m_tradingPlayer; diff --git a/WoW/Source/Ui/TradeFrame.h b/WoW/Source/Ui/TradeFrame.h index 02e26f7..3c9bcda 100644 --- a/WoW/Source/Ui/TradeFrame.h +++ b/WoW/Source/Ui/TradeFrame.h @@ -4,6 +4,8 @@ #include #include "WoW/Source/Object/WGUID.h" +class CGItem_C; + struct lua_State; struct PlayerTradeState { @@ -15,6 +17,9 @@ struct PlayerTradeState { class CGTradeInfo { public: static void SetTradePartner(WOWGUID partner, int32_t a2); + static void SetEnchantingItem(CGItem_C* item); + static void AddPlayerItem(WOWGUID item, WOWGUID container, uint32_t slot); + static WOWGUID m_enchantingItem; static void EnterWorld(); static uint32_t GetPlayerTradeMoney(); static uint32_t GetTargetTradeMoney(); diff --git a/WoW/Source/Ui/TradeSkillFrame.cpp b/WoW/Source/Ui/TradeSkillFrame.cpp index 7afe79b..0697715 100644 --- a/WoW/Source/Ui/TradeSkillFrame.cpp +++ b/WoW/Source/Ui/TradeSkillFrame.cpp @@ -1,4 +1,7 @@ #include "TradeSkillFrame.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" // STATIC: 0x00C235B8 int32_t CGTradeSkillInfo::m_filteredSkills; @@ -34,3 +37,68 @@ uint32_t CGTradeSkillInfo::m_pendingRecastTimes; // STATIC: 0x00C235E4 void* CGTradeSkillInfo::m_linkData; + +// VERIFY: c0b1eab0 manual +// OFFSET: 0x005D9FF0 +void CGTradeSkillInfo::StopRecast() { + if (CGTradeSkillInfo::m_recastSpellID || CGTradeSkillInfo::m_pendingRecastSpellID) { + CGTradeSkillInfo::m_recastSpellID = 0; + CGTradeSkillInfo::m_pendingRecastSpellID = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + } +} + +// VERIFY: da469b43 auto +// OFFSET: 0x005DA020 +void UpdateTradeSkillRecast(int32_t spellId) { + if (spellId == CGTradeSkillInfo::m_recastSpellID) { + CGTradeSkillInfo::m_recastSpellID = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + } + + if (spellId == CGTradeSkillInfo::m_pendingRecastSpellID) { + CGTradeSkillInfo::m_pendingRecastSpellID = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + } +} + +// VERIFY: e58a5a53 manual +// OFFSET: 0x005DA070 +void CGTradeSkillInfo::DoRecast(int32_t spellId) { + if (!CGTradeSkillInfo::m_recastSpellID) { + if (!CGTradeSkillInfo::m_pendingRecastSpellID) { + return; + } + + CGTradeSkillInfo::m_recastSpellID = 0; + CGTradeSkillInfo::m_pendingRecastSpellID = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + return; + } + + if (!CGTradeSkillInfo::m_recastTimes || CGTradeSkillInfo::m_recastSpellID != spellId) { + CGTradeSkillInfo::m_recastSpellID = 0; + CGTradeSkillInfo::m_pendingRecastSpellID = 0; + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + return; + } + + if (--CGTradeSkillInfo::m_recastTimes) { + Spell_C::CastSpell(spellId, nullptr, WOWGUID{ 0 }, false); + FrameScript_SignalEvent(SCRIPT_EVENT_UPDATE_TRADESKILL_RECAST, nullptr); + } else { + CGTradeSkillInfo::m_recastSpellID = 0; + } +} + +// VERIFY: 22405cf4 auto +// OFFSET: 0x005DA0F0 +void CGTradeSkillInfo::CommitPendingRecast(int32_t spellId) { + if (spellId == CGTradeSkillInfo::m_pendingRecastSpellID) { + CGTradeSkillInfo::m_recastSpellID = CGTradeSkillInfo::m_pendingRecastSpellID; + CGTradeSkillInfo::m_recastTimes = CGTradeSkillInfo::m_pendingRecastTimes; + } + + CGTradeSkillInfo::m_pendingRecastTimes = 0; + CGTradeSkillInfo::m_pendingRecastSpellID = 0; +} diff --git a/WoW/Source/Ui/TradeSkillFrame.h b/WoW/Source/Ui/TradeSkillFrame.h index 80819af..a14f03d 100644 --- a/WoW/Source/Ui/TradeSkillFrame.h +++ b/WoW/Source/Ui/TradeSkillFrame.h @@ -2,6 +2,7 @@ #define WOW_SOURCE_UI_TRADESKILLFRAME_H #include +#include "WoW/Source/Object/WGUID.h" struct lua_State; @@ -23,6 +24,9 @@ class CGTradeSkillInfo { static void SetLink(const char* link); static void CommitPendingRecast(int32_t spellId); static void DoRecast(int32_t spellId); + static void StopRecast(); + static bool GetTradeSkillListLink(int32_t spellId, char* buffer, uint32_t bufferSize); + static void SetTradeSkill(int32_t spellId, const WOWGUID& guid, int32_t a3, int32_t a4, int32_t a5); }; int32_t Script_GetTradeSkillInfo(lua_State* L); @@ -56,5 +60,6 @@ int32_t Script_GetTradeSkillRecipeLink(lua_State* L); int32_t Script_GetTradeSkillListLink(lua_State* L); int32_t Script_IsTradeSkillLinked(lua_State* L); void TradeSkillRegisterScriptFunctions(); +void UpdateTradeSkillRecast(int32_t spellId); #endif diff --git a/WoW/Source/Ui/UIMacroOptions.cpp b/WoW/Source/Ui/UIMacroOptions.cpp index 19ed76d..b340df0 100644 --- a/WoW/Source/Ui/UIMacroOptions.cpp +++ b/WoW/Source/Ui/UIMacroOptions.cpp @@ -1 +1,4 @@ #include "UIMacroOptions.h" + +void InitializeMacroOptions() { +} diff --git a/WoW/Source/Ui/UIMacroOptions.h b/WoW/Source/Ui/UIMacroOptions.h index ed5364e..704d97d 100644 --- a/WoW/Source/Ui/UIMacroOptions.h +++ b/WoW/Source/Ui/UIMacroOptions.h @@ -1,4 +1,6 @@ #ifndef WOW_SOURCE_UI_UIMACROOPTIONS_H #define WOW_SOURCE_UI_UIMACROOPTIONS_H +void InitializeMacroOptions(); + #endif diff --git a/WoW/Source/Ui/UIMacros.cpp b/WoW/Source/Ui/UIMacros.cpp index be994f7..d41136b 100644 --- a/WoW/Source/Ui/UIMacros.cpp +++ b/WoW/Source/Ui/UIMacros.cpp @@ -9,6 +9,8 @@ #include "WoW/Source/Object/ObjectClient/Unit_C.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Ui/PetInfo.h" +#include "WoW/Source/Ui/UIMacroOptions.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/AccountData.h" // STATIC: 0x00ACE2A0 static TSExplicitList s_dynamicMacros; @@ -22,6 +24,9 @@ static TSHashTable s_macros; // STATIC: 0x00ACE1E8 static const char* s_macroIconPath = "Interface\\Icons\\"; +// STATIC: 0x00BEAF44 +uint32_t CGUIMacros::m_state; + // STATIC: 0x00BEAF48 const char* CGUIMacros::m_macroRunning; @@ -34,6 +39,12 @@ uint32_t CGUIMacros::m_numMacros; // STATIC: 0x00BEAF54 uint32_t CGUIMacros::m_numCharacterMacros; +// STATIC: 0x00BEAF60 +static uint16_t s_initCounter; + +// STATIC: 0x00BEAF64 +static uint32_t s_pendingLoads; + // VERIFY: 395f9dc1 auto // OFFSET: 0x00564AB0 int32_t CGUIMacros::GetMacroIndexByID(uint32_t id) { @@ -175,3 +186,34 @@ MACRONODE* CGUIMacros::FindMacro(const char* name) { return nullptr; } + +// VERIFY: ebb01234 auto +// OFFSET: 0x0050F4D0 +bool CGUIMacros::IsActionAllowed(uint32_t action) { + return !CGUIMacros::m_macroButton || ((1 << action) & CGUIMacros::m_state); +} + +// VERIFY: 2f0aa8c8 auto +// OFFSET: 0x00565AD0 +void CGUIMacros::RemoveDynamicMacro(MACRONODE* macro) { + s_dynamicMacros.UnlinkNode(macro); +} + +// VERIFY: 4406f3d1 auto +// OFFSET: 0x00566140 +void CGUIMacros::Initialize() { + do { + s_initCounter++; + } while (!s_initCounter); + + InitializeMacroOptions(); + CGUIMacros::LoadIcons(); +} + +// VERIFY: 7d331447 auto +// OFFSET: 0x00567FD0 +void CGUIMacros::LoadMacros() { + s_pendingLoads = 0x30000; + LoadAccountData(4, CGUIMacros::LoadMacrosCallback, reinterpret_cast(static_cast(s_initCounter | 0x10000))); + LoadAccountData(5, CGUIMacros::LoadMacrosCallback, reinterpret_cast(static_cast(s_initCounter | 0x20000))); +} diff --git a/WoW/Source/Ui/UIMacros.h b/WoW/Source/Ui/UIMacros.h index d7d38f1..07328e9 100644 --- a/WoW/Source/Ui/UIMacros.h +++ b/WoW/Source/Ui/UIMacros.h @@ -4,6 +4,8 @@ #include #include #include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/Object/WGUID.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/AccountData.h" struct lua_State; @@ -20,7 +22,8 @@ class MACRONODE : public TSHashObject { /* 056C */ int32_t m_spellFlags; /* 0570 */ uint32_t unk_0570; /* 0574 */ uint32_t m_dynamic; - /* 0578 */ uint8_t unk_0578[12]; + /* 0578 */ WOWGUID m_target; + /* 0580 */ uint32_t unk_0580; /* 0584 */ uint32_t unk_0584; /* 0588 */ uint8_t unk_0588[8]; /* 0590 */ TSLink m_dynamicLink; @@ -32,6 +35,7 @@ class MACRONODE : public TSHashObject { class CGUIMacros { public: + static uint32_t m_state; static const char* m_macroRunning; static MACRONODE* m_macroButton; static uint32_t m_numMacros; @@ -39,12 +43,16 @@ class CGUIMacros { static uint32_t m_sortedMacros[72]; static MACRONODE* FindMacro(const char* name); + static void RemoveDynamicMacro(MACRONODE* macro); + static bool IsActionAllowed(uint32_t action); static void UpdateMacroSpells(); static MACRONODE* GetMacroByID(uint32_t id); static int32_t GetMacroIndexByID(uint32_t id); static MACRONODE* GetMacroByIndex(uint32_t index); static void Initialize(); + static void LoadIcons(); static void LoadMacros(); + static void LoadMacrosCallback(HOSFILE localFile, HOSFILE cacheFile, void* param); static void RunMacro(MACRONODE* macro, const char* button); static void UpdateDynamicMacros(); static void RunMacro(int32_t id, const char* button); @@ -61,8 +69,6 @@ int32_t Script_DeleteMacro(lua_State* L); int32_t Script_EditMacro(lua_State* L); int32_t Script_SetMacroItem(lua_State* L); int32_t Script_GetMacroItem(lua_State* L); -int32_t Script_SetMacroSpell(lua_State* L); -int32_t Script_GetMacroSpell(lua_State* L); int32_t Script_GetNumMacroIcons(lua_State* L); int32_t Script_GetNumMacroItemIcons(lua_State* L); int32_t Script_GetMacroIconInfo(lua_State* L); diff --git a/WoW/Source/Ui/UIMacros_Scripts.cpp b/WoW/Source/Ui/UIMacros_Scripts.cpp index 15eebd7..7c789ae 100644 --- a/WoW/Source/Ui/UIMacros_Scripts.cpp +++ b/WoW/Source/Ui/UIMacros_Scripts.cpp @@ -4,6 +4,12 @@ #include "Engine/Source/FrameScript/FrameScript_Object.h" #include "WoW/Source/Ui/GameUI.h" #include "Engine/Source/lua-5.1/src/lua.h" +#include "Engine/Source/lua-5.1/src/lauxlib.h" +#include "WoW/Source/Ui/SpellBookFrame.h" +#include "WoW/Source/Ui/ActionBarFrame.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" // VERIFY: 3dacc7a5 auto // OFFSET: 0x00564B90 @@ -45,6 +51,88 @@ static int32_t Script_GetRunningMacro(lua_State* L) { return 1; } +// VERIFY: 5ba8c11b manual +// OFFSET: 0x00566DF0 +static MACRONODE* GetMacroFromLua(lua_State* L) { + if (lua_isnumber(L, 1)) { + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + + if (index < 72) { + return CGUIMacros::GetMacroByID(CGUIMacros::m_sortedMacros[index]); + } + } else if (lua_isstring(L, 1)) { + return CGUIMacros::FindMacro(lua_tolstring(L, 1, nullptr)); + } + + return nullptr; +} + +// VERIFY: 2e567c78 auto +// OFFSET: 0x00567320 +static int32_t Script_SetMacroSpell(lua_State* L) { + if (!lua_isstring(L, 2)) { + luaL_error(L, "Usage: SetMacroSpell(macro, spell [,target])"); + return 0; + } + + MACRONODE* macro = GetMacroFromLua(L); + + if (!macro) { + return 0; + } + + int32_t spellId = GetSpellIdByName(lua_tolstring(L, 2, nullptr), ¯o->m_spellFlags); + + if (!spellId) { + spellId = -1; + } + + WOWGUID target = { 0 }; + Script_GetGUIDFromToken(lua_tolstring(L, 3, nullptr), target, false); + + if (macro->m_itemID > 0 || spellId != macro->m_spellID || target != macro->m_target) { + macro->m_target = target; + macro->m_itemID = 0; + macro->m_spellID = spellId; + CGActionBar::UpdateMacro(macro->m_id); + } + + if (macro->m_dynamic) { + macro->m_dynamic = 0; + CGUIMacros::RemoveDynamicMacro(macro); + } + + if (spellId > 0) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: 90bfdb92 auto +// OFFSET: 0x00567450 +static int32_t Script_GetMacroSpell(lua_State* L) { + MACRONODE* macro = GetMacroFromLua(L); + + if (!macro) { + return 0; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(macro->m_spellID, &spell)) { + lua_pushstring(L, spell.m_name); + lua_pushstring(L, spell.m_nameSubtext); + } else { + lua_pushnil(L); + lua_pushnil(L); + } + + return 2; +} + // STATIC: 0x00ACE1F0 static FrameScript_Method s_ScriptFunctions[] = { { "SecureCmdOptionParse", &Script_SecureCmdOptionParse }, diff --git a/WoW/Source/Ui/USEABLESTYLE.h b/WoW/Source/Ui/USEABLESTYLE.h index 66c1c8d..c998bd1 100644 --- a/WoW/Source/Ui/USEABLESTYLE.h +++ b/WoW/Source/Ui/USEABLESTYLE.h @@ -3,11 +3,18 @@ #include #include +#include "Engine/Source/Storm/H/stpl.h" -class USEABLESTYLE { +class BarberShopStyleRec; + +struct STYLEREC : public TSLinkedNode { + /* 0008 */ const BarberShopStyleRec* m_rec; +}; + +class USEABLESTYLE : public TSHashObject { public: - /* 0000 */ uint8_t unk_0000[24]; - /* 0018 */ uint32_t unk_0018[6]; + /* 0018 */ TSList> m_styles; + /* 0024 */ uint32_t unk_0024[3]; }; #endif diff --git a/WoW/Source/Ui/WorldFrame.cpp b/WoW/Source/Ui/WorldFrame.cpp index e4cfab9..44dc38b 100644 --- a/WoW/Source/Ui/WorldFrame.cpp +++ b/WoW/Source/Ui/WorldFrame.cpp @@ -1347,9 +1347,9 @@ void CGWorldFrame::OnFrameSizeChanged(const CRect& rect) { this->m_viewportNDC.maxY = this->m_viewportNDC.maxY < 1.0f ? this->m_viewportNDC.maxY : 1.0f; } -// VERIFY: 8e9977d0 manual +// VERIFY: c2e6c990 manual // OFFSET: 0x004F6560 -static int32_t ObjectCollisionProc(WOWGUID* guid, uint32_t param, World::ObjectCollisionData* data, uint32_t flags) { +static int32_t ObjectCollisionProc(WOWGUID* guid, uintptr_t param, World::ObjectCollisionData* data, uint32_t flags) { CGObject_C* object = ClntObjMgrObjectPtr(*guid, TYPEMASK_OBJECT, __FILE__, __LINE__); if (!object || !object->Unk40(flags) || !(object->m_obj->m_type & TYPEMASK_GAMEOBJECT)) { @@ -1714,9 +1714,9 @@ void CGWorldFrame::OnWorldRender() { CVehiclePassenger_C::PostRenderUpdateAll(); } -// VERIFY: 897b16f5 manual +// VERIFY: 79b17fb9 manual // OFFSET: 0x004F9F70 -int32_t CGWorldFrame::ObjectEnumProc(void* param, uint32_t flags, uint64_t guid, uint32_t a4) { +int32_t CGWorldFrame::ObjectEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4) { CGWorldFrame* frame = CGWorldFrame::s_currentWorldFrame; CGObject_C* object = ClntObjMgrObjectPtr(WOWGUID{ guid }, TYPEMASK_OBJECT, __FILE__, __LINE__); @@ -2390,3 +2390,22 @@ int32_t CGWorldFrame::OnLayerMouseWheel(const CMouseEvent& evt) { int32_t down = CGUIBindings::s_bindings->ExecKey(evt.m_data.m_metaKeyState, binding, 1, 1, static_cast(4)); return CGUIBindings::s_bindings->ExecKey(evt.m_data.m_metaKeyState, binding, 0, 1, static_cast(4)) + down; } + +// VERIFY: 548e1cb9 manual +// OFFSET: 0x004F5910 +int32_t CGWorldFrame::MissileEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4) { + CMissile* missile = reinterpret_cast(a4); + return !missile || missile->m_mapEntity != nullptr; +} + +// VERIFY: c40ba1e3 auto +// OFFSET: 0x004F5930 +int32_t CGWorldFrame::SpellEffectEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4) { + CEffect* effect = reinterpret_cast(a4); + + if (effect) { + effect->UpdateWorldObject(CGWorldFrame::s_currentWorldFrame->m_elapsedSec, flags); + } + + return 1; +} diff --git a/WoW/Source/Ui/WorldFrame.h b/WoW/Source/Ui/WorldFrame.h index b2e9fb9..ae66ca3 100644 --- a/WoW/Source/Ui/WorldFrame.h +++ b/WoW/Source/Ui/WorldFrame.h @@ -123,7 +123,9 @@ class CGWorldFrame : public CSimpleFrame { static void UpdateScreenEffectParams(); static int32_t Update(const void* data, void* param); static void RenderWorld(void* param); - static int32_t ObjectEnumProc(void* param, uint32_t flags, uint64_t guid, uint32_t a4); + static int32_t ObjectEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4); + static int32_t MissileEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4); + static int32_t SpellEffectEnumProc(void* param, uint32_t flags, uint64_t guid, uintptr_t a4); /* 029C */ TSList > m_modelList; /* 02A8 */ TSList > m_hitModelList; diff --git a/WoW/Source/Ui/WorldMap.cpp b/WoW/Source/Ui/WorldMap.cpp index 72da70f..17f44ad 100644 --- a/WoW/Source/Ui/WorldMap.cpp +++ b/WoW/Source/Ui/WorldMap.cpp @@ -25,6 +25,11 @@ #include "WoW/Source/Ui/MinimapFrame.h" #include "WoW/Source/Ui/PartyFrame.h" #include "WoW/Source/Ui/Types.h" +#include +#include +#include "Engine/Source/Base/Coordinate.h" +#include "Engine/Source/Frame/CSimpleModel.h" +#include "Engine/Source/Model2/M2Model.h" // STATIC: 0x00BE8EE0 uint32_t CGWorldMap::m_numLandmarks; @@ -1110,3 +1115,45 @@ const char* CGWorldMap::GetZoneName(uint32_t continent, uint32_t zone) { return areaRec->m_areaName; } + +// VERIFY: 7155245b manual +// OFFSET: 0x005446F0 +static void CenterArrowModel(CSimpleModel* model) { + float x = model->GetWidth() * 0.5f; + float height = model->GetHeight(); + model->m_position.x = x; + model->m_position.y = height * 0.5f; + model->m_position.z = 0.0f; +} + +// VERIFY: b5a7a84c auto +// OFFSET: 0x00544750 +void CGWorldMap::CreateArrowFrame(CSimpleFrame* parent) { + if (!parent) { + return; + } + + if (!CGWorldMap::m_playerArrowFrame) { + void* data = CSimpleModel::s_allocator.GetData(0, typeid(CSimpleModel).raw_name(), SLOG_OBJECT); + CGWorldMap::m_playerArrowFrame = data ? new (data) CSimpleModel(parent) : nullptr; + CGWorldMap::m_playerArrowFrame->SetModel("Interface\\Minimap\\MinimapArrow.mdx"); + CGWorldMap::m_playerArrowFrame->m_modelScale = NDCToDDCHeight(1.0f) * 1.6666666f; + CGWorldMap::m_playerArrowFrame->SetName("PlayerArrowFrame"); + + if (CGWorldMap::m_playerArrowFrame->m_model && CGWorldMap::m_playerArrowFrame->m_model->IsLoaded(0, 0)) { + CenterArrowModel(CGWorldMap::m_playerArrowFrame); + } + } + + if (!CGWorldMap::m_playerArrowEffectFrame) { + void* data = CSimpleModel::s_allocator.GetData(0, typeid(CSimpleModel).raw_name(), SLOG_OBJECT); + CGWorldMap::m_playerArrowEffectFrame = data ? new (data) CSimpleModel(parent) : nullptr; + CGWorldMap::m_playerArrowEffectFrame->SetModel("Interface\\Minimap\\MinimapArrow.mdx"); + CGWorldMap::m_playerArrowEffectFrame->m_modelScale = NDCToDDCHeight(1.0f) * 1.6666666f; + CGWorldMap::m_playerArrowEffectFrame->SetName("PlayerArrowEffectFrame"); + + if (CGWorldMap::m_playerArrowEffectFrame->m_model && CGWorldMap::m_playerArrowEffectFrame->m_model->IsLoaded(0, 0)) { + CenterArrowModel(CGWorldMap::m_playerArrowEffectFrame); + } + } +} diff --git a/WoW/Source/Ui/WorldMap.h b/WoW/Source/Ui/WorldMap.h index 8d90508..551625c 100644 --- a/WoW/Source/Ui/WorldMap.h +++ b/WoW/Source/Ui/WorldMap.h @@ -9,6 +9,7 @@ struct lua_State; class AreaPOIRec; class C3Vector; +class CSimpleFrame; class CSimpleModel; class WorldMapContinentRec; @@ -72,6 +73,7 @@ class CGWorldMap { static CSimpleModel* m_playerMiniArrowFrame; static CSimpleModel* m_playerArrowEffectFrame; static CSimpleModel* m_playerMiniArrowEffectFrame; + static void CreateArrowFrame(CSimpleFrame* parent); static void EnterWorld(); static void InitializeGame(); static void SetMapToCurrentZone(int32_t debug); @@ -100,8 +102,6 @@ int32_t Script_SetMapByID(lua_State* L); int32_t Script_ProcessMapClick(lua_State* L); int32_t Script_GetCorpseMapPosition(lua_State* L); int32_t Script_GetDeathReleasePosition(lua_State* L); -int32_t Script_CreateWorldMapArrowFrame(lua_State* L); -int32_t Script_InitWorldMapPing(lua_State* L); int32_t Script_CreateMiniWorldMapArrowFrame(lua_State* L); int32_t Script_UpdateWorldMapArrowFrames(lua_State* L); int32_t Script_ClickLandmark(lua_State* L); diff --git a/WoW/Source/Ui/WorldMap_Scripts.cpp b/WoW/Source/Ui/WorldMap_Scripts.cpp index 567630e..aaed68c 100644 --- a/WoW/Source/Ui/WorldMap_Scripts.cpp +++ b/WoW/Source/Ui/WorldMap_Scripts.cpp @@ -794,6 +794,65 @@ static int32_t Script_SetMapZoom(lua_State* L) { } // STATIC: 0x00ACCF18 +// VERIFY: 0a301e02 manual +// OFFSET: 0x00545E60 +static int32_t Script_CreateWorldMapArrowFrame(lua_State* L) { + if (lua_type(L, 1) != LUA_TTABLE) { + luaL_error(L, "Usage: CreateWorldMapArrowFrame(parent)"); + } + + lua_rawgeti(L, 1, 0); + CSimpleFrame* parent = static_cast(lua_touserdata(L, -1)); + lua_settop(L, -2); + + if (!parent) { + luaL_error(L, "CreateWorldMapArrowFrame(): Couldn't find 'this' in parent object"); + } + + if (!parent->IsA(CSimpleFrame::GetObjectType())) { + luaL_error(L, "CreateWorldMapArrowFrame(): Wrong object type, expected frame"); + } + + CGWorldMap::CreateArrowFrame(parent); + return 0; +} + +// VERIFY: 230343d0 manual +// OFFSET: 0x00545FF0 +static int32_t Script_InitWorldMapPing(lua_State* L) { + if (lua_type(L, 1) != LUA_TTABLE) { + luaL_error(L, "Usage: InitWorldMapPing(parent)"); + } + + lua_rawgeti(L, 1, 0); + CSimpleFrame* parent = static_cast(lua_touserdata(L, -1)); + lua_settop(L, -2); + + if (!parent) { + luaL_error(L, "InitWorldMapPing(): Couldn't find 'this' in parent object"); + } + + if (!parent->IsA(CSimpleFrame::GetObjectType())) { + luaL_error(L, "InitWorldMapPing(): Wrong object type, expected frame"); + } + + CLayoutFrame* layout = parent->GetLayoutFrameByName("WorldMapPing"); + + if (!layout) { + return 0; + } + + CSimpleModel* ping = static_cast(layout); + + if (!ping) { + return 0; + } + + C3Vector position(layout->GetWidth() * 0.5f, ping->GetHeight() * 0.5f, 0.0f); + ping->SetPosition(position); + return 0; +} + static FrameScript_Method s_ScriptFunctions[] = { { "GetMapContinents", &Script_GetMapContinents }, { "GetMapZones", &Script_GetMapZones }, diff --git a/WoW/Source/WorldClient/DayNight.cpp b/WoW/Source/WorldClient/DayNight.cpp index 81f8b28..752babc 100644 --- a/WoW/Source/WorldClient/DayNight.cpp +++ b/WoW/Source/WorldClient/DayNight.cpp @@ -2829,3 +2829,10 @@ void DayNight::DNStars::Destroy() { this->m_scene = nullptr; } } + +// VERIFY: cfbe1734 manual +// OFFSET: 0x007EE300 +void DayNight::SetFlashColor(CImVector color, float blend) { + DayNight::g_dnInfo.m_flashColor = color; + DayNight::g_dnInfo.m_flashBlend = static_cast(blend * 255.0f); +} diff --git a/WoW/Source/WorldClient/DayNight__DNInfo.h b/WoW/Source/WorldClient/DayNight__DNInfo.h index 2c3bd2c..9f0d4d2 100644 --- a/WoW/Source/WorldClient/DayNight__DNInfo.h +++ b/WoW/Source/WorldClient/DayNight__DNInfo.h @@ -87,6 +87,7 @@ extern DNInfo g_dnInfo; DNInfo* GetInfo(); CImVector LoadLightIntBand(int32_t time, const LightParamsRec* params, int32_t band); +void SetFlashColor(CImVector color, float blend); } // INLINED diff --git a/WoW/Source/WorldClient/Map.h b/WoW/Source/WorldClient/Map.h index 7ee283e..b2cb841 100644 --- a/WoW/Source/WorldClient/Map.h +++ b/WoW/Source/WorldClient/Map.h @@ -116,7 +116,7 @@ class CMapFootprintTexture { CMapFootprintTexture(); }; -typedef int32_t (*MAP_OBJECT_FUNC)(void*, uint32_t, uint64_t, uint32_t); +typedef int32_t (*MAP_OBJECT_FUNC)(void*, uint32_t, uint64_t, uintptr_t); struct MapObjIntersectCandidate { /* 0000 */ CMapObjDef* def; @@ -317,7 +317,8 @@ class CMap { static void ProcessChunkLiquidUpdateList(); static void PrepareMapDoodadDefs(); static void ProcessRenderChunkUpdateList(); - static CMapEntity* ObjectCreate(CM2Model* model, MAP_OBJECT_FUNC func, void* funcParam, uint64_t param64, uint32_t param32, uint32_t a7); + static CMapEntity* ObjectCreate(CM2Model* model, MAP_OBJECT_FUNC func, void* funcParam, uint64_t param64, uintptr_t param32, uint32_t a7); + static CMapEntity* ObjectCreateStatic(CM2Model* model, const C44Matrix& matrix, MAP_OBJECT_FUNC func, void* funcParam, uintptr_t param32); static void ObjectUpdate(CMapEntity* entity, C44Matrix& mat, CAaBox& box, CAaSphere& sphere, C3Vector& vec, bool a6, uint32_t a7); static void PrepareEntitys(int32_t addToScene); static void LinkStaticEntityMultiple2(CMapStaticEntity* entity); diff --git a/WoW/Source/WorldClient/MapEntity.h b/WoW/Source/WorldClient/MapEntity.h index 1ae4099..8da6cda 100644 --- a/WoW/Source/WorldClient/MapEntity.h +++ b/WoW/Source/WorldClient/MapEntity.h @@ -35,10 +35,10 @@ class WMOAreaTableRec; class CMapEntity : public CMapStaticEntity { public: void Tick(); - /* 0090 */ int32_t (*m_func)(void*, uint32_t, uint64_t, uint32_t); + /* 0090 */ int32_t (*m_func)(void*, uint32_t, uint64_t, uintptr_t); /* 0094 */ void* m_funcParam; /* 0098 */ uint64_t m_funcParam64; - /* 00A0 */ uint32_t m_funcParam32; + /* 00A0 */ uintptr_t m_funcParam32; /* 00A4 */ uint32_t unk_00A4; /* 00A8 */ C3Vector unk_00A8; /* 00B4 */ uint32_t unk_00B4; diff --git a/WoW/Source/WorldClient/World.cpp b/WoW/Source/WorldClient/World.cpp index ead00aa..e69dfb5 100644 --- a/WoW/Source/WorldClient/World.cpp +++ b/WoW/Source/WorldClient/World.cpp @@ -442,7 +442,7 @@ TSList > CWorldScene::s_unkList9FreeList = TSExpli C44Matrix CWorldScene::camTransportView; // STATIC: 0x00CE04B0 -int32_t (*World::s_objectCollisionCallback)(WOWGUID* guid, uint32_t param, World::ObjectCollisionData* data, uint32_t flags); +int32_t (*World::s_objectCollisionCallback)(WOWGUID* guid, uintptr_t param, World::ObjectCollisionData* data, uint32_t flags); // STATIC: 0x00ADEE74 static const char* s_invisibleStalkerModel = "InvisibleStalker.m2"; @@ -614,9 +614,9 @@ void World::FindOrCreateDestructibleProxy(CDestructibleProxy* proxy) { CDestructibleProxy::FindOrCreate(proxy); } -// VERIFY: fa5d1384 auto +// VERIFY: f47c89de auto // OFFSET: 0x0077F2B0 -void World::SetObjectCollisionCallback(int32_t (*callback)(WOWGUID* guid, uint32_t param, ObjectCollisionData* data, uint32_t flags)) { +void World::SetObjectCollisionCallback(int32_t (*callback)(WOWGUID* guid, uintptr_t param, ObjectCollisionData* data, uint32_t flags)) { World::s_objectCollisionCallback = callback; } @@ -808,6 +808,34 @@ int32_t World::ObjectIsLoaded(CMapBaseObj* object) { return model->IsLoaded(0, 0); } +// VERIFY: b8f47c0c auto +// OFFSET: 0x007801C0 +void World::ObjectSetShadow(CMapEntity* entity, uint32_t shadow, uint32_t mask) { + if (mask & 0x1) { + entity->unk_007C ^= (entity->unk_007C ^ (shadow << 1)) & 0x2; + } + + if (mask & 0x2) { + entity->unk_007C ^= (entity->unk_007C ^ ~(shadow << 10)) & 0x800; + } + + if (mask & 0x4) { + entity->unk_007C ^= (entity->unk_007C ^ (shadow << 8)) & 0x400; + } + + if (mask & 0x8) { + entity->unk_007C ^= (entity->unk_007C ^ (shadow << 10)) & 0x2000; + } + + if (mask & 0x20) { + if (shadow & 0x20) { + entity->m_flags = static_cast(entity->m_flags | MAPOBJ_FLAG_SHADOW_20000); + } else { + entity->m_flags = static_cast(entity->m_flags & ~MAPOBJ_FLAG_SHADOW_20000); + } + } +} + // VERIFY: 4aa10153 manual // OFFSET: 0x00780240 void CMap::ObjectUpdate(CMapEntity* entity, C44Matrix& mat, CAaBox& box, CAaSphere& sphere, C3Vector& vec, bool a6, uint32_t a7) { @@ -857,9 +885,9 @@ void World::Update(const C3Vector& position) { CMap::PrepareUpdate(false); } -// VERIFY: c32b5640 manual +// VERIFY: 75ab3dc4 manual // OFFSET: 0x00781A10 -CMapEntity* CMap::ObjectCreate(CM2Model* model, MAP_OBJECT_FUNC func, void* funcParam, uint64_t param64, uint32_t param32, uint32_t a7) { +CMapEntity* CMap::ObjectCreate(CM2Model* model, MAP_OBJECT_FUNC func, void* funcParam, uint64_t param64, uintptr_t param32, uint32_t a7) { CMapEntity* entity = CMap::AllocEntity((a7 >> 3) & 0x1); entity->m_model = model; entity->m_funcParam64 = param64; @@ -4490,3 +4518,65 @@ double World::GetFramerate() { return 1000.0; } + +// VERIFY: fa93aad1 auto +// OFFSET: 0x0077F2C0 +void World::ObjectSetUpdateCallback(CMapEntity* entity, int32_t (*func)(void*, uint32_t, uint64_t, uintptr_t), void* param) { + entity->m_func = func; + entity->m_funcParam = param; +} + +// VERIFY: e0c34576 manual +// OFFSET: 0x00782000 +CMapEntity* CMap::ObjectCreateStatic(CM2Model* model, const C44Matrix& matrix, MAP_OBJECT_FUNC func, void* funcParam, uintptr_t param32) { + CMapEntity* entity = CMap::AllocEntity(0); + entity->m_type |= 0x200; + entity->unk_007C = (entity->unk_007C & 0xFFFFA390) | 0x400; + entity->m_flags = MAPOBJ_FLAG_UNPLACED; + entity->m_func = nullptr; + entity->unk_00B4 = 0; + C3Vector ambient = CMap::s_mapLight->m_light.m_ambColor; + CImVector color; + color.b = static_cast(static_cast(ambient.z > 0.0f ? (ambient.z < 1.0f ? ambient.z * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.g = static_cast(static_cast(ambient.y > 0.0f ? (ambient.y < 1.0f ? ambient.y * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.r = static_cast(static_cast(ambient.x > 0.0f ? (ambient.x < 1.0f ? ambient.x * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.a = 0xFF; + entity->unk_00C0 = color; + entity->m_m2AmbientColor = color; + entity->m_funcParam32 = param32; + entity->m_model = model; + entity->m_sphere.c.x = matrix.d0; + entity->m_sphere.c.y = matrix.d1; + entity->m_diffuseLightScale = 1.0f; + entity->m_sphere.c.z = matrix.d2; + entity->unk_00C4 = 1.0f; + entity->m_sphere.r = 0.0f; + entity->m_vec2 = entity->m_sphere.c; + ambient = CMap::s_mapLight->m_light.m_ambColor; + color.b = static_cast(static_cast(ambient.z > 0.0f ? (ambient.z < 1.0f ? ambient.z * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.g = static_cast(static_cast(ambient.y > 0.0f ? (ambient.y < 1.0f ? ambient.y * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.r = static_cast(static_cast(ambient.x > 0.0f ? (ambient.x < 1.0f ? ambient.x * 255.0f + 0.5f : 255.0f) : 0.0f)); + color.a = 0xFF; + entity->unk_00C0 = color; + entity->m_m2AmbientColor = color; + entity->m_scale = sqrtf(matrix.a2 * matrix.a2 + matrix.a1 * matrix.a1 + matrix.a0 * matrix.a0); + entity->m_position.x = matrix.d0; + entity->m_position.y = matrix.d1; + entity->unk_007C |= 0x400; + entity->m_position.z = matrix.d2; + CMap::LinkStaticEntity(entity); + + if (entity->m_model) { + if (!SStrCmpI(s_invisibleStalkerModel, model->m_shared->m_fileNameWithoutPath, STORM_MAX_STR)) { + entity->unk_007C |= 0x4000; + } + + entity->m_model->m_lightingCallback = CMapStaticEntity::ModelLightingCallback; + entity->m_model->m_lightingArg = entity; + entity->m_model->m_refCount++; + } + + entity->m_func = func; + entity->m_funcParam = funcParam; + return entity; +} diff --git a/WoW/Source/WorldClient/World.h b/WoW/Source/WorldClient/World.h index 0a98a1f..3f93636 100644 --- a/WoW/Source/WorldClient/World.h +++ b/WoW/Source/WorldClient/World.h @@ -350,10 +350,10 @@ namespace World { ObjectCollisionData(); }; - extern int32_t (*s_objectCollisionCallback)(WOWGUID* guid, uint32_t param, ObjectCollisionData* data, uint32_t flags); + extern int32_t (*s_objectCollisionCallback)(WOWGUID* guid, uintptr_t param, ObjectCollisionData* data, uint32_t flags); C3Vector* GetCamPos(); - void SetObjectCollisionCallback(int32_t (*callback)(WOWGUID* guid, uint32_t param, ObjectCollisionData* data, uint32_t flags)); + void SetObjectCollisionCallback(int32_t (*callback)(WOWGUID* guid, uintptr_t param, ObjectCollisionData* data, uint32_t flags)); void FindOrCreateDestructibleProxy(CDestructibleProxy* proxy); void CreateWaterRipple(const C3Vector& pos, float a2, float a3, float a4, float a5, float a6, int32_t a7, int32_t a8); int32_t QueryLiquidSounds(CMapEntity* entity, float radius, TSGrowableArray& results); @@ -413,6 +413,7 @@ int32_t ProjectPositionCallback(const C3Vector& position, float& height, void* p void ProjectTextureCallback(const CAaBox& box, const CImVector& color, int32_t index, void* param, int32_t flags); bool MapIsDungeon(); void ObjectDestroy(CMapEntity* entity); +void ObjectSetUpdateCallback(CMapEntity* entity, int32_t (*func)(void*, uint32_t, uint64_t, uintptr_t), void* param); void SetDetailDoodadDensity(int32_t density); void SetDetailDoodadDist(float dist); void SetFarClip(float farClip); @@ -433,6 +434,7 @@ float ValidateFarClip(float farClip, int32_t mapID); int32_t Intersect(const C3Vector& start, const C3Vector& end, C3Vector* hit, float* distance, uint32_t flags, HitTestDebug* debug); void ObjectSetModel(CMapEntity* entity, CM2Model* model); int32_t ObjectIsLoaded(CMapBaseObj* object); + void ObjectSetShadow(CMapEntity* entity, uint32_t shadow, uint32_t mask); void ObjectSetSequenceFinishedCallback(CMapEntity* entity, void (*callback)(CM2Model* model, uint32_t boneId, uint32_t sequenceId, int32_t interrupted, uint32_t time, uint64_t param), uint64_t param, uint16_t doodad); bool ObjectTestConvexVolume(CMapEntity* entity, const C3Vector& point); void ObjectUpdate(CMapEntity* entity, const C44Matrix& matrix); diff --git a/_Triage/AreaList.cpp b/_Triage/AreaList.cpp index c108f2e..9fa298c 100644 --- a/_Triage/AreaList.cpp +++ b/_Triage/AreaList.cpp @@ -7,6 +7,7 @@ #include "WoW/Source/Net/Types.h" #include "WoW/Source/SoundInterface/SoundInterface2.h" #include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/WorldClient/Map.h" #include "WoW/Source/WorldClient/MapEntity.h" #include "WoW/Source/WorldClient/World.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" @@ -236,3 +237,67 @@ void AreaListRegisterLocation(int32_t mapId, CMapEntity* entity) { int32_t subzoneId = area ? area->m_id : 0; CGGameUI::NewZoneFeedback(zone->m_id, subzoneId, s_wmoGroupID, zoneText, subZoneText, realZoneText, World::QueryObjectInside(entity)); } + +// VERIFY: cc53ae16 auto +// OFFSET: 0x0078E960 +void AreaListShutdown() { + s_lastAreaID = -1; + s_lastSubAreaID = -1; + s_lastMapID = -1; + s_inMapObj = 0; + s_lastWMOID = -1; + s_lastWMOHash = -1; + s_lastWMOGroupNum = -1; + s_wmoGroupID = -1; +} + +// VERIFY: f319121e manual +// OFFSET: 0x0078F1F0 +bool AreaListZoneHasBreathParticles(CMapEntity* entity) { + AreaTableRec* area; + + if (!World::QueryObjectInside(entity)) { + uint32_t areaId = 0; + + if (!CMap::QueryAreaId(entity, areaId)) { + return false; + } + + area = g_areaTableDB.GetRecord(areaId); + + if (!area) { + return false; + } + } else { + WMOAreaTableRec* groupRec = nullptr; + WMOAreaTableRec* rootRec = nullptr; + int32_t groupId = 0; + + if (!World::QueryMapObjAreaTable(entity, &groupRec, &rootRec, &groupId)) { + return false; + } + + area = groupRec ? g_areaTableDB.GetRecord(groupRec->m_areaTableID) : nullptr; + + if (!area) { + if (!rootRec) { + return false; + } + + area = g_areaTableDB.GetRecord(rootRec->m_areaTableID); + + if (!area) { + return false; + } + } + } + + AreaTableRec* parent = g_areaTableDB.GetRecord(area->m_parentAreaID); + int32_t flags = area->m_flags; + + if (!(flags & 2) && parent) { + flags = parent->m_flags; + } + + return flags & 1; +} diff --git a/_Triage/PendingSpellCastData.h b/_Triage/PendingSpellCastData.h index 41cd788..4eb9caf 100644 --- a/_Triage/PendingSpellCastData.h +++ b/_Triage/PendingSpellCastData.h @@ -6,6 +6,8 @@ #include "Engine/Source/Tempest/C3Vector.h" #include "WoW/Source/Object/WGUID.h" +class CDataStore; + class PendingSpellCastData { public: /* 0000 */ WOWGUID m_castItem; @@ -47,6 +49,7 @@ class PendingSpellCastData { PendingSpellCastData(); C3Vector GetDestLocation() const; + static void WriteTargetInfo(const PendingSpellCastData* data, CDataStore* msg); }; class CDataStore; diff --git a/_Triage/TIMESTAMPSTRUCT.h b/_Triage/TIMESTAMPSTRUCT.h index b173c4d..dcb3c72 100644 --- a/_Triage/TIMESTAMPSTRUCT.h +++ b/_Triage/TIMESTAMPSTRUCT.h @@ -5,9 +5,17 @@ #include #include "Engine/Source/Storm/H/stpl.h" +class CGameTime; + +struct TIMESTAMPCALLBACK : public TSLinkedNode { + /* 0008 */ void* m_param; + /* 000C */ void (__stdcall* m_callback)(CGameTime* time, void* param); +}; + class TIMESTAMPSTRUCT : public TSHashObject { public: - /* 0018 */ uint32_t unk_0018[6]; + /* 0018 */ TSList> m_callbacks; + /* 0024 */ uint32_t unk_0024[3]; }; #endif