Clone of PhatAC @ https://github.com/floaterxk/PhatAC

FragStack.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "StdAfx.h"
  2. #include "FragStack.h"
  3. FragmentStack::FragmentStack(FragPacket_s *frag)
  4. {
  5. FragHeader_s *header = &frag->header;
  6. m_dwSequence = header->dwSequence;
  7. m_dwID = header->dwID;
  8. m_wGroup = header->wGroup;
  9. m_wCount = header->wCount;
  10. m_pbData = new BYTE[m_wCount * 0x1C0];
  11. m_pbReceived = new bool[m_wCount];
  12. memset(m_pbReceived, 0, sizeof(bool) * m_wCount);
  13. m_wSize = 0;
  14. AddFragment(frag);
  15. }
  16. FragmentStack::~FragmentStack()
  17. {
  18. SafeDeleteArray(m_pbData);
  19. SafeDeleteArray(m_pbReceived);
  20. }
  21. void FragmentStack::AddFragment(FragPacket_s *frag)
  22. {
  23. BYTE* data = frag->data;
  24. DWORD datalen = frag->header.wSize - sizeof(FragHeader_s);
  25. WORD index = frag->header.wIndex;
  26. WORD count = frag->header.wCount;
  27. memcpy(&m_pbData[index * 0x1C0], data, datalen);
  28. m_pbReceived[index] = true;
  29. if (index == (count - 1))
  30. {
  31. m_wSize = (WORD) (((count - 1) * 0x1C0) + datalen);
  32. }
  33. else if (datalen < 0x1C0)
  34. {
  35. //Size should never be less than 0x1C0 if it isn't the last chunk
  36. LOG(Temp, Normal, "This should never happen\n");
  37. }
  38. }
  39. bool FragmentStack::IsComplete(void)
  40. {
  41. for (int i = 0; i < m_wCount; i++)
  42. {
  43. if (m_pbReceived[i] != true) { return false; }
  44. }
  45. return true;
  46. }
  47. int FragmentStack::GetLength(void)
  48. {
  49. return m_wSize;
  50. }
  51. BYTE *FragmentStack::GetData(void)
  52. {
  53. return m_pbData;
  54. }