forked from MontagueM/MontevenDynamicExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexplate.cpp
More file actions
108 lines (94 loc) · 3.27 KB
/
Copy pathtexplate.cpp
File metadata and controls
108 lines (94 loc) · 3.27 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
#include "texplate.h"
bool TexturePlateSet::parse()
{
int fileSize = getData();
if (!fileSize) return false;
uint32_t val;
memcpy((char*)&val, data + 0x18, 4);
dimensionFlag = (val == 4);
TexturePlate* texplate = nullptr;
// can iterate enum?
memcpy((char*)&val, data + 0x28, 4);
texplate = new TexturePlate(uint32ToHexStr(val), packagesPath, "Diffuse");
texplates.push_back(texplate);
memcpy((char*)&val, data + 0x2C, 4);
texplate = new TexturePlate(uint32ToHexStr(val), packagesPath, "Normal");
texplates.push_back(texplate);
memcpy((char*)&val, data + 0x30, 4);
texplate = new TexturePlate(uint32ToHexStr(val), packagesPath, "GStack");
texplates.push_back(texplate);
memcpy((char*)&val, data + 0x34, 4);
// Check to see if we should bother extracting dyemap or not
texplate = new TexturePlate(uint32ToHexStr(val), packagesPath, "Dyemap");
texplates.push_back(texplate);
return true;
}
void TexturePlateSet::saveTexturePlateSet(std::string fullSavePath)
{
for (auto& plate : texplates)
{
plate->savePlate(fullSavePath);
}
}
void TexturePlate::parsePlate()
{
int fileSize = getData();
if (fileSize <= 0x20) return;
uint32_t count;
memcpy((char*)&count, data + 0x30, 4);
uint32_t texHash;
TexplateTexture* tex = nullptr;
for (int i = 0x40; i < 0x40 + count * 20; i += 20)
{
memcpy((char*)&texHash, data + i, 4);
tex = new TexplateTexture(uint32ToHexStr(texHash), packagesPath);
memcpy((char*)&tex->offsetX, data + i + 4, 4);
memcpy((char*)&tex->offsetY, data + i + 8, 4);
memcpy((char*)&tex->scaleX, data + i + 0xC, 4);
memcpy((char*)&tex->scaleY, data + i + 0x10, 4);
textures.push_back(tex);
}
}
void TexturePlate::savePlate(std::string fullSavePath)
{
if (!textures.size()) return;
int maxValue = 0;
for (auto& tex : textures)
{
if (tex->offsetX + tex->scaleX > maxValue)
{
maxValue = tex->offsetX + tex->scaleX;
}
if (tex->offsetY + tex->scaleY > maxValue)
{
maxValue = tex->offsetY + tex->scaleY;
}
}
maxValue = (int)pow(2, ceil(log2(maxValue)));
DXGI_FORMAT dxFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
if (type == "Diffuse")
dxFormat = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
DirectX::ScratchImage OutputPlate;
OutputPlate.Initialize2D(dxFormat, maxValue, maxValue, 1, 0);
for (auto& tex : textures)
{
tex->get();
DirectX::ScratchImage DSResizedImage;
DirectX::Rect imageRect = DirectX::Rect(0, 0, tex->width, tex->height);
DirectX::Resize(*tex->DSImage.GetImage(0, 0, 0), tex->scaleX, tex->scaleY, DirectX::TEX_FILTER_FLAGS::TEX_FILTER_SEPARATE_ALPHA, DSResizedImage);
DirectX::Image Resized = *DSResizedImage.GetImage(0, 0, 0);
DirectX::CopyRectangle(Resized, imageRect, *OutputPlate.GetImage(0, 0, 0), DirectX::TEX_FILTER_FLAGS::TEX_FILTER_SEPARATE_ALPHA, tex->offsetX, tex->offsetY);
tex->DSImage.Release();
DSResizedImage.Release();
free(tex);
}
std::string FileName;
wchar_t* widestr;
FileName = fullSavePath + hash + "_" + type + ".png";
// convert to unicode (utf-16)
int wchars_num = MultiByteToWideChar(CP_ACP, 0, FileName.c_str(), -1, NULL, 0);
widestr = new wchar_t[wchars_num];
MultiByteToWideChar(CP_ACP, 0, FileName.c_str(), -1, widestr, wchars_num);
DirectX::SaveToWICFile(*OutputPlate.GetImage(0, 0, 0), DirectX::WIC_FLAGS::WIC_FLAGS_NONE, GetWICCodec(DirectX::WIC_CODEC_PNG), widestr);
OutputPlate.Release();
}