Skip to content

Commit a4db647

Browse files
authored
Merge pull request #10 from EctoplasmNWN/erf-extractor
Add Tool_ErfExtractor
2 parents a0a9e91 + da45ad9 commit a4db647

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ There are some tools in the Tools subdirectory:
1818

1919
- 2da_merge allows merging a 2da into a base 2da, overwriting rows that are already present or inserting ones that are not.
2020
- generate_placeable_blueprints allows the user to generate a series of blueprints from placeables defined in 2da using a base blueprint
21-
- key_bif_extractor allows extracting all resources in a KEY from their BIFs.
21+
- key_bif_extractor allows extracting all resources in a KEY from their BIFs.
22+
- erf_extractor allows extracting all resources from an ERF.

Tools/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ add_executable(2da_merge Tool_2daMerge.cpp)
22
target_link_libraries(2da_merge FileFormats)
33
set_target_properties(2da_merge PROPERTIES FOLDER "Tools")
44

5+
add_executable(erf_extractor Tool_ErfExtractor.cpp)
6+
target_link_libraries(erf_extractor FileFormats)
7+
set_target_properties(erf_extractor PROPERTIES FOLDER "Tools")
8+
59
add_executable(key_bif_extractor Tool_KeyBifExtractor.cpp)
610
target_link_libraries(key_bif_extractor FileFormats)
711
set_target_properties(key_bif_extractor PROPERTIES FOLDER "Tools")

Tools/Tool_ErfExtractor.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "FileFormats/Erf.hpp"
2+
#include "Utility/Assert.hpp"
3+
4+
namespace
5+
{
6+
7+
int extract_erf(const char* out_path, const char* in_path)
8+
{
9+
using namespace FileFormats::Erf;
10+
11+
Raw::Erf erf_raw;
12+
bool loaded = Raw::Erf::ReadFromFile(in_path, &erf_raw);
13+
14+
if (!loaded)
15+
{
16+
std::printf("Failed to open %s.", in_path);
17+
return 1;
18+
}
19+
20+
Friendly::Erf erf(std::move(erf_raw));
21+
22+
for (const Friendly::ErfResource& resource : erf.GetResources())
23+
{
24+
char path[512];
25+
sprintf(path, "%s/%s.%s", out_path, resource.m_ResRef.c_str(), FileFormats::Resource::StringFromResourceType(resource.m_ResType));
26+
27+
FILE* file = std::fopen(path, "wb");
28+
if (file)
29+
{
30+
std::printf("Writing %s.\n", path);
31+
std::fwrite(resource.m_DataBlock->GetData(), resource.m_DataBlock->GetDataLength(), 1, file);
32+
std::fclose(file);
33+
}
34+
else
35+
{
36+
std::printf("Failed to open %s\n", path);
37+
}
38+
}
39+
40+
return 0;
41+
}
42+
43+
}
44+
45+
int main(int argc, char** argv)
46+
{
47+
if (argc != 3)
48+
{
49+
std::printf("erf_extractor [out_dir] [erf_path]\n");
50+
return 1;
51+
}
52+
53+
return extract_erf(argv[1], argv[2]);
54+
}

0 commit comments

Comments
 (0)