-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropColorCompiler.h
More file actions
233 lines (209 loc) · 5.93 KB
/
PropColorCompiler.h
File metadata and controls
233 lines (209 loc) · 5.93 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//========= Copyright Satjo Interactive 2025, All rights reserved. ============//
//
// Оригинальный код написан: Tirmiks
// Отдельные благодарности: ugo_zapad, Ambiabstract, MyCbEH
//
//=============================================================================//
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
#include <windows.h>
#include <algorithm>
#include <map>
#include <set>
#include <sstream>
#include <filesystem>
namespace fs = std::filesystem;
#pragma pack(push, 1)
struct Vector
{
float x, y, z;
};
struct StudioHdr
{
int id;
int version;
int checksum;
char name[64];
int length;
Vector eyeposition;
Vector illumposition;
Vector hull_min;
Vector hull_max;
Vector view_bbmin;
Vector view_bbmax;
int flags;
int numbones;
int boneindex;
int numbonecontrollers;
int bonecontrollerindex;
int numhitboxsets;
int hitboxsetindex;
int numlocalanim;
int localanimindex;
int numlocalseq;
int localseqindex;
int activitylistversion;
int eventsindexed;
int numtextures;
int textureindex;
int numcdtextures;
int cdtextureindex;
int numskinref;
int numskinfamilies;
int skinindex;
int numbodyparts;
int bodypartindex;
int numlocalattachments;
int localattachmentindex;
int numlocalnodes;
int localnodeindex;
int localnodenameindex;
int numflexdesc;
int flexdescindex;
int numflexcontrollers;
int flexcontrollerindex;
int numflexrules;
int flexruleindex;
int numikchains;
int ikchainindex;
int nummouths;
int mouthindex;
int numlocalposeparameters;
int localposeparamindex;
int surfacepropindex;
int keyvalueindex;
int keyvaluesize;
int numlocalikautoplaylocks;
int localikautoplaylockindex;
float mass;
int contents;
int numincludemodels;
int includemodelindex;
int virtualModel;
int szanimblocknameindex;
int numanimblocks;
int animblockindex;
int animblockModel;
int bonetablebynameindex;
int pVertexBase;
int pIndexBase;
unsigned char constdirectionallightdot;
unsigned char rootLOD;
unsigned char numAllowedRootLODs;
unsigned char unused1;
int unused4;
int numflexcontrollerui;
int flexcontrolleruiindex;
float flVertAnimFixedPointScale;
int unused3;
int studiohdr2index;
int unused2;
};
struct StudioHdr2
{
int numsrcbonetransform;
int srcbonetransformindex;
int illumpositionattachmentindex;
float flMaxEyeDeflection;
int linearboneindex;
int sznameindex;
int m_nBoneFlexDriverCount;
int m_nBoneFlexDriverIndex;
int unused[56];
};
struct Texture
{
int sznameindex;
int flags;
int used;
int unused1;
int material;
int clientmaterial;
int unused[10];
};
struct PostCompilePropInfo {
std::string originalModel;
std::string coloredModel;
std::string rendercolor;
int skin;
size_t startPos;
size_t endPos;
};
#pragma pack(pop)
class MDLFile
{
private:
std::vector<unsigned char> fileData;
std::vector<unsigned char> newFileData;
StudioHdr* header;
StudioHdr2* header2;
std::vector<std::string> textureNames;
std::vector<std::string> textureDirs;
std::vector<std::vector<short>> skinFamilies;
std::string surfaceProp;
std::string keyValues;
int alreadyEditedOffset;
public:
bool Load(const std::string& filename);
bool Save(const std::string& filename);
bool AddMaterial(const std::string& materialPath);
bool AddMaterialWithSkin(const std::string& materialPath);
bool AddMultipleMaterialsWithSkins(const std::vector<std::string>& materialPaths);
std::vector<std::string> GetTextureNames() const { return textureNames; }
std::vector<std::string> GetTextureDirs() const { return textureDirs; }
private:
void ParseTextures();
void ParseTextureDirs();
void ParseSkinFamilies();
void ParseSurfaceProp();
void ParseKeyValues();
std::string ReadString(int offset);
int FindAlreadyEditedMarker();
void RebuildMDLFile(const std::vector<std::string>& newTextureNames,
const std::vector<std::vector<short>>& newSkinFamilies,
const std::vector<std::string>& newTextureDirs);
};
class HammerCompiler
{
private:
std::string vmfPath;
std::string gameDir;
std::vector<PostCompilePropInfo> postCompileProps;
struct EntityInfo {
std::string model;
std::string rendercolor;
int skin = 0;
size_t startPos;
size_t endPos;
};
struct ModelColorInfo
{
std::set<std::string> colors;
std::vector<EntityInfo*> entities;
};
std::vector<std::string> createdFiles;
std::vector<EntityInfo> entities;
std::map<std::string, ModelColorInfo> modelData;
public:
HammerCompiler(const std::string& vmfPath, const std::string& gameDir);
bool ProcessVMF();
bool ProcessModels();
bool UpdateVMF();
void AddCreatedFile(const std::string& filePath);
bool SaveCreatedFilesList();
bool DeleteCreatedFiles();
bool ParseVMFForPostCompile();
bool AddFilesToBSP(const std::string& bspPath, const std::string& gameDir);
bool RestoreVMFAfterPostCompile();
std::string RestoreEntityContent(const std::string& entityContent);
private:
bool ParseVMF();
bool CopyModelFiles(const std::string& originalModelPath);
std::string CreateVMTContent(const std::string& originalContent, const std::string& newBaseTexture, const std::string& color);
std::string ReadFileContent(const std::string& path);
bool WriteFileContent(const std::string& path, const std::string& content);
};