diff --git a/source/converter.hpp b/source/converter.hpp index db40c78..6ce714d 100644 --- a/source/converter.hpp +++ b/source/converter.hpp @@ -28,7 +28,6 @@ namespace hellextractor::converter { typedef std::function(helldivers2::data::meta_t meta)> function_t; struct do_register { - public: do_register(std::list types, function_t fn); }; @@ -41,7 +40,7 @@ namespace hellextractor::converter { public: virtual ~base(); base(helldivers2::data::meta_t meta); - + /** Retrieve a list of outputs * * Key is the section that is exported. diff --git a/source/converter_bik.cpp b/source/converter_bik.cpp new file mode 100644 index 0000000..85c7edb --- /dev/null +++ b/source/converter_bik.cpp @@ -0,0 +1,55 @@ +// Copyright 2024 Michael Fabian 'Xaymar' Dirks +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "converter_bik.hpp" +#include +#include +#include "converter.hpp" +#include "endian.h" + +static constexpr uint64_t type = 0x18fa2930f06559aaull; // bik +static constexpr std::string_view section_default = "bik"; + +static auto instance = hellextractor::converter::registry::do_register( + std::list{ + type, + }, + [](helldivers2::data::meta_t meta) { return std::make_shared(meta); }); + +hellextractor::converter::bik::~bik() {} + +hellextractor::converter::bik::bik(helldivers2::data::meta_t meta) : base(meta), _bik(meta) {} + +std::map> hellextractor::converter::bik::outputs() +{ + return { + {std::string{section_default}, + { + _bik.size(), + _bik.extension(), + }}, + }; +} + +void hellextractor::converter::bik::extract(std::string section, std::filesystem::path path) +{ + if (section_default == section) { // Extract "texture" section. + std::ofstream stream{path, std::ios::trunc | std::ios::binary | std::ios::out}; + if (!stream || stream.bad() || !stream.is_open()) { + throw std::runtime_error("Unable to open output file"); + } + + for (auto const& section : _bik.sections()) { + stream.write(reinterpret_cast(section.first), section.second); + } + + stream.close(); + } +} diff --git a/source/converter_bik.hpp b/source/converter_bik.hpp new file mode 100644 index 0000000..6fa307a --- /dev/null +++ b/source/converter_bik.hpp @@ -0,0 +1,28 @@ +// Copyright 2024 Michael Fabian 'Xaymar' Dirks +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once +#include "converter.hpp" +#include "hd2_bik.hpp" +#include "hd2_data.hpp" + +namespace hellextractor::converter { + class bik : public base { + helldivers2::bik _bik; + + public: + virtual ~bik(); + bik(helldivers2::data::meta_t meta); + + std::map> outputs() override; + + void extract(std::string section, std::filesystem::path path) override; + }; +} // namespace hellextractor::converter diff --git a/source/converter_texture.cpp b/source/converter_texture.cpp index 5bd826b..9d8340e 100644 --- a/source/converter_texture.cpp +++ b/source/converter_texture.cpp @@ -16,7 +16,7 @@ #include "hd2_texture.hpp" static constexpr uint64_t type = 0x329ec6a0c63842cdull; // texture -static constexpr std::string_view section_texture = "texture"; +static constexpr std::string_view section_default = "texture"; static auto instance = hellextractor::converter::registry::do_register( std::list{ @@ -31,7 +31,7 @@ hellextractor::converter::texture::texture(helldivers2::data::meta_t meta) : bas std::map> hellextractor::converter::texture::outputs() { return { - {std::string{section_texture}, + {std::string{section_default}, { _texture.size(), _texture.extension(), @@ -41,7 +41,7 @@ std::map> hellextractor::converter:: void hellextractor::converter::texture::extract(std::string section, std::filesystem::path path) { - if (section_texture == section) { // Extract "texture" section. + if (section_default == section) { // Extract "texture" section. std::ofstream stream{path, std::ios::trunc | std::ios::binary | std::ios::out}; if (!stream || stream.bad() || !stream.is_open()) { throw std::runtime_error("Unable to open output file"); diff --git a/source/hd2_bik.cpp b/source/hd2_bik.cpp new file mode 100644 index 0000000..fcf48fa --- /dev/null +++ b/source/hd2_bik.cpp @@ -0,0 +1,40 @@ +// Copyright 2024 Michael Fabian 'Xaymar' Dirks +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "hd2_bik.hpp" + +helldivers2::bik::~bik() {} + +helldivers2::bik::bik(helldivers2::data::meta_t meta) : _meta(meta) +{ + _header = reinterpret_cast(_meta.main); + _data_header = reinterpret_cast(reinterpret_cast(_header) + sizeof(header_t)); + _data_header_sz = _meta.main_size - sizeof(header_t); + _data = reinterpret_cast(_meta.stream ? _meta.stream : _meta.gpu); + _data_sz = _meta.stream_size ? _meta.stream_size : _meta.gpu_size; +} + +size_t helldivers2::bik::size() +{ + return _data_header_sz + _data_sz; +} + +std::string helldivers2::bik::extension() +{ + return "bik"; +} + +std::list> helldivers2::bik::sections() +{ + return { + {_data_header, _data_header_sz}, + {_data, _data_sz}, + }; +} diff --git a/source/hd2_bik.hpp b/source/hd2_bik.hpp new file mode 100644 index 0000000..38fae91 --- /dev/null +++ b/source/hd2_bik.hpp @@ -0,0 +1,45 @@ +// Copyright 2024 Michael Fabian 'Xaymar' Dirks +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once +#include +#include +#include +#include "hd2_data.hpp" + +namespace helldivers2 { + class bik { + public: + struct header_t { + uint32_t __unk0; + uint32_t __unk1; + uint32_t __unk2; + uint32_t __unk3; + }; + + private: + helldivers2::data::meta_t _meta; + header_t const* _header; + uint8_t const* _data_header; + size_t _data_header_sz; + uint8_t const* _data; + size_t _data_sz; + + public: + ~bik(); + bik(helldivers2::data::meta_t meta); + + size_t size(); + + std::string extension(); + + std::list> sections(); + }; +} // namespace helldivers2 diff --git a/source/hd2_texture.hpp b/source/hd2_texture.hpp index eb15ec6..8e4d078 100644 --- a/source/hd2_texture.hpp +++ b/source/hd2_texture.hpp @@ -35,9 +35,9 @@ namespace helldivers2 { helldivers2::data::meta_t _meta; header_t const* _header; uint8_t const* _data_header; - size_t _data_header_sz; + size_t _data_header_sz; uint8_t const* _data; - size_t _data_sz; + size_t _data_sz; public: ~texture(); diff --git a/source/main.cpp b/source/main.cpp index 4b491c6..baa70c8 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -94,7 +94,6 @@ try { // } //} - return 0; } catch (const std::exception& ex) { std::cerr << "Exception: " << ex.what() << std::endl; diff --git a/source/mapped_file.hpp b/source/mapped_file.hpp index 5a9833d..b125e9a 100644 --- a/source/mapped_file.hpp +++ b/source/mapped_file.hpp @@ -16,7 +16,7 @@ class mapped_file { std::filesystem::path _path; std::shared_ptr _file; std::shared_ptr _map; - uint8_t const* _ptr; + uint8_t const* _ptr; public: mapped_file();