Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
#20 Add converter for .wwise_stream
Browse files Browse the repository at this point in the history
This outputs .wem files, not .wav or similar. Keep as close to the original file as possible.

Fixes #20
  • Loading branch information
Xaymar committed Feb 29, 2024
1 parent 670bc32 commit 36c8d7f
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
55 changes: 55 additions & 0 deletions source/converter_wwise_stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
//
// 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_wwise_stream.hpp"
#include <fstream>
#include <string_view>
#include "converter.hpp"
#include "endian.h"

static constexpr uint64_t type = 0x0e44215d23554b50ull;
static constexpr std::string_view section_default = "wem";

static auto instance = hellextractor::converter::registry::do_register(
std::list<uint64_t>{
type,
},
[](helldivers2::data::meta_t meta) { return std::make_shared<hellextractor::converter::wwise_stream>(meta); });

hellextractor::converter::wwise_stream::~wwise_stream() {}

hellextractor::converter::wwise_stream::wwise_stream(helldivers2::data::meta_t meta) : base(meta), _data(meta) {}

std::map<std::string, std::pair<size_t, std::string>> hellextractor::converter::wwise_stream::outputs()
{
return {
{std::string{section_default},
{
_data.size(),
_data.extension(),
}},
};
}

void hellextractor::converter::wwise_stream::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 : _data.sections()) {
stream.write(reinterpret_cast<char const*>(section.first), section.second);
}

stream.close();
}
}
28 changes: 28 additions & 0 deletions source/converter_wwise_stream.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
//
// 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_data.hpp"
#include "hd2_wwise_stream.hpp"

namespace hellextractor::converter {
class wwise_stream : public base {
helldivers2::wwise_stream _data;

public:
virtual ~wwise_stream();
wwise_stream(helldivers2::data::meta_t meta);

std::map<std::string, std::pair<size_t, std::string>> outputs() override;

void extract(std::string section, std::filesystem::path path) override;
};
} // namespace hellextractor::converter
37 changes: 37 additions & 0 deletions source/hd2_wwise_stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
//
// 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_wwise_stream.hpp"

helldivers2::wwise_stream::~wwise_stream() {}

helldivers2::wwise_stream::wwise_stream(helldivers2::data::meta_t meta) : _meta(meta)
{
_header = reinterpret_cast<decltype(_header)>(_meta.main);
_data = reinterpret_cast<decltype(_data)>(_meta.stream ? _meta.stream : _meta.gpu);
_data_sz = (_meta.stream_size ? _meta.stream_size : _meta.gpu_size) - sizeof(footer_t);
}

size_t helldivers2::wwise_stream::size()
{
return _data_sz;
}

std::string helldivers2::wwise_stream::extension()
{
return "wem";
}

std::list<std::pair<void const*, size_t>> helldivers2::wwise_stream::sections()
{
return {
{_data, _data_sz},
};
}
48 changes: 48 additions & 0 deletions source/hd2_wwise_stream.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
//
// 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 <cinttypes>
#include <cstddef>
#include <list>
#include "hd2_data.hpp"

namespace helldivers2 {
class wwise_stream {
public:
struct header_t {
uint32_t __unk0;
uint32_t __unk1;
uint32_t __unk2;
};

struct footer_t {
uint32_t __unk0;
uint32_t __unk1;
uint32_t __unk2;
};

private:
helldivers2::data::meta_t _meta;
header_t const* _header;
uint8_t const* _data;
size_t _data_sz;

public:
~wwise_stream();
wwise_stream(helldivers2::data::meta_t meta);

size_t size();

std::string extension();

std::list<std::pair<void const*, size_t>> sections();
};
} // namespace helldivers2

0 comments on commit 36c8d7f

Please sign in to comment.