forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PString.cpp
78 lines (62 loc) · 1.36 KB
/
PString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "StdAfx.h"
#include "PackObj.h"
#include "PString.h"
PString::PString() {
m_szString = NULL;
m_Length = 0;
}
PString::PString(const char* szString)
{
if (!szString) {
m_Length = 0;
m_szString = new char[1];
*m_szString = '\0';
} else {
m_Length = (DWORD)strlen(szString);
m_szString = new char[ m_Length + 1 ];
m_szString[ m_Length ] = '\0';
memcpy(m_szString, szString, m_Length);
}
}
PString::~PString() {
Destroy();
}
void PString::Destroy()
{
if (m_szString)
{
delete [] m_szString;
m_szString = NULL;
}
}
BOOL PString::UnPack(BYTE** ppData, ULONG iSize)
{
DWORD Length;
// Default pack includes 16-bit length.
WORD Length16;
if (!UNPACK(WORD, Length16))
return FALSE;
if (Length16 == 0xFFFF)
{
// If necessary will include 32-bit length.
DWORD Length32;
if (!UNPACK(DWORD, Length32))
return FALSE;
Length = Length32;
}
else
Length = Length16;
if (iSize < Length)
return FALSE;
// Not the real code.
m_Length = Length + 1;
m_szString = new char[ m_Length ];
memcpy(m_szString, *ppData, Length);
m_szString[ Length ] = '\0';
*ppData += Length;
iSize -= Length;
#ifdef PRE_TOD
PACK_ALIGN();
#endif
return TRUE;
}