forked from CodeRedModding/CodeRed-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinter.cpp
151 lines (130 loc) · 5.14 KB
/
Printer.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "Printer.hpp"
#include "Engine/Engine.hpp"
namespace Printer
{
void Empty(std::ostringstream& stream)
{
stream.str(std::string());
}
void FillRight(std::ostringstream& stream, char fill, size_t width)
{
stream << std::setfill(fill) << std::setw(width) << std::right;
}
void FillLeft(std::ostringstream& stream, char fill, size_t width)
{
stream << std::setfill(fill) << std::setw(width) << std::left;
}
void FillRight(std::ofstream& stream, char fill, size_t width)
{
stream << std::setfill(fill) << std::setw(width) << std::right;
}
void FillLeft(std::ofstream& stream, char fill, size_t width)
{
stream << std::setfill(fill) << std::setw(width) << std::left;
}
std::string Hex(uintptr_t decimal, size_t width)
{
std::ostringstream stream;
stream << "0x" << std::setfill('0') << std::setw(width) << std::right << std::uppercase << std::hex << decimal;
return stream.str();
}
std::string Hex(uintptr_t decimal, EWidthTypes width)
{
return Hex(decimal, static_cast<size_t>(width));
}
std::string Hex(void* pointer)
{
return Hex(reinterpret_cast<uintptr_t>(pointer), sizeof(uintptr_t));
}
std::string Decimal(uintptr_t hex, size_t width)
{
std::ostringstream stream;
stream << std::setfill('0') << std::setw(width) << std::right << std::uppercase << std::dec << hex;
return stream.str();
}
std::string Decimal(uintptr_t hex, EWidthTypes width)
{
return Decimal(hex, static_cast<size_t>(width));
}
std::string Precision(float value, size_t precision)
{
std::ostringstream stream;
stream << std::setprecision(precision) << value;
return stream.str();
}
void Header(std::ostringstream& stream, const std::string& fileName, const std::string& fileExtension, bool bPragmaPush)
{
stream << "/*\n";
stream << "#############################################################################################\n";
stream << "# " << Configuration::GameName << " (" << Configuration::GameVersion + ") SDK\n";
stream << "# Generated with the " << Engine::GeneratorName << " " << Engine::GeneratorVersion << "\n";
stream << "# ========================================================================================= #\n";
stream << "# File: " << fileName << "." << fileExtension << "\n";
stream << "# ========================================================================================= #\n";
stream << "# Credits: " << Engine::GeneratorCredits << "\n";
stream << "# Links: " << Engine::GeneratorLinks << "\n";
stream << "#############################################################################################\n";
stream << "*/\n";
if ((fileName != "SdkHeaders") && (fileName != "GameDefines"))
{
if (fileExtension == "hpp")
{
stream << "#pragma once\n";
if (Configuration::UsingConstants)
{
stream << "#include \"../SdkConstants.hpp\"\n";
}
}
else if (fileExtension == "cpp")
{
stream << "#include \"../SdkHeaders.hpp\"\n";
}
}
if (bPragmaPush)
{
stream << "\n#ifdef _MSC_VER\n";
stream << "\t#pragma pack(push, 0x" + std::to_string(Configuration::FinalAlignment) + ")\n";
stream << "#endif\n";
}
}
void Header(std::ofstream& stream, const std::string& fileName, const std::string& fileExtension, bool bPragmaPush)
{
std::ostringstream sStream;
Header(sStream, fileName, fileExtension, bPragmaPush);
stream << sStream.str();
}
void Section(std::ostringstream& stream, const std::string& sectionName)
{
stream << "\n/*\n";
stream << "# ========================================================================================= #\n";
stream << "# " << sectionName << "\n";
stream << "# ========================================================================================= #\n";
stream << "*/\n\n";
}
void Section(std::ofstream& stream, const std::string& sectionName)
{
std::ostringstream sStream;
Section(sStream, sectionName);
stream << sStream.str();
}
void Footer(std::ostringstream& stream, bool bPragmaPop)
{
stream << "/*\n";
stream << "# ========================================================================================= #\n";
stream << "#\n";
stream << "# ========================================================================================= #\n";
stream << "*/\n";
if (bPragmaPop)
{
stream << "\n#ifdef _MSC_VER\n";
stream << "\t#pragma pack(pop)\n";
stream << "#endif\n";
}
}
void Footer(std::ofstream& stream, bool bPragmaPop)
{
std::ostringstream sStream;
Footer(sStream, bPragmaPop);
stream << sStream.str();
}
}