~ruther/NosSmooth

ref: f39daa88d90c8afb6bc792aa3c0c8a38d6094a91 NosSmooth/Local/NosSmooth.LocalCore/NostaleString.h -rw-r--r-- 2.6 KiB
f39daa88 — František Boháček feat: call parsing failed packet if parsing failed 3 years ago
                                                                                
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Thanks to atom0s
// https://atom0s.com/forums/viewtopic.php?f=21&t=151&sid=d2fd50008534f41bbc3ab1a8b1ef6a6e

#pragma once

struct NostaleStringA
{
    char*   m_Buffer;
    size_t  m_Length;
 
    NostaleStringA(void)
        : m_Buffer(nullptr)
        , m_Length(0)
    { }
    NostaleStringA(const char* str)
        : m_Buffer(nullptr)
        , m_Length(0)
    {
        this->set(str);
    }
    ~NostaleStringA(void)
    {
        if (this->m_Buffer != nullptr)
            delete[] this->m_Buffer;
        this->m_Buffer = nullptr;
    }
 
    // Returns the size of the string.
    size_t len(void)
    {
        return (this->m_Buffer != nullptr) ? this->m_Length : 0;
    }
 
    // Returns the string within the buffer.
    char* get(void)
    {
        return (this->m_Buffer != nullptr) ? (char*)(this->m_Buffer + 0x08) : nullptr;
    }
 
    // Sets the string buffer.
    void set(const char* str)
    {
        if (this->m_Buffer != nullptr)
            delete[] this->m_Buffer;
 
        this->m_Length = strlen(str);
        this->m_Buffer = new char[this->m_Length + 8 + 1];
 
        *(unsigned int*)(this->m_Buffer + 0x00) = 1; // Reference Count
        *(unsigned int*)(this->m_Buffer + 0x04) = this->m_Length; // Length
        memcpy(this->m_Buffer + 0x08, str, this->m_Length);
        this->m_Buffer[this->m_Length + 0x08] = '\0';
    }
};
 
struct NostaleStringW
{
    wchar_t*    m_Buffer;
    size_t      m_Length;
 
    NostaleStringW(void)
        : m_Buffer(nullptr)
        , m_Length(0)
    { }
    NostaleStringW(const wchar_t* str)
        : m_Buffer(nullptr)
        , m_Length(0)
    {
        this->set(str);
    }
    ~NostaleStringW(void)
    {
        if (this->m_Buffer != nullptr)
            delete[] this->m_Buffer;
        this->m_Buffer = nullptr;
    }
 
    // Returns the size of the string.
    size_t len(void)
    {
        return (this->m_Buffer != nullptr) ? this->m_Length : 0;
    }
 
    // Returns the string within the buffer.
    wchar_t* get(void)
    {
        return (this->m_Buffer != nullptr) ? (wchar_t*)((char*)this->m_Buffer + 0x08) : nullptr;
    }
 
    // Sets the string buffer.
    void set(const wchar_t* str)
    {
        if (this->m_Buffer != nullptr)
            delete[] this->m_Buffer;
 
        this->m_Length = wcslen(str) * 2;
        this->m_Buffer = new wchar_t[this->m_Length + 8 + 1];
 
        *(unsigned int*)((char*)this->m_Buffer + 0x00) = 1; // Reference Count
        *(unsigned int*)((char*)this->m_Buffer + 0x04) = this->m_Length; // Length
        memcpy((char*)this->m_Buffer + 0x08, str, this->m_Length);
        *(wchar_t*)((char*)this->m_Buffer + this->m_Length + 0x08) = L'\0';
    }
};
Do not follow this link