Skip to content

Instantly share code, notes, and snippets.

@mrowrpurr
Last active January 2, 2023 23:52
Show Gist options
  • Save mrowrpurr/10345744bd71c4bed0cc0965643ed6eb to your computer and use it in GitHub Desktop.
Save mrowrpurr/10345744bd71c4bed0cc0965643ed6eb to your computer and use it in GitHub Desktop.
Read Papyrus script docstring comment from .pex

Read Papyrus .pex Docstring Comment

Example Script

scriptName MyScript
{This is the text that we are looking for, right here.

Oh, and it can have newlines.}

C++ code (using Champollion)

#include <Pex/FileReader.hpp>
#include <filesystem>
#include <format>
#include <iostream>

int main() {
    auto path = std::filesystem::current_path() / "../../MyScript.pex";
    auto pex = Pex::Binary();
    auto reader = Pex::FileReader(path.string());
    reader.read(pex);
    std::cout << pex.getObjects().front().getDocString().asString();
    // Prints out "This is the text that we are looking for, right here.\n\nOh..."
}
cmake_minimum_required(VERSION 3.21)
project(PexDocStringReader)
find_package(Champollion CONFIG REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Champollion::Champollion)
{
"version": 3,
"configurePresets": [
{
"name": "Debug",
"displayName": "Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"architecture": { "value": "x64", "strategy": "external" },
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_CXX_FLAGS": "/std:c++20 /permissive- /Zc:preprocessor /EHsc /MP /W4 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -DUNICODE -D_UNICODE",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md",
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}
#include <Pex/FileReader.hpp>
#include <filesystem>
#include <format>
#include <iostream>
int main() {
auto path = std::filesystem::current_path() / "../../MyScript.pex";
auto pex = Pex::Binary();
auto reader = Pex::FileReader(path.string());
reader.read(pex);
std::cout << pex.getObjects().front().getDocString().asString();
// Prints out "This is the text that we are looking for, right here.\n..."
}
scriptName MyScript
{This is the text that we are looking for, right here.
Oh, and it can have newlines.}
<PapyrusProject Flags="TESV_Papyrus_Flags.flg" Game="sse" Output=".">
<Imports>
<Import>C:\Program Files (x86)\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source</Import>
</Imports>
<Folders>
<Folder>.</Folder>
</Folders>
</PapyrusProject>
{
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg.git",
"baseline": "cc288af760054fa489574bd8e22d05aa8fa01e5c"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/SkyrimScripting/vcpkg-dev.git",
"baseline": "6bef2935934077c80b5a1278946c3c31c9e5a975",
"packages": ["champollion"]
}
]
}
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "example",
"version-string": "0.0.1",
"dependencies": ["champollion"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment