Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vpkpp/PackFileType.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum class PackFileType {
PCK,
VPK,
VPK_VTMB,
WAD3,
ZIP,
};

Expand Down
39 changes: 39 additions & 0 deletions include/vpkpp/format/WAD3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <sourcepp/parser/Binary.h>

#include "../PackFile.h"

namespace vpkpp {

constexpr int8_t WAD3_FILENAME_MAX_SIZE = 16;
constexpr auto WAD3_SIGNATURE = sourcepp::parser::binary::makeFourCC("WAD3");
constexpr std::string_view WAD3_EXTENSION = ".wad";

/**
* Valve GoldSrc WAD3 file
*/
class WAD3 : public PackFile {
public:
/// Create a WAD3 file
static std::unique_ptr<PackFile> create(const std::string& path);

/// Open a WAD3 file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

[[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;

bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

protected:
explicit WAD3(const std::string& fullFilePath_);

void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;

private:
VPKPP_REGISTER_PACKFILE_OPEN(WAD3_EXTENSION, &WAD3::open);
};

} // namespace vpkpp
1 change: 1 addition & 0 deletions include/vpkpp/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "format/PCK.h"
#include "format/VPK.h"
#include "format/VPK_VTMB.h"
#include "format/WAD3.h"
#include "format/ZIP.h"
#include "Attribute.h"
#include "Entry.h"
Expand Down
1 change: 1 addition & 0 deletions lang/c/include/vpkppc/PackFileType.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum {
VPKPP_PACK_FILE_TYPE_PCK,
VPKPP_PACK_FILE_TYPE_VPK,
VPKPP_PACK_FILE_TYPE_VPK_VTMB,
VPKPP_PACK_FILE_TYPE_WAD3,
VPKPP_PACK_FILE_TYPE_ZIP,
} vpkpp_pack_file_type_e;

Expand Down
9 changes: 9 additions & 0 deletions lang/c/include/vpkppc/format/WAD3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "../PackFile.h"

// REQUIRES MANUAL FREE: vpkpp_close
SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_create(const char* path);

// REQUIRES MANUAL FREE: vpkpp_close
SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_open(const char* path, vpkpp_entry_callback_t callback);
2 changes: 2 additions & 0 deletions lang/c/src/vpkppc/_vpkppc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/PCK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK_VTMB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/WAD3.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/ZIP.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Attribute.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Entry.h"
Expand All @@ -25,6 +26,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK_VTMB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/WAD3.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/ZIP.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Convert.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Entry.cpp"
Expand Down
29 changes: 29 additions & 0 deletions lang/c/src/vpkppc/format/WAD3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <vpkppc/format/WAD3.h>

#include <vpkpp/format/WAD3.h>

#include <sourceppc/Helpers.h>

using namespace vpkpp;

SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_create(const char* path) {
SOURCEPP_EARLY_RETURN_VAL(path, nullptr);

auto packFile = WAD3::create(path);
if (!packFile) {
return nullptr;
}
return packFile.release();
}

SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_open(const char* path, vpkpp_entry_callback_t callback) {
SOURCEPP_EARLY_RETURN_VAL(path, nullptr);

auto packFile = WAD3::open(path, callback ? [callback](const std::string& path, const Entry& entry) {
callback(path.c_str(), const_cast<Entry*>(&entry));
} : static_cast<PackFile::EntryCallback>(nullptr));
if (!packFile) {
return nullptr;
}
return packFile.release();
}
52 changes: 52 additions & 0 deletions lang/csharp/src/vpkpp/Format/WAD3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Runtime.InteropServices;

namespace vpkpp.Format
{
using EntryCallback = Action<string, Entry>;

internal static unsafe partial class Extern
{
[DllImport("vpkppc")]
public static extern void* vpkpp_wad3_create([MarshalAs(UnmanagedType.LPStr)] string path);

[DllImport("vpkppc")]
public static extern void* vpkpp_wad3_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback);
}

public class WAD3 : PackFile
{
private protected unsafe WAD3(void* handle) : base(handle) {}

public static WAD3? Create(string path)
{
unsafe
{
var handle = Extern.vpkpp_wad3_create(path);
return handle == null ? null : new WAD3(handle);
}
}

public new static WAD3? Open(string path)
{
unsafe
{
var handle = Extern.vpkpp_wad3_open(path, 0);
return handle == null ? null : new WAD3(handle);
}
}

public new static WAD3? Open(string path, EntryCallback callback)
{
unsafe
{
EntryCallbackNative callbackNative = (path, entry) =>
{
callback(path, new Entry(entry, true));
};
var handle = Extern.vpkpp_wad3_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative));
return handle == null ? null : new WAD3(handle);
}
}
}
}
2 changes: 2 additions & 0 deletions src/vpkpp/_vpkpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/PCK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPK_VTMB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/WAD3.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/ZIP.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/Attribute.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/Entry.h"
Expand All @@ -26,6 +27,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK_VTMB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/WAD3.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/ZIP.cpp"
"${CMAKE_CURRENT_LIST_DIR}/PackFile.cpp")

Expand Down
Loading