Add Some Tools and Assets to create cpp's for 0.9+

This commit is contained in:
2023-03-13 21:19:07 +01:00
parent f6e3c50814
commit 780025bb74
47 changed files with 214 additions and 30355 deletions

9
tools/build_tools.sh Executable file
View File

@ -0,0 +1,9 @@
#Build Tools
echo "Generate Directorys"
mkdir -p bin
echo "Building file2array"
g++ -static -o bin/file2array file2array/file2array.cpp
echo "Building rd7f2afix"
g++ -static -o bin/rd7f2afix rd7f2afix/rd7f2afix.cpp
echo "Finished!"

4
tools/clear_tools.sh Executable file
View File

@ -0,0 +1,4 @@
#Delete Tools
echo "Delete Binary Directory"
rm -rf bin
echo "Finished!"

View File

@ -0,0 +1,43 @@
#include <fstream>
#include <iostream>
#include <vector>
int main(int argc, char *argv[]) {
if (argc < 3) {
std::cout << "Usage:\nfile2array <file> <dstfilename>\n";
return 0;
}
std::string file_path = argv[1];
std::ifstream file(file_path, std::ios::binary);
if (!file.is_open()) {
std::cerr << "[-] Could not open file" << std::endl;
return 1;
}
std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(file), {});
const size_t array_size = buffer.size();
std::ofstream fout(std::string(argv[2]) + ".cpp");
fout << "#include <" << argv[2] << ".hpp>" << std::endl;
fout << "\nunsigned char " << argv[2] << "[] = {";
for (std::size_t i = 0; i < buffer.size(); ++i) {
if (i != 0) {
fout << ", ";
}
fout << "0x" << std::hex << static_cast<int>(buffer[i]);
}
fout << "};" << std::endl;
fout << "\nsize_t " << argv[2] << "_size = 0x" << std::hex << array_size
<< ";" << std::endl;
std::ofstream fhead(std::string(argv[2]) + ".hpp");
fhead << "#pragma once\n#include <cstddef>\n";
fhead << "\nextern unsigned char " << argv[2] << "[];";
fhead << "\nextern size_t " << argv[2] << "_size;";
file.close();
fout.close();
return 0;
}

View File

@ -0,0 +1,46 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
int main(int argc, char *argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " input_file path\n";
return 1;
}
std::string input_filename =
std::filesystem::path(argv[1]).filename().string();
std::string input_path = argv[1];
std::string path = argv[2];
std::string header_filename =
input_filename.substr(0, input_filename.find_last_of(".")) + ".hpp";
std::string include_statement =
"#include <" + path + "/" + header_filename + ">";
std::ifstream input_file(input_path);
if (!input_file.is_open()) {
std::cerr << "Error: Failed to open input file\n";
return 1;
}
std::string input_contents((std::istreambuf_iterator<char>(input_file)),
std::istreambuf_iterator<char>());
input_file.close();
std::regex pattern("#include\\s+<.*\\.hpp>\\s*?");
input_contents =
std::regex_replace(input_contents, pattern, include_statement);
std::ofstream output_file(input_filename);
if (!output_file.is_open()) {
std::cerr << "Error: Failed to open output file for writing\n";
return 1;
}
output_file << input_contents;
output_file.close();
std::cout << "Done! Output written to " << input_filename << std::endl;
std::cout << "Include statement: " << include_statement << std::endl;
return 0;
}