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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ The Python wrappers can be found on PyPI in the [sourcepp](https://pypi.org/proj
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td rowspan="39"><code>vpkpp</code></td>
<td rowspan="41"><code>vpkpp</code></td>
<td>007 v1.1, v1.3 (007 - Nightfire)</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="39" align="center">C<br>C#<br>Python</td>
<td rowspan="41" align="center">C<br>C#<br>Python</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
Expand Down Expand Up @@ -265,6 +265,12 @@ The Python wrappers can be found on PyPI in the [sourcepp](https://pypi.org/proj
<td align="center">✅</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td>REZ v1-2 (LithTech Engine)</td>
<td align="center">✅</td>
<td align="center">❌</td>
</tr>
<tr><!-- empty row to disable GitHub striped bg color --></tr>
<tr>
<td>SDAT (PS3, Portal 2 &amp; CS:GO)</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -533,6 +539,7 @@ These are only the tools and games using `sourcepp` that I know of. If you would
- HOG parser was contributed by [@erysdren](https://github.com/erysdren).
- OL parser is based on [reverse-engineering work](https://github.com/erysdren/scratch/blob/main/kaitai/worldcraft_ol.ksy) by [@erysdren](https://github.com/erysdren).
- ORE parser is based on [reverse-engineering work](https://github.com/erysdren/narbacular-drop-tools) by [@erysdren](https://github.com/erysdren).
- REZ parser is based on [RezExtract](https://github.com/no-lith/RezExtract) by [@no-lith](https://github.com/no-lith).
- VPP parser was contributed by [@erysdren](https://github.com/erysdren).
- WAD3 parser/writer was contributed by [@ozxybox](https://github.com/ozxybox).
- `vtfpp`
Expand Down
8 changes: 7 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ <h2>Supported Formats</h2>
<td>✅</td>
</tr>
<tr class="support-table-no-offset">
<td rowspan="20">
<td rowspan="21">
vpkpp
<ul>
<li>C</li>
Expand Down Expand Up @@ -676,6 +676,11 @@ <h2>Supported Formats</h2>
<td>✅</td>
<td>✅</td>
</tr>
<tr>
<td>REZ v1-2 (LithTech Engine)</td>
<td>✅</td>
<td>❌</td>
</tr>
<tr>
<td>SDAT (PS3, Portal 2 &amp; CS:GO)</td>
<td>✅</td>
Expand Down Expand Up @@ -890,6 +895,7 @@ <h2>Special Thanks</h2>
<li>HOG parser was contributed by <a href="https://github.com/erysdren" target="_blank" rel="noreferrer">@erysdren</a>.</li>
<li>OL parser is based on <a href="https://github.com/erysdren/scratch/blob/main/kaitai/worldcraft_ol.ksy" target="_blank" rel="noreferrer">reverse-engineering work</a> by <a href="https://github.com/erysdren" target="_blank" rel="noreferrer">@erysdren</a>.</li>
<li>ORE parser is based on <a href="https://github.com/erysdren/narbacular-drop-tools" target="_blank" rel="noreferrer">reverse-engineering work</a> by <a href="https://github.com/erysdren" target="_blank" rel="noreferrer">@erysdren</a>.</li>
<li>REZ parser is based on <a href="https://github.com/no-lith/RezExtract" target="_blank" rel="noreferrer">RezExtract</a> by <a href="https://github.com/no-lith" target="_blank" rel="noreferrer">@no-lith</a>.</li>
<li>VPP parser was contributed by <a href="https://github.com/erysdren" target="_blank" rel="noreferrer">@erysdren</a>.</li>
<li>WAD3 parser/writer was contributed by <a href="https://github.com/ozxybox" target="_blank" rel="noreferrer">@ozxybox</a>.</li>
</ul>
Expand Down
37 changes: 37 additions & 0 deletions include/vpkpp/format/REZ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ReSharper disable CppRedundantQualifier

#pragma once

#include "../PackFile.h"

namespace vpkpp {

constexpr std::string_view REZ_EXTENSION = ".rez";

class REZ : public PackFileReadOnly {
public:
/// Open a REZ 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;

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

[[nodiscard]] std::string_view getFileType() const;

[[nodiscard]] std::string_view getUserTitle() const;

[[nodiscard]] uint32_t getVersion() const;

protected:
using PackFileReadOnly::PackFileReadOnly;

std::string fileType;
std::string userTitle;
uint32_t version;

private:
VPKPP_REGISTER_PACKFILE_OPEN(REZ_EXTENSION, &REZ::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 @@ -17,6 +17,7 @@
#include "format/ORE.h"
#include "format/PAK.h"
#include "format/PCK.h"
#include "format/REZ.h"
#include "format/SDAT.h"
#include "format/TAB.h"
#include "format/VPK.h"
Expand Down
17 changes: 17 additions & 0 deletions lang/c/include/vpkppc/format/REZ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "../PackFile.h"

VPKPP_EXTERNVAR const char* VPKPP_REZ_EXTENSION;

VPKPP_API vpkpp_pack_file_handle_t vpkpp_rez_open(const char* path, vpkpp_entry_callback_t callback); // REQUIRES MANUAL FREE: vpkpp_close
VPKPP_API sourcepp_string_t vpkpp_rez_get_file_type(vpkpp_pack_file_handle_t handle);
VPKPP_API sourcepp_string_t vpkpp_rez_get_user_title(vpkpp_pack_file_handle_t handle);
VPKPP_API uint32_t vpkpp_rez_get_version(vpkpp_pack_file_handle_t handle);

// C++ conversion routines
#ifdef __cplusplus

#include <vpkpp/format/REZ.h>

#endif
1 change: 1 addition & 0 deletions lang/c/include/vpkppc/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "format/ORE.h"
#include "format/PAK.h"
#include "format/PCK.h"
#include "format/REZ.h"
#include "format/SDAT.h"
#include "format/TAB.h"
#include "format/VPK.h"
Expand Down
2 changes: 2 additions & 0 deletions lang/c/src/vpkppc/_vpkppc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_pretty_parser(vpkpp C
"${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"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/REZ.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/SDAT.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/TAB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK.h"
Expand Down Expand Up @@ -39,6 +40,7 @@ add_pretty_parser(vpkpp C
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/REZ.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/SDAT.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/TAB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
Expand Down
47 changes: 47 additions & 0 deletions lang/c/src/vpkppc/format/REZ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <vpkppc/format/REZ.h>

#include <sourceppc/Helpers.h>

using namespace sourceppc;
using namespace vpkpp;

const char* VPKPP_REZ_EXTENSION = REZ_EXTENSION.data();

VPKPP_API vpkpp_pack_file_handle_t vpkpp_rez_open(const char* path, vpkpp_entry_callback_t callback) {
SOURCEPP_EARLY_RETURN_VAL(path, nullptr);

auto packFile = REZ::open(path, callback ? [callback](const std::string& entryPath, const Entry& entry) {
callback(entryPath.c_str(), const_cast<Entry*>(&entry));
} : static_cast<PackFile::EntryCallback>(nullptr));
if (!packFile) {
return nullptr;
}
return packFile.release();
}

VPKPP_API sourcepp_string_t vpkpp_rez_get_file_type(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);

const auto* rez = dynamic_cast<REZ*>(convert::handle<PackFile>(handle));
SOURCEPP_EARLY_RETURN_VAL(rez, SOURCEPP_STRING_INVALID);

return convert::toString(rez->getFileType());
}

VPKPP_API sourcepp_string_t vpkpp_rez_get_user_title(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);

const auto* rez = dynamic_cast<REZ*>(convert::handle<PackFile>(handle));
SOURCEPP_EARLY_RETURN_VAL(rez, SOURCEPP_STRING_INVALID);

return convert::toString(rez->getUserTitle());
}

VPKPP_API uint32_t vpkpp_rez_get_version(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, 0);

const auto* rez = dynamic_cast<REZ*>(convert::handle<PackFile>(handle));
SOURCEPP_EARLY_RETURN_VAL(rez, 0);

return rez->getVersion();
}
12 changes: 12 additions & 0 deletions lang/csharp/src/vpkpp/DLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ internal static partial class DLL
[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_pck_open(string path, EntryCallbackNative? callback);

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_rez_open(string path, EntryCallbackNative? callback);

[LibraryImport(Name)]
public static partial sourcepp.DLL.String vpkpp_rez_get_file_type(nint handle);

[LibraryImport(Name)]
public static partial sourcepp.DLL.String vpkpp_rez_get_user_title(nint handle);

[LibraryImport(Name)]
public static partial uint vpkpp_rez_get_version(nint handle);

[LibraryImport(Name, StringMarshalling = StringMarshalling.Utf8)]
public static partial nint vpkpp_sdat_create(string path);

Expand Down
49 changes: 49 additions & 0 deletions lang/csharp/src/vpkpp/Format/REZ.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;

namespace sourcepp.vpkpp.Format;

using EntryCallback = Action<string, Entry>;
using OpenPropertyRequest = Func<PackFile, OpenProperty, byte[]>;

public class REZ : PackFile
{
protected REZ(nint handle, bool managed = true) : base(handle, managed)
{
}

public new static REZ? Open(string path, EntryCallback? callback = null, OpenPropertyRequest? requestProperty = null)
{
var handle = DLL.vpkpp_rez_open(path, callback is not null ? (entryPath, entry) =>
{
callback(entryPath, new Entry(entry, false));
} : null);
return handle == nint.Zero ? null : new REZ(handle);
}

public string FileType
{
get
{
ThrowIfDisposed();
return new sourcepp.String(DLL.vpkpp_rez_get_file_type(Handle)).Read();
}
}

public string UserTitle
{
get
{
ThrowIfDisposed();
return new sourcepp.String(DLL.vpkpp_rez_get_user_title(Handle)).Read();
}
}

public uint Version
{
get
{
ThrowIfDisposed();
return DLL.vpkpp_rez_get_version(Handle);
}
}
}
18 changes: 13 additions & 5 deletions lang/python/src/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ inline void register_python(py::module_& m) {
.def("get_godot_version", &PCK::getGodotVersion)
.def("set_godot_version", &PCK::setGodotVersion, "major"_a = 0, "minor"_a = 0, "patch"_a = 0);

vpkpp.attr("TAB_EXTENSION") = TAB_EXTENSION;
vpkpp.attr("TAB_FILENAME_MAX_SIZE") = TAB_FILENAME_MAX_SIZE;
vpkpp.attr("TAB_HASHED_FILEPATH_PREFIX") = TAB_HASHED_FILEPATH_PREFIX;
vpkpp.attr("ARC_EXTENSION") = ARC_EXTENSION;
vpkpp.attr("ARC_CHUNK_SIZE") = ARC_CHUNK_SIZE;
vpkpp.attr("REZ_EXTENSION") = REZ_EXTENSION;

py::class_<REZ, PackFileReadOnly>(vpkpp, "REZ")
.def_static("open", &REZ::open, "path"_a, "callback"_a = nullptr)
.def_prop_ro("file_type", &REZ::getFileType)
.def_prop_ro("user_title", &REZ::getUserTitle)
.def_prop_ro("version", &REZ::getVersion);

vpkpp.attr("SDAT_SIGNATURE") = SDAT_SIGNATURE;
vpkpp.attr("SDAT_EXTENSION") = SDAT_EXTENSION;
Expand All @@ -276,6 +278,12 @@ inline void register_python(py::module_& m) {
.def_static("create", &SDAT::create, "path"_a)
.def_static("open", &SDAT::open, "path"_a, "callback"_a = nullptr);

vpkpp.attr("TAB_EXTENSION") = TAB_EXTENSION;
vpkpp.attr("TAB_FILENAME_MAX_SIZE") = TAB_FILENAME_MAX_SIZE;
vpkpp.attr("TAB_HASHED_FILEPATH_PREFIX") = TAB_HASHED_FILEPATH_PREFIX;
vpkpp.attr("ARC_EXTENSION") = ARC_EXTENSION;
vpkpp.attr("ARC_CHUNK_SIZE") = ARC_CHUNK_SIZE;

auto cTAB = py::class_<TAB, PackFile>(vpkpp, "TAB");

py::enum_<TAB::Version>(cTAB, "Version")
Expand Down
2 changes: 2 additions & 0 deletions src/vpkpp/_vpkpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_pretty_parser(vpkpp
"${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"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/REZ.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/SDAT.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/TAB.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/VPK.h"
Expand All @@ -40,6 +41,7 @@ add_pretty_parser(vpkpp
"${CMAKE_CURRENT_LIST_DIR}/format/ORE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PAK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/PCK.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/REZ.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/SDAT.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/TAB.cpp"
"${CMAKE_CURRENT_LIST_DIR}/format/VPK.cpp"
Expand Down
Loading
Loading