-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag_processor.cpp
More file actions
45 lines (37 loc) · 1.47 KB
/
flag_processor.cpp
File metadata and controls
45 lines (37 loc) · 1.47 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
#include "flag_processor.h"
#include <iostream>
#include "SimpleIni.h"
void dump_flags(char* texture, std::string output_file)
{
CSimpleIniA ini;
ini.SetUnicode();
uint8_t mipmap = *((uint32_t*)texture + 5);
uint8_t fixed = *((uint32_t*)texture + 6);
uint8_t clamp = *((uint32_t*)texture + 7);
uint8_t blendmode = *((uint32_t*)texture + 8);
uint8_t compression = (*((uint32_t*)texture + 9) & 0x20) >> 5;
ini.SetLongValue("flags", "mipmap", mipmap);
ini.SetLongValue("flags", "fixed", fixed);
ini.SetLongValue("flags", "clamp", clamp);
ini.SetLongValue("flags", "blendmode", blendmode);
ini.SetLongValue("flags", "VQ compression", compression);
ini.SaveFile(output_file.c_str());
}
void load_flags(char* texture, std::string input_file)
{
CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(input_file.c_str());
uint8_t mipmap = ini.GetLongValue("flags", "mipmap", 0);
uint8_t fixed = ini.GetLongValue("flags", "fixed", 0);
uint8_t clamp = ini.GetLongValue("flags", "clamp", 0);
uint8_t blendmode = ini.GetLongValue("flags", "blendmode", 0);
uint8_t compression = ini.GetLongValue("flags", "VQ compression", 0x20);
*((uint32_t*)texture + 5) = mipmap;
*((uint32_t*)texture + 6) = fixed;
*((uint32_t*)texture + 7) = clamp;
*((uint32_t*)texture + 8) = blendmode;
uint32_t compressionWord = *((uint32_t*)texture + 9);
compressionWord = (compressionWord & ~0x20) | (compression << 5);
*((uint32_t*)texture + 9) = compressionWord;
}