Skip to content

Commit

Permalink
vpkpp: add support for 007 format (closes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Jan 1, 2025
1 parent 0f60123 commit 32c9f8d
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<tr><!-- empty row to disable github striped bg color --></tr>
<tr>
<td rowspan="27"><code>vpkpp</code></td>
<td><a href="https://developer.valvesoftware.com/wiki/Bonus_Maps">BMZ</a></td>
<td align="center">✅</td>
<td>007 v1.1, v1.3 (007 - Nightfire)</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="27" align="center">C<br>C#</td>
</tr>
<tr><!-- empty row to disable github striped bg color --></tr>
<tr>
<td><a href="https://developer.valvesoftware.com/wiki/BSP_(Source)">BSP</a> v17-27</td>
<td><a href="https://developer.valvesoftware.com/wiki/Bonus_Maps">BMZ</a></td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
</tr>
<tr>
<td rowspan="14"><code>vpkpp</code></td>
<td><a href="https://developer.valvesoftware.com/wiki/Bonus_Maps">BMZ</a></td>
<td align="center">✅</td>
<td>007 v1.1, v1.3 (007 - Nightfire)</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="14" align="center">C<br>C#</td>
</tr>
<tr>
<td><a href="https://developer.valvesoftware.com/wiki/BSP_(Source)">BSP</a> v17-27</td>
<td><a href="https://developer.valvesoftware.com/wiki/Bonus_Maps">BMZ</a></td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
Expand Down
48 changes: 48 additions & 0 deletions include/vpkpp/format/OO7.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <array>

#include "../PackFile.h"

namespace vpkpp {

constexpr std::string_view OO7_EXTENSION = ".007";

class OO7 : public PackFileReadOnly {
public:
/// Open a 007 file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "7E4766FD0F7340069AA923C9D3DAB37B";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return OO7::GUID;
}

[[nodiscard]] bool hasPackFileChecksum() const override;

[[nodiscard]] bool verifyPackFileChecksum() const override;

[[nodiscard]] constexpr bool isCaseSensitive() const override {
return true;
}

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

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

[[nodiscard]] explicit operator std::string() const override;

protected:
using PackFileReadOnly::PackFileReadOnly;

uint32_t majorVersion{};
uint32_t minorVersion{};
bool hasChecksum = false;
std::array<std::byte, 16> checksum{};

private:
VPKPP_REGISTER_PACKFILE_OPEN(OO7_EXTENSION, &OO7::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 @@ -8,6 +8,7 @@
#include "format/FPX.h"
#include "format/GCF.h"
#include "format/GMA.h"
#include "format/OO7.h"
#include "format/ORE.h"
#include "format/PAK.h"
#include "format/PCK.h"
Expand Down
9 changes: 9 additions & 0 deletions lang/c/include/vpkppc/format/OO7.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_007_open(const char* path, vpkpp_entry_callback_t callback);

// REQUIRES MANUAL FREE: sourcepp_string_free
SOURCEPP_API sourcepp_string_t vpkpp_007_guid(vpkpp_pack_file_handle_t handle);
2 changes: 2 additions & 0 deletions lang/c/src/vpkppc/_vpkppc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/FPX.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/GCF.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/GMA.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/OO7.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/ORE.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/PAK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/PCK.h"
Expand All @@ -20,6 +21,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/GMA.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/OO7.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
Expand Down
27 changes: 27 additions & 0 deletions lang/c/src/vpkppc/format/OO7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <vpkppc/format/OO7.h>

#include <vpkpp/format/OO7.h>

#include <sourceppc/Convert.hpp>
#include <sourceppc/Helpers.h>

using namespace vpkpp;

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

auto packFile = OO7::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();
}

// REQUIRES MANUAL FREE: sourcepp_string_free
SOURCEPP_API sourcepp_string_t vpkpp_007_guid(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);

return Convert::toString(OO7::GUID);
}
58 changes: 58 additions & 0 deletions lang/csharp/src/vpkpp/Format/OO7.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Runtime.InteropServices;

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

internal static unsafe partial class Extern
{
internal static unsafe partial class OO7
{
[LibraryImport("vpkppc", EntryPoint = "vpkpp_007_open")]
public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback);

[LibraryImport("vpkppc", EntryPoint = "vpkpp_007_guid")]
public static partial sourcepp.String GUID();
}
}

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

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

public new static OO7? Open(string path, EntryCallback callback)
{
unsafe
{
EntryCallbackNative callbackNative = (path, entry) =>
{
callback(path, new Entry(entry, true));
};
var handle = Extern.OO7.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative));
return handle == null ? null : new OO7(handle);
}
}

public static string GUID
{
get
{
unsafe
{
var str = Extern.OO7.GUID();
return sourcepp.StringUtils.ConvertToStringAndDelete(ref str);
}
}
}
}
}
14 changes: 3 additions & 11 deletions src/vpkpp/PackFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,9 @@
#include <sourcepp/FS.h>
#include <sourcepp/String.h>

// Need to include these so the compiler will think the automatic registry
// variables are important enough to initialize :3 (I love C++!)
#include <vpkpp/format/FPX.h>
#include <vpkpp/format/GCF.h>
#include <vpkpp/format/GMA.h>
#include <vpkpp/format/ORE.h>
#include <vpkpp/format/PAK.h>
#include <vpkpp/format/PCK.h>
#include <vpkpp/format/VPK.h>
#include <vpkpp/format/VPK_VTMB.h>
#include <vpkpp/format/ZIP.h>
// Need to include this so the compiler will think the automatic registry
// variables in the formats are important enough to initialize :3 (I love C++!)
#include <vpkpp/vpkpp.h>

using namespace sourcepp;
using namespace vpkpp;
Expand Down
4 changes: 3 additions & 1 deletion src/vpkpp/_vpkpp.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
add_pretty_parser(vpkpp
DEPS libzstd_static MINIZIP::minizip sourcepp_crypto sourcepp_parser sourcepp::kvpp
DEPS libzstd_static miniz MINIZIP::minizip sourcepp_crypto sourcepp_parser sourcepp::kvpp
DEPS_PUBLIC tsl::hat_trie
PRECOMPILED_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/FPX.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/GCF.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/GMA.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/OO7.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/ORE.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/PAK.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/PCK.h"
Expand All @@ -21,6 +22,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/GMA.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/OO7.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
Expand Down
Loading

0 comments on commit 32c9f8d

Please sign in to comment.