mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-31 05:15:54 -05:00
Compare commits
56 Commits
ImHex-v1.3
...
ImHex-v1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0bb71be58 | ||
|
|
c7fc39ac19 | ||
|
|
b540ead0ae | ||
|
|
26878548f0 | ||
|
|
e4c9d86755 | ||
|
|
2a3de1b705 | ||
|
|
e02280f9ee | ||
|
|
bbba68cef7 | ||
|
|
28b281b403 | ||
|
|
c807959d75 | ||
|
|
3416d30f2b | ||
|
|
10bf1c76cf | ||
|
|
5b7c212029 | ||
|
|
1c2e948940 | ||
|
|
7ea34e410a | ||
|
|
56950e44d8 | ||
|
|
ed42452fc1 | ||
|
|
a68ecb8888 | ||
|
|
8d4cf59497 | ||
|
|
3c2fed22e4 | ||
|
|
ff550bd105 | ||
|
|
0ad6e3abde | ||
|
|
891968db53 | ||
|
|
5799d1d7ea | ||
|
|
9c6bfeb50f | ||
|
|
9f7cdded6a | ||
|
|
03298b0b0c | ||
|
|
5f2738872e | ||
|
|
63585e6de7 | ||
|
|
cb6caafa64 | ||
|
|
236fadee47 | ||
|
|
0549e62a14 | ||
|
|
b4bf2b946f | ||
|
|
5e82bfadac | ||
|
|
a5c9f3b18a | ||
|
|
38262e6bb9 | ||
|
|
0a37b60d70 | ||
|
|
345e264ff8 | ||
|
|
ba2c396534 | ||
|
|
439f04e19b | ||
|
|
eaeea8d093 | ||
|
|
9af8d7e693 | ||
|
|
dac2e0f786 | ||
|
|
f70b7066b9 | ||
|
|
3f44a743e8 | ||
|
|
834e5261b3 | ||
|
|
0e2966f10d | ||
|
|
b2bc248447 | ||
|
|
e6589ecba1 | ||
|
|
f75ba4b6ee | ||
|
|
cf18580960 | ||
|
|
e7d1973957 | ||
|
|
35cc68544b | ||
|
|
41d8967deb | ||
|
|
658ec20b37 | ||
|
|
fb5fcbafc1 |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,2 +1,4 @@
|
||||
*.pat linguist-language=Rust
|
||||
*.hexpat linguist-language=Rust
|
||||
|
||||
tests/patterns/test_data/** binary
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
## Checklist
|
||||
- [ ] A pattern for this format doesn't exist yet (or this PR improves the existing one)
|
||||
- [ ] The new pattern has been added to the relevant table in the Readme
|
||||
- [ ] The new pattern has a description pragma (`#pragma description My pattern Description here`)
|
||||
- [ ] The pattern was associated with all relevant MIME types (using `#pragma MIME mime-type` in the source code)
|
||||
- Make sure to never use `application/octet-stream` here as that means "Unidentifiable binary data"
|
||||
- [ ] A test file for this pattern has been added to [/tests/patterns/test_data](/tests/patterns/test_data)
|
||||
|
||||
25
.github/workflows/tests.yml
vendored
25
.github/workflows/tests.yml
vendored
@@ -28,6 +28,7 @@ jobs:
|
||||
sudo apt update
|
||||
sudo apt install -y \
|
||||
build-essential \
|
||||
ccache \
|
||||
gcc-12 \
|
||||
g++-12 \
|
||||
lld \
|
||||
@@ -41,12 +42,21 @@ jobs:
|
||||
|
||||
sudo pip install jsonschema
|
||||
|
||||
- name: 📜 Setup ccache
|
||||
uses: hendrikmuhs/ccache-action@v1
|
||||
with:
|
||||
key: ${{ runner.os }}-ccache-${{ github.run_id }}
|
||||
restore-keys: ${{ runner.os }}-ccache
|
||||
max-size: 1G
|
||||
|
||||
- name: 🛠️ Build
|
||||
run: |
|
||||
cd tests
|
||||
mkdir -p build
|
||||
cd build
|
||||
CC=gcc-12 CXX=g++-12 cmake \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_C_FLAGS="-fuse-ld=lld --coverage" \
|
||||
-DCMAKE_CXX_FLAGS="-fuse-ld=lld --coverage" \
|
||||
-DLIBPL_ENABLE_TESTS=OFF \
|
||||
@@ -57,20 +67,7 @@ jobs:
|
||||
- name: 🧪 Perform Unit Tests
|
||||
run: |
|
||||
cd tests/build
|
||||
ctest --output-on-failure
|
||||
|
||||
#- name: ⚗️ Generate Coverage Report
|
||||
# run: |
|
||||
# cd tests/build
|
||||
# lcov -d ./_deps/pattern_language-build/lib --gcov-tool /usr/bin/gcov-12 -c -o coverage.info
|
||||
|
||||
#- name: ⬆️ Upload Coverage Report
|
||||
# uses: coverallsapp/github-action@master
|
||||
# env:
|
||||
# NODE_OPTIONS: --max-old-space-size=8000
|
||||
# with:
|
||||
# github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# path-to-lcov: tests/build/coverage.info
|
||||
ctest --output-on-failure -j 4
|
||||
|
||||
- name: 📎 Validate JSON Files
|
||||
run: |
|
||||
|
||||
24
README.md
24
README.md
@@ -1,6 +1,7 @@
|
||||
# ImHex Database
|
||||
|
||||
This repository serves as a database for files to use with the [ImHex Hex Editor](https://github.com/WerWolv/ImHex). It currently contains
|
||||
|
||||
- [Patterns](/patterns) - Binary Format definitions for the Pattern Language
|
||||
- [Pattern Libraries](/includes) - Libraries that make using the Pattern Language easier
|
||||
- [Magic Files](/magic) - Custom magic file definitions for the use with libmagic
|
||||
@@ -25,6 +26,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| 3DS | | [`patterns/3ds.hexpat`](patterns/3ds.hexpat) | Autodesk 3DS Max Model file |
|
||||
| 7Z | | [`patterns/7z.hexpat`](patterns/7z.hexpat) | 7z File Format |
|
||||
| AFE2 | | [`patterns/afe2.hexpat`](patterns/afe2.hexpat) | Nintendo Switch Atmosphère CFW Fatal Error log |
|
||||
| ANI | `application/x-navi-animation` | [`patterns/ani.hexpat`](patterns/ani.hexpat) | Windows Animated Cursor file |
|
||||
| AR | `application/x-archive` | [`patterns/ar.hexpat`](patterns/ar.hexpat) | Static library archive files |
|
||||
| ARIA2 | | [`patterns/aria2.hexpat`](patterns/aria2.hexpat) | ARIA2 Download Manager Control files |
|
||||
| ARM VTOR | | [`patterns/arm_cm_vtor.hexpat`](patterns/arm_cm_vtor.hexpat) | ARM Cortex M Vector Table Layout |
|
||||
@@ -48,6 +50,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| DMG | | [`patterns/dmg.hexpat`](patterns/dmg.hexpat) | Apple Disk Image Trailer (DMG) |
|
||||
| DS_Store | | [`patterns/dsstore.hexpat`](patterns/dsstore.hexpat) | .DS_Store file format |
|
||||
| DTA | | [`patterns/max_v104.hexpat`](patterns/max_v104.hexpat) | Mechanized Assault and Exploration v1.04 (strategy game) save file format |
|
||||
| DTED | | [`patterns/dted.hexpat`](patterns/dted.hexpat) | Digital Terrain Elevation Data (DTED) |
|
||||
| ELF | `application/x-executable` | [`patterns/elf.hexpat`](patterns/elf.hexpat) | ELF header in elf binaries |
|
||||
| EVTX | | [`patterns/evtx.hexpat`](patterns/evtx.hexpat) | MS Windows Vista Event Log |
|
||||
| FAS | | [`patterns/fas_oskasoftware.hexpat`](patterns/fas_oskasoftware.hexpat) [`patterns/fas_oskasoftware_old.hexpat`](patterns/fas_oskasoftware_old.hexpat) (Old versions of Oska DeskMate) | Oska Software DeskMates FAS (Frames and Sequences) file |
|
||||
@@ -56,6 +59,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System |
|
||||
| FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format |
|
||||
| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Gameboy ROM |
|
||||
| GGUF | | [`patterns/gguf.hexpat`](patterns/gguf.hexpat) | GGML Inference Models |
|
||||
| GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files |
|
||||
| GZIP | `application/gzip` | [`patterns/gzip.hexpat`](patterns/gzip.hexpat) | GZip compressed data format |
|
||||
| Halo Bitmap || [`patterns/hinf_bitmap.hexpat`](patterns/hinf_bitmap.hexpat) | Halo Infinite Bitmap tag files |
|
||||
@@ -78,28 +82,33 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
|
||||
| NE | | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
|
||||
| nes | | [`patterns/nes.hexpat`](patterns/nes.hexpat) | .nes file format |
|
||||
| NotepadWindowState | | [`patterns/notepad-windowstate.hexpat`](patterns/notepad-windowstate.hexpat) | Windows 11 Notepad - Window State .bin file |
|
||||
| NRO | | [`patterns/nro.hexpat`](patterns/nro.hexpat) | Nintendo Switch NRO files |
|
||||
| NTAG | | [`patterns/ntag.hexpat`](patterns/ntag.hexpat) | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC |
|
||||
| OGG | `audio/ogg` | [`patterns/ogg.hexpat`](patterns/ogg.hexpat) | OGG Audio format |
|
||||
| PAK | | [`patterns/xgspak.hexpat`](patterns/xgspak.hexpat) | Exient XGS Engine Pak files |
|
||||
| PCAP | `application/vnd.tcpdump.pcap` | [`patterns/pcap.hexpat`](patterns/pcap.hexpat) | pcap header and packets |
|
||||
| PCX | `application/x-pcx` | [`patterns/pcx.hexpat`](patterns/pcx.hexpat) | PCX Image format |
|
||||
| PE | `application/x-dosexec` `application/x-msdownload` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
|
||||
| PP | | [`patterns/selinuxpp.hexpat`](patterns/selinuxpp.pat) | SE Linux package |
|
||||
| PFS0 | | [`patterns/pfs0.hexpat`](patterns/pfs0.hexpat) | Nintendo Switch PFS0 archive (NSP files) |
|
||||
| PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format |
|
||||
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
|
||||
| PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO |
|
||||
| Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding |
|
||||
| PyInstaller | | [`patterns/pyinstaller.hexpat`](patterns/pyinstaller.hexpat) | PyInstaller binray files |
|
||||
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
|
||||
| PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO |
|
||||
| Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding |
|
||||
| PyInstaller | | [`patterns/pyinstaller.hexpat`](patterns/pyinstaller.hexpat) | PyInstaller binray files |
|
||||
| PYC | | [`patterns/pyc.hexpat`](patterns/pyc.hexpat) | Python bytecode files |
|
||||
| QBCL | | [`patterns/qbcl.hexpat`](patterns/qbcl.hexpat) | Qubicle voxel scene project file |
|
||||
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
|
||||
| RAS | `image/x-sun-raster` | [`patterns/ras.hexpat`](patterns/ras.hexpat) | RAS image files |
|
||||
| ReFS | | [`patterns/refs.hexpat`](patterns/refs.hexpat) | Microsoft Resilient File System |
|
||||
| Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format |
|
||||
| shp | | [`patterns/shp.hexpat`](patterns/shp.hexpat) | ESRI shape file |
|
||||
| shx | | [`patterns/shx.hexpat`](patterns/shx.hexpat) | ESRI index file |
|
||||
| SPIRV | | [`patterns/spirv.hexpat`](patterns/spirv.hexpat) | SPIR-V header and instructions |
|
||||
| STL | `model/stl` | [`patterns/stl.hexpat`](patterns/stl.hexpat) | STL 3D Model format |
|
||||
| StuffItV5 | `application/x-stuffit` | [`patterns/sit5.hexpat`](patterns/sit5.hexpat) | StuffIt V5 archive |
|
||||
| SWF | |[`patterns/swf.hexpat`](patterns/swf.hexpat) | Shockwave Flash file format |
|
||||
| TAR | `application/x-tar` | [`patterns/tar.hexpat`](patterns/tar.hexpat) | Tar file format |
|
||||
| TIFF | `image/tiff` | [`patterns/tiff.hexpat`](patterns/tiff.hexpat) | Tag Image File Format |
|
||||
| TGA | `image/tga` | [`patterns/tga.hexpat`](patterns/tga.hexpat) | Truevision TGA/TARGA image |
|
||||
@@ -113,7 +122,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| WAS | | [`patterns\was_oskasoftware.hexpat`](patterns\was_oskasoftware.hexpat) | Oska Software DeskMates WAS/WA3 (WAVE/MP3 Set) file
|
||||
| WAD | | [`patterns/wad.hexpat`](patterns/wad.hexpat) | DOOM WAD Archive |
|
||||
| XBEH | `audio/x-xbox-executable` | [`patterns/xbeh.hexpat`](patterns/xbeh.hexpat) | Xbox executable |
|
||||
| XCI | | [`patterns/xci.hexpat`](patterns/xci.hexpat) | Nintendo Switch XCI cardridge ROM |
|
||||
| XCI | | [`patterns/xci.hexpat`](patterns/xci.hexpat) | Nintendo Switch XCI cartridge ROM |
|
||||
| XGT | | [`patterns/xgt.hexpat`](patterns/xgstexture.hexpat) | Exient XGS Engine Texture |
|
||||
| Xilinx BIT | | [`patterns/xilinx_bit.hexpat`](patterns/xilinx_bit.hexpat) | Xilinx FPGA Bitstreams |
|
||||
| Xilinx Bootgen | | [`patterns/xilinx_bootgen.hexpat`](patterns/xilinx_bootgen.hexpat) | Xilinx ZynqMP Boot Images |
|
||||
| ZIP | `application/zip` | [`patterns/zip.hexpat`](patterns/zip.hexpat) | End of Central Directory Header, Central Directory File Headers |
|
||||
@@ -168,6 +178,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| ASCII+OEM | [`encodings/ascii_oem.tbl`](encodings/ascii_oem.tbl) | ASCII encoding with Windows OEM characters |
|
||||
| Baltic ISO | [`encodings/baltic_iso.tbl`](encodings/baltic_iso.tbl) | Baltic ISO encoding |
|
||||
| Baltic Windows | [`encodings/baltic_windows.tbl`](encodings/baltic_windows.tbl) | Baltic Windows encoding |
|
||||
| Big5 (Traditional Chinese) | [`encodings/big5.tbl`](encodings/big5.tbl) | Big5 encoding for Traditional Chinese |
|
||||
| Cyrillic ISO | [`encodings/cyrillic_iso.tbl`](encodings/cyrillic_iso.tbl) | Cyrillic ISO encoding |
|
||||
| Cyrillic Windows | [`encodings/cyrillic_windows.tbl`](encodings/cyrillic_windows.tbl) | Cyrillic Windows encoding |
|
||||
| Cyrillic KOI8-R | [`encodings/cyrillic_koi8_r.tbl`](encodings/cyrillic_koi8_r.tbl) | Cyrillic KOI8-R encoding (Russian Characters) |
|
||||
@@ -195,14 +206,17 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
| Turkish Windows | [`encodings/turkish_windows.tbl`](encodings/turkish_windows.tbl) | Turkish Windows encoding |
|
||||
| UTF-8 | [`encodings/utf8.tbl`](encodings/utf8.tbl) | UTF-8 encoding |
|
||||
| Vietnamese | [`encodings/vietnamese.tbl`](encodings/vietnamese.tbl) | Vietnamese character encoding |
|
||||
> import custom encoding from File -> Import... -> Custome Encoding File
|
||||
|
||||
### Data Processor Nodes
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| Caesar Cipher | [`nodes/caesar.hexnode`](nodes/caesar.hexnode) | Simple adjustable per-byte Caecar Cipher (ROT) |
|
||||
| XOR Cipher | [`nodes/xor.hexnode`](nodes/xor.hexnode) | XORs a input with a repeating XOR pad |
|
||||
|
||||
### Themes
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| Visual Studio Dark | [`themes/vs_dark.json`](themes/vs_dark.json) | Theme similar to Visual Studio's Dark theme |
|
||||
|
||||
18594
encodings/big5.tbl
Normal file
18594
encodings/big5.tbl
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
import hex.impl.imhex_check;
|
||||
|
||||
/*!
|
||||
Core intrinsic functions to interact with the ImHex Hex Editor
|
||||
*/
|
||||
|
||||
namespace hex::core {
|
||||
namespace auto hex::core {
|
||||
|
||||
/**
|
||||
A type representing a selection in the hex editor
|
||||
@@ -37,4 +37,14 @@ namespace hex::core {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Add a file to the Virtual Filesystem
|
||||
@param path The name of the file
|
||||
@param pattern The pattern associated with the file
|
||||
*/
|
||||
fn add_virtual_file(str path, auto pattern)
|
||||
{
|
||||
builtin::hex::core::add_virtual_file(path, pattern);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
import hex.impl.imhex_check;
|
||||
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Library to allow decoding of more complex values
|
||||
*/
|
||||
|
||||
namespace hex::dec {
|
||||
namespace auto hex::dec {
|
||||
|
||||
/**
|
||||
Demangles a mangled name into a human readable name
|
||||
@@ -17,4 +19,46 @@ namespace hex::dec {
|
||||
return builtin::hex::dec::demangle(mangled_name);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Decompresses the bytes of a pattern into a section using the zlib algorithm
|
||||
@param pattern The pattern whose bytes should be decompressed
|
||||
@param section The section to decompress the data into
|
||||
@param window_size The window size passed to zlib
|
||||
@return true if successful, false otherwise
|
||||
*/
|
||||
fn zlib_decompress(ref auto pattern, std::mem::Section section, u64 window_size = 0) {
|
||||
return builtin::hex::dec::zlib_decompress(pattern, section, window_size);
|
||||
};
|
||||
|
||||
/**
|
||||
Decompresses the bytes of a pattern into a section using the bzip algorithm
|
||||
@param pattern The pattern whose bytes should be decompressed
|
||||
@param section The section to decompress the data into
|
||||
@return true if successful, false otherwise
|
||||
*/
|
||||
fn bzip_decompress(ref auto pattern, std::mem::Section section) {
|
||||
return builtin::hex::dec::bzip_decompress(pattern, section);
|
||||
};
|
||||
|
||||
/**
|
||||
Decompresses the bytes of a pattern into a section using the LZMA algorithm
|
||||
@param pattern The pattern whose bytes should be decompressed
|
||||
@param section The section to decompress the data into
|
||||
@return true if successful, false otherwise
|
||||
*/
|
||||
fn lzma_decompress(ref auto pattern, std::mem::Section section) {
|
||||
return builtin::hex::dec::lzma_decompress(pattern, section);
|
||||
};
|
||||
|
||||
/**
|
||||
Decompresses the bytes of a pattern into a section using the zstd algorithm
|
||||
@param pattern The pattern whose bytes should be decompressed
|
||||
@param section The section to decompress the data into
|
||||
@return true if successful, false otherwise
|
||||
*/
|
||||
fn zstd_decompress(ref auto pattern, std::mem::Section section) {
|
||||
return builtin::hex::dec::zstd_decompress(pattern, section);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
import hex.impl.imhex_check;
|
||||
|
||||
/*!
|
||||
Library to do HTTP requests
|
||||
*/
|
||||
|
||||
namespace hex::http {
|
||||
namespace auto hex::http {
|
||||
|
||||
/**
|
||||
Performs a HTTP GET request to the given URL and returns the response body
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
import hex.impl.imhex_check;
|
||||
|
||||
/*!
|
||||
Library to interact with the currently loaded provider.
|
||||
*/
|
||||
|
||||
namespace hex::prv {
|
||||
namespace auto hex::prv {
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
#include <hex/dec.pat>
|
||||
import hex.impl.imhex_check;
|
||||
import hex.dec;
|
||||
|
||||
/*!
|
||||
Types to automatically decode mangled names
|
||||
*/
|
||||
|
||||
namespace hex::type {
|
||||
|
||||
namespace auto hex::type {
|
||||
|
||||
/**
|
||||
A mangled name string that gets demangled when displayed
|
||||
*/
|
||||
struct MangledName {
|
||||
char value[];
|
||||
} [[sealed, format("hex::type::impl::format_mangled_name")]];
|
||||
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_mangled_name(ref MangledName name) {
|
||||
return hex::dec::demangle(name.value);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/sys.pat>
|
||||
import std.sys;
|
||||
import std.core;
|
||||
|
||||
/*!
|
||||
The array library contains a helper type to make it easier to create multi-dimensional arrays
|
||||
and pass arrays to functions as parameters.
|
||||
*/
|
||||
|
||||
namespace std {
|
||||
namespace auto std {
|
||||
|
||||
/**
|
||||
Simple one dimensional array wrapper
|
||||
@@ -30,6 +31,16 @@ namespace std {
|
||||
std::assert($ - startAddress == NumBytes, "Not enough bytes available to fit a whole number of types");
|
||||
} [[format("std::impl::format_array")]];
|
||||
|
||||
|
||||
/**
|
||||
An interface type for getting the index of the currently processed element in an array. This is a nice wrapper around `std::core::array_index()`
|
||||
|
||||
To use it, inherit from it and use the `this.index` field to get the index of the current element
|
||||
*/
|
||||
struct IIndexed {
|
||||
const u64 index = std::core::array_index();
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_array(ref auto array) {
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/limits.pat>
|
||||
import std.limits;
|
||||
|
||||
/*!
|
||||
This library contains various helper functions for common bit operations.
|
||||
This library contains various helper functions for common bit operations.
|
||||
*/
|
||||
|
||||
namespace std::bit {
|
||||
namespace auto std::bit {
|
||||
|
||||
/**
|
||||
Calculates the number of 1 bits in a given number
|
||||
@param x The number
|
||||
@return The number of bits set to 1 in `x`
|
||||
*/
|
||||
fn popcount(u128 x) {
|
||||
x = (x & (std::limits::u128_max() / 3)) + ((x >> 1) & (std::limits::u128_max() / 3));
|
||||
x = (x & (std::limits::u128_max() / 5)) + ((x >> 2) & (std::limits::u128_max() / 5));
|
||||
x = (x & (std::limits::u128_max() / 17)) + ((x >> 4) & (std::limits::u128_max() / 17));
|
||||
|
||||
return x % 0xFF;
|
||||
};
|
||||
/**
|
||||
Calculates the number of 1 bits in a given number
|
||||
@param x The number
|
||||
@return The number of bits set to 1 in `x`
|
||||
*/
|
||||
fn popcount(u128 x) {
|
||||
x = (x & (std::limits::u128_max() / 3)) + ((x >> 1) & (std::limits::u128_max() / 3));
|
||||
x = (x & (std::limits::u128_max() / 5)) + ((x >> 2) & (std::limits::u128_max() / 5));
|
||||
x = (x & (std::limits::u128_max() / 17)) + ((x >> 4) & (std::limits::u128_max() / 17));
|
||||
|
||||
return x % 0xFF;
|
||||
};
|
||||
|
||||
/**
|
||||
Checks if only a single bit is set to 1 in a given number
|
||||
@param x The number
|
||||
@return True if there's a single bit set to 1 in `x`, false otherwise
|
||||
*/
|
||||
fn has_single_bit(u128 x) {
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
Rounds the given number up to the next bigger power of two
|
||||
@param x The number
|
||||
@return Next bigger power of two that can fit `x`
|
||||
*/
|
||||
fn bit_ceil(u128 x) {
|
||||
if (x == 0) return 0;
|
||||
|
||||
u8 i;
|
||||
while ((1 << i) < x)
|
||||
i = i + 1;
|
||||
|
||||
return 1 << i;
|
||||
};
|
||||
/**
|
||||
Checks if only a single bit is set to 1 in a given number
|
||||
@param x The number
|
||||
@return True if there's a single bit set to 1 in `x`, false otherwise
|
||||
*/
|
||||
fn has_single_bit(u128 x) {
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
Rounds the given number up to the next bigger power of two
|
||||
@param x The number
|
||||
@return Next bigger power of two that can fit `x`
|
||||
*/
|
||||
fn bit_ceil(u128 x) {
|
||||
if (x == 0) return 0;
|
||||
|
||||
u8 i;
|
||||
while ((1 << i) < x)
|
||||
i = i + 1;
|
||||
|
||||
return 1 << i;
|
||||
};
|
||||
|
||||
/**
|
||||
Rounds the given number down to the next bigger power of two
|
||||
@param x The number
|
||||
@return Next smaller power of two
|
||||
*/
|
||||
fn bit_floor(u128 x) {
|
||||
if (x == 0) return 0;
|
||||
|
||||
u8 i;
|
||||
while ((x >> i) > 0)
|
||||
i = i + 1;
|
||||
|
||||
return 1 << (i - 1);
|
||||
};
|
||||
/**
|
||||
Rounds the given number down to the next bigger power of two
|
||||
@param x The number
|
||||
@return Next smaller power of two
|
||||
*/
|
||||
fn bit_floor(u128 x) {
|
||||
if (x == 0) return 0;
|
||||
|
||||
u8 i;
|
||||
while ((x >> i) > 0)
|
||||
i = i + 1;
|
||||
|
||||
return 1 << (i - 1);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
The core library contains intrinsics and "compiler magic" functions that
|
||||
get extra help from the runtime to fulfill their purpose.
|
||||
*/
|
||||
|
||||
namespace std::core {
|
||||
namespace auto std::core {
|
||||
|
||||
/**
|
||||
The layout order of each field after byte-endianness has been handled.
|
||||
@@ -38,12 +38,20 @@ namespace std::core {
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the first parameter of the attribute of a pattern if it has one
|
||||
Returns the nth parameter of the attribute of a pattern if it has one
|
||||
@param pattern The pattern to check
|
||||
@param attribute The attribute's name to query
|
||||
@param [index] The parameter index of the attribute to return. Defaults to 0
|
||||
*/
|
||||
fn get_attribute_argument(ref auto pattern, str attribute, u32 index = 0) {
|
||||
return builtin::std::core::get_attribute_argument(pattern, attribute, index);
|
||||
};
|
||||
|
||||
/**
|
||||
@warning Removed in 1.27.0
|
||||
*/
|
||||
fn get_attribute_value(ref auto pattern, str attribute) {
|
||||
return builtin::std::core::get_attribute_value(pattern, attribute);
|
||||
builtin::std::error("`std::core::get_attribute_value(pattern, attribute)` has been removed.\nUse `std::core::get_attribute_argument(pattern, attribute, [index])` instead.");
|
||||
};
|
||||
|
||||
|
||||
@@ -146,4 +154,23 @@ namespace std::core {
|
||||
fn set_display_name(ref auto pattern, str name) {
|
||||
builtin::std::core::set_display_name(pattern, name);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Changes the comment attached to a pattern
|
||||
@param pattern The pattern to modify
|
||||
@param name The new comment of the pattern
|
||||
*/
|
||||
fn set_pattern_comment(ref auto pattern, str comment) {
|
||||
builtin::std::core::set_pattern_comment(pattern, name);
|
||||
};
|
||||
|
||||
/**
|
||||
Executes the function with the given name, passing in all given arguments
|
||||
@param function_name The namespace-prefixed name of the function
|
||||
@param args Arguments to pass to the function
|
||||
*/
|
||||
fn execute_function(str function_name, auto ... args) {
|
||||
builtin::std::core::execute_function(function_name, args);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
of ASCII characters.
|
||||
*/
|
||||
|
||||
namespace std::ctype {
|
||||
namespace auto std::ctype {
|
||||
|
||||
/**
|
||||
Checks if the given character `c` is a digit between '0' and '9'
|
||||
|
||||
@@ -1,112 +1,120 @@
|
||||
#pragma once
|
||||
|
||||
/*!
|
||||
The File library allows reading and writing from/to external files using
|
||||
a C-like File IO API.
|
||||
The File library allows reading and writing from/to external files using
|
||||
a C-like File IO API.
|
||||
|
||||
**These functions are considered dangerous and require the user to manually permit them**
|
||||
**These functions are considered dangerous and require the user to manually permit them**
|
||||
*/
|
||||
|
||||
namespace std::file {
|
||||
namespace auto std::file {
|
||||
|
||||
/**
|
||||
/**
|
||||
A handle representing a file that has been opened
|
||||
*/
|
||||
using Handle = s32;
|
||||
|
||||
/**
|
||||
using Handle = s32;
|
||||
|
||||
/**
|
||||
The mode to open a file in.
|
||||
Read opens the file in read-only mode
|
||||
Write opens the file in read and write mode
|
||||
Create creates a new file if it doesn't exist and overwrites an existing file
|
||||
Read opens the file in read-only mode
|
||||
Write opens the file in read and write mode
|
||||
Create creates a new file if it doesn't exist and overwrites an existing file
|
||||
*/
|
||||
enum Mode : u8 {
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Create = 3
|
||||
};
|
||||
enum Mode : u8 {
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Create = 3
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
Opens a file
|
||||
@param path The path to the file to open
|
||||
@param mode File open mode
|
||||
@return Handle to the newly opened file
|
||||
@param path The path to the file to open
|
||||
@param mode File open mode
|
||||
@return Handle to the newly opened file
|
||||
*/
|
||||
fn open(str path, Mode mode) {
|
||||
return builtin::std::file::open(path, u32(mode));
|
||||
};
|
||||
fn open(str path, Mode mode) {
|
||||
return builtin::std::file::open(path, u32(mode));
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
Closes a file handle that has been opened previously
|
||||
@param handle The handle to close
|
||||
@param handle The handle to close
|
||||
*/
|
||||
fn close(Handle handle) {
|
||||
builtin::std::file::close(handle);
|
||||
};
|
||||
fn close(Handle handle) {
|
||||
builtin::std::file::close(handle);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
Reads the content of a file into a string
|
||||
@param handle The file handle to read from
|
||||
@param size Number of bytes to read
|
||||
@return String containing the read data
|
||||
@param handle The file handle to read from
|
||||
@param size Number of bytes to read
|
||||
@return String containing the read data
|
||||
*/
|
||||
fn read(Handle handle, u64 size) {
|
||||
return builtin::std::file::read(handle, size);
|
||||
};
|
||||
fn read(Handle handle, u64 size) {
|
||||
return builtin::std::file::read(handle, size);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
Writes the content of a string into a file
|
||||
@param handle The file handle to write to
|
||||
@param data String or Pattern to write to the file
|
||||
@param handle The file handle to write to
|
||||
@param data String or Pattern to write to the file
|
||||
*/
|
||||
fn write(Handle handle, auto data) {
|
||||
builtin::std::file::write(handle, data);
|
||||
};
|
||||
fn write(Handle handle, auto data) {
|
||||
builtin::std::file::write(handle, data);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
Sets the current cursor position in the given file handle
|
||||
@param handle The file handle to set the cursor position in
|
||||
@param offset The offset to move the cursor to
|
||||
@param handle The file handle to set the cursor position in
|
||||
@param offset The offset to move the cursor to
|
||||
*/
|
||||
fn seek(Handle handle, u64 offset) {
|
||||
builtin::std::file::seek(handle, offset);
|
||||
};
|
||||
fn seek(Handle handle, u64 offset) {
|
||||
builtin::std::file::seek(handle, offset);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Queries the size of a file
|
||||
@param handle The handle of the file to get the size of
|
||||
@return The file's size
|
||||
*/
|
||||
fn size(Handle handle) {
|
||||
return builtin::std::file::size(handle);
|
||||
};
|
||||
/**
|
||||
Queries the size of a file
|
||||
@param handle The handle of the file to get the size of
|
||||
@return The file's size
|
||||
*/
|
||||
fn size(Handle handle) {
|
||||
return builtin::std::file::size(handle);
|
||||
};
|
||||
|
||||
/**
|
||||
Resizes a file
|
||||
@param handle The handle of the file to resize
|
||||
*/
|
||||
fn resize(Handle handle, u64 size) {
|
||||
builtin::std::file::resize(handle, size);
|
||||
};
|
||||
/**
|
||||
Resizes a file
|
||||
@param handle The handle of the file to resize
|
||||
*/
|
||||
fn resize(Handle handle, u64 size) {
|
||||
builtin::std::file::resize(handle, size);
|
||||
};
|
||||
|
||||
/**
|
||||
Flushes changes made to a file to disk
|
||||
@param handle The handle of the file to flush
|
||||
*/
|
||||
fn flush(Handle handle) {
|
||||
builtin::std::file::remove(handle);
|
||||
};
|
||||
/**
|
||||
Flushes changes made to a file to disk
|
||||
@param handle The handle of the file to flush
|
||||
*/
|
||||
fn flush(Handle handle) {
|
||||
builtin::std::file::flush(handle);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Deletes a file from disk. This will also automatically close this file
|
||||
@param handle The handle of the file to delete
|
||||
*/
|
||||
fn remove(Handle handle) {
|
||||
builtin::std::file::remove(handle);
|
||||
};
|
||||
/**
|
||||
Deletes a file from disk. This will also automatically close this file
|
||||
@param handle The handle of the file to delete
|
||||
*/
|
||||
fn remove(Handle handle) {
|
||||
builtin::std::file::remove(handle);
|
||||
};
|
||||
|
||||
/**
|
||||
Create all directories for the provided path
|
||||
@param path The path for which all directories should be created
|
||||
*/
|
||||
fn create_directories(str path) {
|
||||
builtin::std::file::create_directories(path);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
/*!
|
||||
Library for doing arithmetic with fixed point numbers and converting them from/to floating point numbers.
|
||||
Library for doing arithmetic with fixed point numbers and converting them from/to floating point numbers.
|
||||
*/
|
||||
|
||||
namespace std::fxpt {
|
||||
namespace auto std::fxpt {
|
||||
|
||||
/**
|
||||
A fixed point value
|
||||
*/
|
||||
using fixed = s128;
|
||||
/**
|
||||
A fixed point value
|
||||
*/
|
||||
using fixed = s128;
|
||||
|
||||
/**
|
||||
Converts a fixed point value into a floating point value
|
||||
@param fxt The fixed point value to convert
|
||||
@param precision The bits of precision the new value should have
|
||||
@return The floating point representation of fxt
|
||||
*/
|
||||
fn to_float(fixed fxt, u32 precision) {
|
||||
return double(fxt) / double((1 << precision));
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a floating point value into a fixed point value
|
||||
@param flt The floating point value to convert
|
||||
@param precision The bits of precision the new value should have
|
||||
@return The fixed point representation of flt
|
||||
*/
|
||||
fn to_fixed(double flt, u32 precision) {
|
||||
return s128((flt * (1 << precision)));
|
||||
};
|
||||
/**
|
||||
Converts a fixed point value into a floating point value
|
||||
@param fxt The fixed point value to convert
|
||||
@param precision The bits of precision the new value should have
|
||||
@return The floating point representation of fxt
|
||||
*/
|
||||
fn to_float(fixed fxt, u32 precision) {
|
||||
return double(fxt) / double((1 << precision));
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a floating point value into a fixed point value
|
||||
@param flt The floating point value to convert
|
||||
@param precision The bits of precision the new value should have
|
||||
@return The fixed point representation of flt
|
||||
*/
|
||||
fn to_fixed(double flt, u32 precision) {
|
||||
return s128((flt * (1 << precision)));
|
||||
};
|
||||
|
||||
/**
|
||||
Changes the number of bits used to represent the decimal part of the given fixed point number
|
||||
@param value The fixed point value to convert
|
||||
@param start_precision The current number of bits used
|
||||
@param end_precision The new number of bits used
|
||||
@return `value` as a new fixed point number with `end_precision` bits of precision
|
||||
*/
|
||||
fn change_precision(fixed value, u32 start_precision, u32 end_precision) {
|
||||
return std::fxpt::to_fixed(std::fxpt::to_float(value, start_precision), end_precision);
|
||||
};
|
||||
|
||||
/**
|
||||
Adds two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the addition of `a` and `b`
|
||||
*/
|
||||
fn add(fixed a, fixed b, u32 precision) {
|
||||
return a + b;
|
||||
};
|
||||
|
||||
/**
|
||||
Subtracts two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the subtraction of `a` and `b`
|
||||
*/
|
||||
fn subtract(fixed a, fixed b, u32 precision) {
|
||||
return a - b;
|
||||
};
|
||||
|
||||
/**
|
||||
Multiplies two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the multiplication of `a` and `b`
|
||||
*/
|
||||
fn multiply(fixed a, fixed b, u32 precision) {
|
||||
return (a * b) / (1 << precision);
|
||||
};
|
||||
|
||||
/**
|
||||
Divides two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the division of `a` and `b`
|
||||
*/
|
||||
fn divide(fixed a, fixed b, u32 precision) {
|
||||
return (a << precision) / b;
|
||||
};
|
||||
/**
|
||||
Changes the number of bits used to represent the decimal part of the given fixed point number
|
||||
@param value The fixed point value to convert
|
||||
@param start_precision The current number of bits used
|
||||
@param end_precision The new number of bits used
|
||||
@return `value` as a new fixed point number with `end_precision` bits of precision
|
||||
*/
|
||||
fn change_precision(fixed value, u32 start_precision, u32 end_precision) {
|
||||
return std::fxpt::to_fixed(std::fxpt::to_float(value, start_precision), end_precision);
|
||||
};
|
||||
|
||||
/**
|
||||
Adds two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the addition of `a` and `b`
|
||||
*/
|
||||
fn add(fixed a, fixed b, u32 precision) {
|
||||
return a + b;
|
||||
};
|
||||
|
||||
/**
|
||||
Subtracts two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the subtraction of `a` and `b`
|
||||
*/
|
||||
fn subtract(fixed a, fixed b, u32 precision) {
|
||||
return a - b;
|
||||
};
|
||||
|
||||
/**
|
||||
Multiplies two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the multiplication of `a` and `b`
|
||||
*/
|
||||
fn multiply(fixed a, fixed b, u32 precision) {
|
||||
return (a * b) / (1 << precision);
|
||||
};
|
||||
|
||||
/**
|
||||
Divides two fixed point numbers with a given precision together
|
||||
@param a First fixed point number
|
||||
@param b Second fixed point number
|
||||
@param precision The precision of `a` and `b`
|
||||
@return Result of the division of `a` and `b`
|
||||
*/
|
||||
fn divide(fixed a, fixed b, u32 precision) {
|
||||
return (a << precision) / b;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
The hash library contains various data hash functions
|
||||
*/
|
||||
|
||||
namespace std::hash {
|
||||
namespace auto std::hash {
|
||||
|
||||
/**
|
||||
Calculates the CRC32 hash of the bytes inside of a given pattern
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
The IO library allows formatting strings and outputting text to the console
|
||||
*/
|
||||
|
||||
namespace std {
|
||||
namespace auto std {
|
||||
|
||||
/**
|
||||
Formats the given arguments using the format string and prints the result to the console
|
||||
|
||||
@@ -1,169 +1,169 @@
|
||||
#pragma once
|
||||
|
||||
/*!
|
||||
Library to calculate the minimum and maximum values that fit into a given data type
|
||||
Library to calculate the minimum and maximum values that fit into a given data type
|
||||
*/
|
||||
|
||||
namespace std::limits {
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u8`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u8_min() {
|
||||
return u8(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u8`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u8_max() {
|
||||
return u8(-1);
|
||||
};
|
||||
namespace auto std::limits {
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u8`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u8_min() {
|
||||
return u8(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u8`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u8_max() {
|
||||
return u8(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s8`.
|
||||
@return Minimum value
|
||||
*/
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s8`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s8_min() {
|
||||
return -s8((std::limits::u8_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s8`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s8_max() {
|
||||
return s8((std::limits::u8_max() / 2));
|
||||
};
|
||||
return -s8((std::limits::u8_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s8`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s8_max() {
|
||||
return s8((std::limits::u8_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u16`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u16_min() {
|
||||
return u16(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u16`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u16_max() {
|
||||
return u16(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s16`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s16_min() {
|
||||
return -s16((std::limits::u16_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s16`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s16_max() {
|
||||
return s16((std::limits::u16_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u32`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u32_min() {
|
||||
return u32(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u32`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u32_max() {
|
||||
return u32(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s32`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s32_min() {
|
||||
return -s32((std::limits::u32_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s32`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s32_max() {
|
||||
return s32((std::limits::u32_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u64`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u64_min() {
|
||||
return u64(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u64`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u64_max() {
|
||||
return u64(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s64`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s64_min() {
|
||||
return -s64((std::limits::u64_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s64`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s64_max() {
|
||||
return s64((std::limits::u64_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u128`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u128_min() {
|
||||
return u128(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u128`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u128_max() {
|
||||
return u128(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s128`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s128_min() {
|
||||
return -s128((std::limits::u128_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s128`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s128_max() {
|
||||
return s128((std::limits::u128_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u16`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u16_min() {
|
||||
return u16(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u16`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u16_max() {
|
||||
return u16(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s16`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s16_min() {
|
||||
return -s16((std::limits::u16_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s16`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s16_max() {
|
||||
return s16((std::limits::u16_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u32`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u32_min() {
|
||||
return u32(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u32`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u32_max() {
|
||||
return u32(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s32`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s32_min() {
|
||||
return -s32((std::limits::u32_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s32`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s32_max() {
|
||||
return s32((std::limits::u32_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u64`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u64_min() {
|
||||
return u64(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u64`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u64_max() {
|
||||
return u64(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s64`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s64_min() {
|
||||
return -s64((std::limits::u64_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s64`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s64_max() {
|
||||
return s64((std::limits::u64_max() / 2));
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `u128`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn u128_min() {
|
||||
return u128(0);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `u128`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn u128_max() {
|
||||
return u128(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the minimum value that can be stored in a `s128`.
|
||||
@return Minimum value
|
||||
*/
|
||||
fn s128_min() {
|
||||
return -s128((std::limits::u128_max() / 2)) - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the maximum value that can be stored in a `s128`.
|
||||
@return Maximum value
|
||||
*/
|
||||
fn s128_max() {
|
||||
return s128((std::limits::u128_max() / 2));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,340 +1,340 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Library containing more advanced mathematical operations.
|
||||
Library containing more advanced mathematical operations.
|
||||
*/
|
||||
|
||||
namespace std::math {
|
||||
|
||||
/**
|
||||
Compares the values `a` and `b` with each other and returns the smaller of the two
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@return `a` if `a` is smaller than `b`, otherwise `b`
|
||||
*/
|
||||
fn min(auto a, auto b) {
|
||||
if (a < b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
};
|
||||
|
||||
/**
|
||||
Compares the values `a` and `b` with each other and returns the bigger of the two
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@return `a` if `a` is bigger than `b`, otherwise `b`
|
||||
*/
|
||||
fn max(auto a, auto b) {
|
||||
if (a > b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
};
|
||||
|
||||
/**
|
||||
Clamps the value of `x` between `min` and `max`.
|
||||
@param x Value
|
||||
@param min Minimum value
|
||||
@param max Maximum value
|
||||
@return `min` if `x` is smaller than `min`, `max` if `x` is bigger than `max`, `x` otherwise
|
||||
*/
|
||||
fn clamp(auto x, auto min, auto max) {
|
||||
if (x < min)
|
||||
return min;
|
||||
else if (x > max)
|
||||
return max;
|
||||
else
|
||||
return x;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the absolute value of `x`.
|
||||
@param x Value
|
||||
@return `x` if `x` is positive, `-x` otherwise
|
||||
*/
|
||||
fn abs(auto x) {
|
||||
if (x < 0)
|
||||
return -x;
|
||||
else
|
||||
return x;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the sign of `x`.
|
||||
@param x Value
|
||||
@return `1` if `x` is positive, `-1` if `x` is negative, `0` if `x` is zero
|
||||
*/
|
||||
fn sign(auto x) {
|
||||
if (x > 0)
|
||||
return 1;
|
||||
else if (x < 0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
Copies the sign of `y` to `x`.
|
||||
@param x Value
|
||||
@param y Value
|
||||
@return `x` if `y` is positive, `-x` if `y` is negative
|
||||
*/
|
||||
fn copy_sign(auto x, auto y) {
|
||||
if (y >= 0)
|
||||
return std::math::abs(x);
|
||||
else
|
||||
return -std::math::abs(x);
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the factorial of `x`.
|
||||
@param x Value
|
||||
@return Factorial of `x`
|
||||
*/
|
||||
fn factorial(u128 x) {
|
||||
u128 result;
|
||||
|
||||
result = x;
|
||||
while (x > 1) {
|
||||
x = x - 1;
|
||||
result = result * x;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the binomial coefficient of `n` and `k`.
|
||||
@param n Value
|
||||
@param k Value
|
||||
@return Binomial coefficient of `n` and `k`
|
||||
*/
|
||||
fn comb(u128 n, u128 k) {
|
||||
if (k > n)
|
||||
return 0;
|
||||
else
|
||||
return std::math::factorial(n) / (std::math::factorial(k) * std::math::factorial(n - k));
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the permutation of `n` and `k`.
|
||||
@param n Value
|
||||
@param k Value
|
||||
@return Permutation of `n` and `k`
|
||||
*/
|
||||
fn perm(u128 n, u128 k) {
|
||||
if (k > n)
|
||||
return 0;
|
||||
else
|
||||
return std::math::factorial(n) / std::math::factorial(n - k);
|
||||
};
|
||||
|
||||
/**
|
||||
Floors the value of `value`.
|
||||
@param value Value
|
||||
@return `value` floored
|
||||
*/
|
||||
fn floor(auto value) { return builtin::std::math::floor(value); };
|
||||
|
||||
/**
|
||||
Ceils the value of `value`.
|
||||
@param value Value
|
||||
@return `value` ceiled
|
||||
*/
|
||||
fn ceil(auto value) { return builtin::std::math::ceil(value); };
|
||||
|
||||
/**
|
||||
Rounds the value of `value`.
|
||||
@param value Value
|
||||
@return `value` rounded
|
||||
*/
|
||||
fn round(auto value) { return builtin::std::math::round(value); };
|
||||
|
||||
/**
|
||||
Truncates the value of `value`.
|
||||
@param value Value
|
||||
@return `value` truncated
|
||||
*/
|
||||
fn trunc(auto value) { return builtin::std::math::trunc(value); };
|
||||
|
||||
|
||||
/**
|
||||
Calculates the logarithm of `value` with base 10.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base 10
|
||||
*/
|
||||
fn log10(auto value) { return builtin::std::math::log10(value); };
|
||||
|
||||
/**
|
||||
Calculates the logarithm of `value` with base 2.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base 2
|
||||
*/
|
||||
fn log2(auto value) { return builtin::std::math::log2(value); };
|
||||
|
||||
/**
|
||||
Calculates the natural logarithm of `value`.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base `e`
|
||||
*/
|
||||
fn ln(auto value) { return builtin::std::math::ln(value); };
|
||||
|
||||
/**
|
||||
Calculates the floating point modulus of `value`.
|
||||
@param value Value
|
||||
@return Floating point modulus of `value`
|
||||
*/
|
||||
fn fmod(auto value) { return builtin::std::math::fmod(value); };
|
||||
|
||||
/**
|
||||
Calculates the value of `base` raised to the power of `exp`.
|
||||
@param base Base
|
||||
@param exp Exponent
|
||||
@return `base` raised to the power of `exp`
|
||||
*/
|
||||
fn pow(auto base, auto exp) { return builtin::std::math::pow(base, exp); };
|
||||
namespace auto std::math {
|
||||
|
||||
/**
|
||||
Calculates the value of the natural number `e` raised to the power of `value`.
|
||||
@param value Exponent
|
||||
@return `e` raised to the power of `value`
|
||||
*/
|
||||
Compares the values `a` and `b` with each other and returns the smaller of the two
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@return `a` if `a` is smaller than `b`, otherwise `b`
|
||||
*/
|
||||
fn min(auto a, auto b) {
|
||||
if (a < b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
};
|
||||
|
||||
/**
|
||||
Compares the values `a` and `b` with each other and returns the bigger of the two
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@return `a` if `a` is bigger than `b`, otherwise `b`
|
||||
*/
|
||||
fn max(auto a, auto b) {
|
||||
if (a > b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
};
|
||||
|
||||
/**
|
||||
Clamps the value of `x` between `min` and `max`.
|
||||
@param x Value
|
||||
@param min Minimum value
|
||||
@param max Maximum value
|
||||
@return `min` if `x` is smaller than `min`, `max` if `x` is bigger than `max`, `x` otherwise
|
||||
*/
|
||||
fn clamp(auto x, auto min, auto max) {
|
||||
if (x < min)
|
||||
return min;
|
||||
else if (x > max)
|
||||
return max;
|
||||
else
|
||||
return x;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the absolute value of `x`.
|
||||
@param x Value
|
||||
@return `x` if `x` is positive, `-x` otherwise
|
||||
*/
|
||||
fn abs(auto x) {
|
||||
if (x < 0)
|
||||
return -x;
|
||||
else
|
||||
return x;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the sign of `x`.
|
||||
@param x Value
|
||||
@return `1` if `x` is positive, `-1` if `x` is negative, `0` if `x` is zero
|
||||
*/
|
||||
fn sign(auto x) {
|
||||
if (x > 0)
|
||||
return 1;
|
||||
else if (x < 0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
Copies the sign of `y` to `x`.
|
||||
@param x Value
|
||||
@param y Value
|
||||
@return `x` if `y` is positive, `-x` if `y` is negative
|
||||
*/
|
||||
fn copy_sign(auto x, auto y) {
|
||||
if (y >= 0)
|
||||
return std::math::abs(x);
|
||||
else
|
||||
return -std::math::abs(x);
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the factorial of `x`.
|
||||
@param x Value
|
||||
@return Factorial of `x`
|
||||
*/
|
||||
fn factorial(u128 x) {
|
||||
u128 result;
|
||||
|
||||
result = x;
|
||||
while (x > 1) {
|
||||
x = x - 1;
|
||||
result = result * x;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the binomial coefficient of `n` and `k`.
|
||||
@param n Value
|
||||
@param k Value
|
||||
@return Binomial coefficient of `n` and `k`
|
||||
*/
|
||||
fn comb(u128 n, u128 k) {
|
||||
if (k > n)
|
||||
return 0;
|
||||
else
|
||||
return std::math::factorial(n) / (std::math::factorial(k) * std::math::factorial(n - k));
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the permutation of `n` and `k`.
|
||||
@param n Value
|
||||
@param k Value
|
||||
@return Permutation of `n` and `k`
|
||||
*/
|
||||
fn perm(u128 n, u128 k) {
|
||||
if (k > n)
|
||||
return 0;
|
||||
else
|
||||
return std::math::factorial(n) / std::math::factorial(n - k);
|
||||
};
|
||||
|
||||
/**
|
||||
Floors the value of `value`.
|
||||
@param value Value
|
||||
@return `value` floored
|
||||
*/
|
||||
fn floor(auto value) { return builtin::std::math::floor(value); };
|
||||
|
||||
/**
|
||||
Ceils the value of `value`.
|
||||
@param value Value
|
||||
@return `value` ceiled
|
||||
*/
|
||||
fn ceil(auto value) { return builtin::std::math::ceil(value); };
|
||||
|
||||
/**
|
||||
Rounds the value of `value`.
|
||||
@param value Value
|
||||
@return `value` rounded
|
||||
*/
|
||||
fn round(auto value) { return builtin::std::math::round(value); };
|
||||
|
||||
/**
|
||||
Truncates the value of `value`.
|
||||
@param value Value
|
||||
@return `value` truncated
|
||||
*/
|
||||
fn trunc(auto value) { return builtin::std::math::trunc(value); };
|
||||
|
||||
|
||||
/**
|
||||
Calculates the logarithm of `value` with base 10.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base 10
|
||||
*/
|
||||
fn log10(auto value) { return builtin::std::math::log10(value); };
|
||||
|
||||
/**
|
||||
Calculates the logarithm of `value` with base 2.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base 2
|
||||
*/
|
||||
fn log2(auto value) { return builtin::std::math::log2(value); };
|
||||
|
||||
/**
|
||||
Calculates the natural logarithm of `value`.
|
||||
@param value Value
|
||||
@return Logarithm of `value` with base `e`
|
||||
*/
|
||||
fn ln(auto value) { return builtin::std::math::ln(value); };
|
||||
|
||||
/**
|
||||
Calculates the floating point modulus of `value`.
|
||||
@param value Value
|
||||
@return Floating point modulus of `value`
|
||||
*/
|
||||
fn fmod(auto value) { return builtin::std::math::fmod(value); };
|
||||
|
||||
/**
|
||||
Calculates the value of `base` raised to the power of `exp`.
|
||||
@param base Base
|
||||
@param exp Exponent
|
||||
@return `base` raised to the power of `exp`
|
||||
*/
|
||||
fn pow(auto base, auto exp) { return builtin::std::math::pow(base, exp); };
|
||||
|
||||
/**
|
||||
Calculates the value of the natural number `e` raised to the power of `value`.
|
||||
@param value Exponent
|
||||
@return `e` raised to the power of `value`
|
||||
*/
|
||||
fn exp(auto value) { return builtin::std::math::exp(value); };
|
||||
|
||||
/**
|
||||
Calculates the square root of `value`.
|
||||
@param value Value
|
||||
@return Square root of `value`
|
||||
*/
|
||||
fn sqrt(auto value) { return builtin::std::math::sqrt(value); };
|
||||
/**
|
||||
Calculates the square root of `value`.
|
||||
@param value Value
|
||||
@return Square root of `value`
|
||||
*/
|
||||
fn sqrt(auto value) { return builtin::std::math::sqrt(value); };
|
||||
|
||||
/**
|
||||
Calculates the cubic root of `value`.
|
||||
@param value Value
|
||||
@return Cubic root of `value`
|
||||
*/
|
||||
fn cbrt(auto value) { return builtin::std::math::cbrt(value); };
|
||||
/**
|
||||
Calculates the cubic root of `value`.
|
||||
@param value Value
|
||||
@return Cubic root of `value`
|
||||
*/
|
||||
fn cbrt(auto value) { return builtin::std::math::cbrt(value); };
|
||||
|
||||
/**
|
||||
Calculates the sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Sine of `value`
|
||||
*/
|
||||
fn sin(auto value) { return builtin::std::math::sin(value); };
|
||||
/**
|
||||
Calculates the sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Sine of `value`
|
||||
*/
|
||||
fn sin(auto value) { return builtin::std::math::sin(value); };
|
||||
|
||||
/**
|
||||
Calculates the cosine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Cosine of `value`
|
||||
*/
|
||||
fn cos(auto value) { return builtin::std::math::cos(value); };
|
||||
/**
|
||||
Calculates the cosine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Cosine of `value`
|
||||
*/
|
||||
fn cos(auto value) { return builtin::std::math::cos(value); };
|
||||
|
||||
/**
|
||||
Calculates the tangent of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Tangent of `value`
|
||||
*/
|
||||
fn tan(auto value) { return builtin::std::math::tan(value); };
|
||||
/**
|
||||
Calculates the tangent of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Tangent of `value`
|
||||
*/
|
||||
fn tan(auto value) { return builtin::std::math::tan(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Arc sine of `value`
|
||||
*/
|
||||
fn asin(auto value) { return builtin::std::math::asin(value); };
|
||||
/**
|
||||
Calculates the arc sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Arc sine of `value`
|
||||
*/
|
||||
fn asin(auto value) { return builtin::std::math::asin(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc cosine of `value`.
|
||||
@param value Value
|
||||
@return Arc cosine of `value` in radians
|
||||
*/
|
||||
fn acos(auto value) { return builtin::std::math::acos(value); };
|
||||
/**
|
||||
Calculates the arc cosine of `value`.
|
||||
@param value Value
|
||||
@return Arc cosine of `value` in radians
|
||||
*/
|
||||
fn acos(auto value) { return builtin::std::math::acos(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc tangent of `value`.
|
||||
@param value Value
|
||||
@return Arc tangent of `value` in radians between `-pi/2` and `pi/2`
|
||||
*/
|
||||
fn atan(auto value) { return builtin::std::math::atan(value); };
|
||||
/**
|
||||
Calculates the arc tangent of `value`.
|
||||
@param value Value
|
||||
@return Arc tangent of `value` in radians between `-pi/2` and `pi/2`
|
||||
*/
|
||||
fn atan(auto value) { return builtin::std::math::atan(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc tangent of `value`.
|
||||
@param y Value representing the proportion of the y-coordinate
|
||||
@param x Value representing the proportion of the x-coordinate.
|
||||
@return Arc tangent of `value` in radians between `-pi` and `pi`
|
||||
*/
|
||||
fn atan2(auto y, auto x) { return builtin::std::math::atan2(y, x); };
|
||||
/**
|
||||
Calculates the arc tangent of `value`.
|
||||
@param y Value representing the proportion of the y-coordinate
|
||||
@param x Value representing the proportion of the x-coordinate.
|
||||
@return Arc tangent of `value` in radians between `-pi` and `pi`
|
||||
*/
|
||||
fn atan2(auto y, auto x) { return builtin::std::math::atan2(y, x); };
|
||||
|
||||
/**
|
||||
Calculates the hyperbolic sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic sine of `value`
|
||||
*/
|
||||
fn sinh(auto value) { return builtin::std::math::sinh(value); };
|
||||
/**
|
||||
Calculates the hyperbolic sine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic sine of `value`
|
||||
*/
|
||||
fn sinh(auto value) { return builtin::std::math::sinh(value); };
|
||||
|
||||
/**
|
||||
Calculates the hyperbolic cosine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic cosine of `value`
|
||||
*/
|
||||
fn cosh(auto value) { return builtin::std::math::cosh(value); };
|
||||
/**
|
||||
Calculates the hyperbolic cosine of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic cosine of `value`
|
||||
*/
|
||||
fn cosh(auto value) { return builtin::std::math::cosh(value); };
|
||||
|
||||
/**
|
||||
Calculates the hyperbolic tangent of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic tangent of `value`
|
||||
*/
|
||||
fn tanh(auto value) { return builtin::std::math::tanh(value); };
|
||||
/**
|
||||
Calculates the hyperbolic tangent of `value`.
|
||||
@param value Angle value in radians
|
||||
@return Hyperbolic tangent of `value`
|
||||
*/
|
||||
fn tanh(auto value) { return builtin::std::math::tanh(value); };
|
||||
|
||||
|
||||
/**
|
||||
Calculates the arc hyperbolic sine of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic sine of `value`
|
||||
*/
|
||||
fn asinh(auto value) { return builtin::std::math::asinh(value); };
|
||||
/**
|
||||
Calculates the arc hyperbolic sine of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic sine of `value`
|
||||
*/
|
||||
fn asinh(auto value) { return builtin::std::math::asinh(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc hyperbolic cosine of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic cosine of `value`
|
||||
*/
|
||||
fn acosh(auto value) { return builtin::std::math::acosh(value); };
|
||||
/**
|
||||
Calculates the arc hyperbolic cosine of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic cosine of `value`
|
||||
*/
|
||||
fn acosh(auto value) { return builtin::std::math::acosh(value); };
|
||||
|
||||
/**
|
||||
Calculates the arc hyperbolic tangent of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic tangent of `value`
|
||||
*/
|
||||
fn atanh(auto value) { return builtin::std::math::atanh(value); };
|
||||
/**
|
||||
Calculates the arc hyperbolic tangent of `value`.
|
||||
@param value Value
|
||||
@return Arc hyperbolic tangent of `value`
|
||||
*/
|
||||
fn atanh(auto value) { return builtin::std::math::atanh(value); };
|
||||
|
||||
|
||||
/**
|
||||
Options to use with the `std::math::accumulate` function.
|
||||
*/
|
||||
enum AccumulateOperation : u8 {
|
||||
Add = 0,
|
||||
Multiply = 1,
|
||||
Modulo = 2,
|
||||
Min = 3,
|
||||
Max = 4
|
||||
};
|
||||
/**
|
||||
Options to use with the `std::math::accumulate` function.
|
||||
*/
|
||||
enum AccumulateOperation : u8 {
|
||||
Add = 0,
|
||||
Multiply = 1,
|
||||
Modulo = 2,
|
||||
Min = 3,
|
||||
Max = 4
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the sum of all values in the specified memory range.
|
||||
@param start Start address
|
||||
@param end End address
|
||||
@param valueSize Size of each value in bytes
|
||||
@param section Section to use
|
||||
@param operation Operation to use
|
||||
@param endian Endianness to use
|
||||
@return Sum of all values in the specified memory range
|
||||
*/
|
||||
fn accumulate(u128 start, u128 end, u128 valueSize, std::mem::Section section = 0, AccumulateOperation operation = AccumulateOperation::Add, std::mem::Endian endian = std::mem::Endian::Native) {
|
||||
return builtin::std::math::accumulate(start, end, valueSize, section, u128(operation), u128(endian));
|
||||
};
|
||||
|
||||
/**
|
||||
Calculates the sum of all values in the specified memory range.
|
||||
@param start Start address
|
||||
@param end End address
|
||||
@param valueSize Size of each value in bytes
|
||||
@param [section] Section to use
|
||||
@param [operation] Operation to use. Defaults to addition
|
||||
@param [endian] Endianness to use. Defaults to native
|
||||
@return Sum of all values in the specified memory range
|
||||
*/
|
||||
fn accumulate(u128 start, u128 end, u128 valueSize, std::mem::Section section = 0, AccumulateOperation operation = AccumulateOperation::Add, std::mem::Endian endian = std::mem::Endian::Native) {
|
||||
return builtin::std::math::accumulate(start, end, valueSize, section, u128(operation), u128(endian));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Library for doing raw memory accesses and other low-level operations.
|
||||
*/
|
||||
|
||||
namespace std::mem {
|
||||
namespace auto std::mem {
|
||||
|
||||
namespace impl {
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace std::mem {
|
||||
Reads a unsigned value from the memory
|
||||
@param address The address to read from
|
||||
@param size The size of the value to read
|
||||
@param endian The endianess of the value to read
|
||||
@param [endian] The endianess of the value to read. Defaults to native
|
||||
@return The value read
|
||||
*/
|
||||
fn read_unsigned(u128 address, u8 size, Endian endian = Endian::Native) {
|
||||
@@ -115,7 +115,7 @@ namespace std::mem {
|
||||
Reads a signed value from the memory
|
||||
@param address The address to read from
|
||||
@param size The size of the value to read
|
||||
@param endian The endianess of the value to read
|
||||
@param [endian] The endianess of the value to read. Defaults to native
|
||||
@return The value read
|
||||
*/
|
||||
fn read_signed(u128 address, u8 size, Endian endian = Endian::Native) {
|
||||
@@ -128,7 +128,7 @@ namespace std::mem {
|
||||
@param size The size of the value to read
|
||||
@return The value read
|
||||
*/
|
||||
fn read_string(u128 address, u8 size) {
|
||||
fn read_string(u128 address, u128 size) {
|
||||
return builtin::std::mem::read_string(address, size);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
The Pointer library contains helper functions to deal with pointer types.
|
||||
The `relative_to` functions are meant to be used with the `[[pointer_base]]` attribute
|
||||
*/
|
||||
|
||||
namespace std::ptr {
|
||||
namespace auto std::ptr {
|
||||
|
||||
/**
|
||||
Use the offset of the current pointer as start address
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/limits.pat>
|
||||
import std.limits;
|
||||
|
||||
/*!
|
||||
Library to generate random numbers. Supports various different distribution types.
|
||||
*/
|
||||
|
||||
namespace std::random {
|
||||
namespace auto std::random {
|
||||
|
||||
/**
|
||||
Represents the type of distribution to use to generate a random number
|
||||
@@ -61,8 +61,8 @@ namespace std::random {
|
||||
> - `Poisson(mean) -> i128`
|
||||
|
||||
@param distribution Distribution to use
|
||||
@param param1 This parameter depends on the type of distribution used.
|
||||
@param param2 This parameter depends on the type of distribution used.
|
||||
@param [param1] This parameter depends on the type of distribution used. Defaults to 0
|
||||
@param [param2] This parameter depends on the type of distribution used. Defaults to 0
|
||||
*/
|
||||
fn generate_using(Distribution distribution, auto param1 = 0, auto param2 = 0) {
|
||||
return builtin::std::random::generate(u32(distribution), param1, param2);
|
||||
@@ -71,8 +71,8 @@ namespace std::random {
|
||||
|
||||
/**
|
||||
Generates a uniformly distributed random number between `min` and `max`
|
||||
@param min Minimum number
|
||||
@param max Maximum number
|
||||
@param [min] Minimum number. Defaults to 0
|
||||
@param [max] Maximum number. Defaults to `u64_max`
|
||||
*/
|
||||
fn generate(u64 min = std::limits::u64_min(), u64 max = std::limits::u64_max()) {
|
||||
return std::random::generate_using(Distribution::Uniform, min, max);
|
||||
|
||||
@@ -1,129 +1,149 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Libray to interact with strings.
|
||||
Libray to interact with strings.
|
||||
*/
|
||||
|
||||
namespace std::string {
|
||||
namespace auto std::string {
|
||||
|
||||
/**
|
||||
Base type for sized strings. Represents a string with its size preceeding it.
|
||||
@tparam SizeType The type of the size field.
|
||||
@tparam DataType The type of the characters.
|
||||
*/
|
||||
struct SizedStringBase<SizeType, DataType> {
|
||||
SizeType size;
|
||||
DataType data[size];
|
||||
} [[sealed, format("std::string::impl::format_sized_string"), transform("std::string::impl::format_sized_string")]];
|
||||
/**
|
||||
Base type for sized strings. Represents a string with its size preceeding it.
|
||||
@tparam SizeType The type of the size field.
|
||||
@tparam DataType The type of the characters.
|
||||
*/
|
||||
struct SizedStringBase<SizeType, DataType> {
|
||||
SizeType size;
|
||||
DataType data[size];
|
||||
} [[sealed, format("std::string::impl::format_string"), transform("std::string::impl::format_string")]];
|
||||
|
||||
/**
|
||||
A ASCII string with a prefixed size.
|
||||
@tparam SizeType The type of the size field.
|
||||
*/
|
||||
using SizedString<SizeType> = SizedStringBase<SizeType, char>;
|
||||
/**
|
||||
A ASCII string with a prefixed size.
|
||||
@tparam SizeType The type of the size field.
|
||||
*/
|
||||
using SizedString<SizeType> = SizedStringBase<SizeType, char>;
|
||||
|
||||
/**
|
||||
A UTF-16 string with a prefixed size.
|
||||
@tparam SizeType The type of the size field.
|
||||
*/
|
||||
using SizedString16<SizeType> = SizedStringBase<SizeType, char16>;
|
||||
/**
|
||||
A UTF-16 string with a prefixed size.
|
||||
@tparam SizeType The type of the size field.
|
||||
*/
|
||||
using SizedString16<SizeType> = SizedStringBase<SizeType, char16>;
|
||||
|
||||
namespace impl {
|
||||
/**
|
||||
Base type for null-terminated strings. Represents a string with its size determined by the first 0x00 byte found.
|
||||
@tparam DataType The type of the characters.
|
||||
*/
|
||||
struct NullStringBase<DataType> {
|
||||
DataType string[while(std::mem::read_unsigned($, sizeof(DataType)) != 0x00)];
|
||||
DataType null_terminator;
|
||||
} [[sealed, format("std::string::impl::format_string"), transform("std::string::impl::format_string")]];
|
||||
|
||||
fn format_sized_string(ref auto string) {
|
||||
return string.data;
|
||||
};
|
||||
/**
|
||||
A null-terminated ASCII string.
|
||||
*/
|
||||
using NullString = NullStringBase<char>;
|
||||
|
||||
}
|
||||
/**
|
||||
A null-terminated UTF-16 string.
|
||||
*/
|
||||
using NullString16 = NullStringBase<char16>;
|
||||
|
||||
/**
|
||||
Gets the length of a string.
|
||||
@param string The string to get the length of.
|
||||
@return The length of the string.
|
||||
*/
|
||||
fn length(str string) {
|
||||
return builtin::std::string::length(string);
|
||||
};
|
||||
namespace impl {
|
||||
|
||||
/**
|
||||
Gets the character at a given index.
|
||||
@param string The string to get the character from.
|
||||
@param index The index of the character to get.
|
||||
@return The character at the given index.
|
||||
*/
|
||||
fn at(str string, u32 index) {
|
||||
return builtin::std::string::at(string, index);
|
||||
};
|
||||
fn format_string(ref auto string) {
|
||||
return string.data;
|
||||
};
|
||||
|
||||
/**
|
||||
Gets a substring of a string.
|
||||
@param string The string to get the substring from.
|
||||
@param pos The position of the first character of the substring.
|
||||
@param count The number of characters to get.
|
||||
@return The substring.
|
||||
*/
|
||||
fn substr(str string, u32 pos, u32 count) {
|
||||
return builtin::std::string::substr(string, pos, count);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
Gets the length of a string.
|
||||
@param string The string to get the length of.
|
||||
@return The length of the string.
|
||||
*/
|
||||
fn length(str string) {
|
||||
return builtin::std::string::length(string);
|
||||
};
|
||||
|
||||
/**
|
||||
Gets the character at a given index.
|
||||
@param string The string to get the character from.
|
||||
@param index The index of the character to get.
|
||||
@return The character at the given index.
|
||||
*/
|
||||
fn at(str string, u32 index) {
|
||||
return builtin::std::string::at(string, index);
|
||||
};
|
||||
|
||||
/**
|
||||
Gets a substring of a string.
|
||||
@param string The string to get the substring from.
|
||||
@param pos The position of the first character of the substring.
|
||||
@param count The number of characters to get.
|
||||
@return The substring.
|
||||
*/
|
||||
fn substr(str string, u32 pos, u32 count) {
|
||||
return builtin::std::string::substr(string, pos, count);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Converts a string to an integer.
|
||||
@param string The string to convert.
|
||||
@param base The base of the number.
|
||||
@return The integer.
|
||||
*/
|
||||
fn parse_int(str string, u8 base) {
|
||||
return builtin::std::string::parse_int(string, base);
|
||||
};
|
||||
/**
|
||||
Converts a string to an integer.
|
||||
@param string The string to convert.
|
||||
@param base The base of the number.
|
||||
@return The integer.
|
||||
*/
|
||||
fn parse_int(str string, u8 base) {
|
||||
return builtin::std::string::parse_int(string, base);
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a string to a float.
|
||||
@param string The string to convert.
|
||||
@return The float.
|
||||
*/
|
||||
fn parse_float(str string) {
|
||||
return builtin::std::string::parse_float(string);
|
||||
};
|
||||
/**
|
||||
Converts a string to a float.
|
||||
@param string The string to convert.
|
||||
@return The float.
|
||||
*/
|
||||
fn parse_float(str string) {
|
||||
return builtin::std::string::parse_float(string);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Converts any type to a string.
|
||||
@param x The value to convert.
|
||||
@return The string.
|
||||
*/
|
||||
/**
|
||||
Converts any type to a string.
|
||||
@param x The value to convert.
|
||||
@return The string.
|
||||
*/
|
||||
fn to_string(auto x) {
|
||||
return std::format("{}", x);
|
||||
};
|
||||
|
||||
/**
|
||||
Checks if a string starts with a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string starts with the substring, false otherwise.
|
||||
*/
|
||||
/**
|
||||
Checks if a string starts with a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string starts with the substring, false otherwise.
|
||||
*/
|
||||
fn starts_with(str string, str part) {
|
||||
return std::string::substr(string, 0, std::string::length(part)) == part;
|
||||
};
|
||||
|
||||
/**
|
||||
Checks if a string ends with a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string ends with the substring, false otherwise.
|
||||
*/
|
||||
/**
|
||||
Checks if a string ends with a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string ends with the substring, false otherwise.
|
||||
*/
|
||||
fn ends_with(str string, str part) {
|
||||
return std::string::substr(string, std::string::length(string) - std::string::length(part), std::string::length(part)) == part;
|
||||
};
|
||||
|
||||
/**
|
||||
Checks if a string contains a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string contains the substring, false otherwise.
|
||||
*/
|
||||
/**
|
||||
Checks if a string contains a given substring.
|
||||
@param string The string to check.
|
||||
@param part The substring to check for.
|
||||
@return True if the string contains the substring, false otherwise.
|
||||
*/
|
||||
fn contains(str string, str part) {
|
||||
s32 string_len = std::string::length(string);
|
||||
s32 part_len = std::string::length(part);
|
||||
@@ -136,12 +156,12 @@ namespace std::string {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
Reverses a string.
|
||||
@param string The string to reverse.
|
||||
@return The reversed string.
|
||||
*/
|
||||
fn reverse(str string) {
|
||||
/**
|
||||
Reverses a string.
|
||||
@param string The string to reverse.
|
||||
@return The reversed string.
|
||||
*/
|
||||
fn reverse(str string) {
|
||||
str result;
|
||||
|
||||
s32 i;
|
||||
@@ -154,82 +174,82 @@ namespace std::string {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a string to upper case.
|
||||
@param string The string to convert.
|
||||
@return The converted string.
|
||||
*/
|
||||
/**
|
||||
Converts a string to upper case.
|
||||
@param string The string to convert.
|
||||
@return The converted string.
|
||||
*/
|
||||
fn to_upper(str string) {
|
||||
str result;
|
||||
|
||||
u32 i;
|
||||
char c;
|
||||
while (i < std::string::length(string)) {
|
||||
c = std::string::at(string, i);
|
||||
|
||||
if (c >= 'a' && c <= 'z')
|
||||
result = result + char(c - 0x20);
|
||||
else
|
||||
result = result + c;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a string to lower case.
|
||||
@param string The string to convert.
|
||||
@return The converted string.
|
||||
*/
|
||||
fn to_lower(str string) {
|
||||
str result;
|
||||
|
||||
u32 i;
|
||||
char c;
|
||||
while (i < std::string::length(string)) {
|
||||
c = std::string::at(string, i);
|
||||
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
result = result + char(c + 0x20);
|
||||
else
|
||||
result = result + c;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
str result;
|
||||
|
||||
u32 i;
|
||||
char c;
|
||||
while (i < std::string::length(string)) {
|
||||
c = std::string::at(string, i);
|
||||
|
||||
if (c >= 'a' && c <= 'z')
|
||||
result = result + char(c - 0x20);
|
||||
else
|
||||
result = result + c;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a string to lower case.
|
||||
@param string The string to convert.
|
||||
@return The converted string.
|
||||
*/
|
||||
fn to_lower(str string) {
|
||||
str result;
|
||||
|
||||
u32 i;
|
||||
char c;
|
||||
while (i < std::string::length(string)) {
|
||||
c = std::string::at(string, i);
|
||||
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
result = result + char(c + 0x20);
|
||||
else
|
||||
result = result + c;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
Replaces all occurrences of a substring with another substring.
|
||||
@param string The string to replace in.
|
||||
@param pattern The substring to replace.
|
||||
@param replace The substring to replace with.
|
||||
@return The string with the replacements.
|
||||
*/
|
||||
fn replace(str string, str pattern, str replace) {
|
||||
s32 string_len = std::string::length(string);
|
||||
s32 pattern_len = std::string::length(pattern);
|
||||
/**
|
||||
Replaces all occurrences of a substring with another substring.
|
||||
@param string The string to replace in.
|
||||
@param pattern The substring to replace.
|
||||
@param replace The substring to replace with.
|
||||
@return The string with the replacements.
|
||||
*/
|
||||
fn replace(str string, str pattern, str replace) {
|
||||
s32 string_len = std::string::length(string);
|
||||
s32 pattern_len = std::string::length(pattern);
|
||||
|
||||
if (pattern_len > string_len || pattern_len * string_len == 0 )
|
||||
return string;
|
||||
if (pattern_len > string_len || pattern_len * string_len == 0 )
|
||||
return string;
|
||||
|
||||
str result;
|
||||
s32 string_index;
|
||||
s32 remaining_len = string_len;
|
||||
while (pattern_len <= remaining_len) {
|
||||
if (std::string::substr(string, string_index, pattern_len) == pattern) {
|
||||
result += replace;
|
||||
string_index += pattern_len;
|
||||
} else {
|
||||
result += std::string::at(string, string_index);
|
||||
string_index += 1;
|
||||
}
|
||||
remaining_len = string_len - string_index;
|
||||
}
|
||||
result += std::string::substr(string, string_index, remaining_len );
|
||||
return result;
|
||||
};
|
||||
str result;
|
||||
s32 string_index;
|
||||
s32 remaining_len = string_len;
|
||||
while (pattern_len <= remaining_len) {
|
||||
if (std::string::substr(string, string_index, pattern_len) == pattern) {
|
||||
result += replace;
|
||||
string_index += pattern_len;
|
||||
} else {
|
||||
result += std::string::at(string, string_index);
|
||||
string_index += 1;
|
||||
}
|
||||
remaining_len = string_len - string_index;
|
||||
}
|
||||
result += std::string::substr(string, string_index, remaining_len );
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Basic helper functions
|
||||
*/
|
||||
|
||||
namespace std {
|
||||
namespace auto std {
|
||||
|
||||
/**
|
||||
Asserts that a given value is true. If it's not, abort evaluation and print the given message to the console
|
||||
@param conditoon The condition that is required to be true
|
||||
@param condition The condition that is required to be true
|
||||
@param message The message to print in case the assertion doesn't hold
|
||||
*/
|
||||
fn assert(bool condition, str message) {
|
||||
@@ -21,7 +21,7 @@ namespace std {
|
||||
|
||||
/**
|
||||
Asserts that a given value is true. If it's not, print the given message to the console as a warning
|
||||
@param conditoon The condition that is required to be true
|
||||
@param condition The condition that is required to be true
|
||||
@param message The message to print in case the assertion doesn't hold
|
||||
*/
|
||||
fn assert_warn(bool condition, str message) {
|
||||
|
||||
@@ -1,200 +1,200 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Library to handle time and date related operations.
|
||||
Library to handle time and date related operations.
|
||||
*/
|
||||
|
||||
namespace std::time {
|
||||
namespace auto std::time {
|
||||
|
||||
/**
|
||||
A structured representation of a time and date.
|
||||
*/
|
||||
struct Time {
|
||||
u8 sec;
|
||||
u8 min;
|
||||
u8 hour;
|
||||
u8 mday;
|
||||
u8 mon;
|
||||
u16 year;
|
||||
u8 wday;
|
||||
u16 yday;
|
||||
bool isdst;
|
||||
} [[sealed]];
|
||||
/**
|
||||
A structured representation of a time and date.
|
||||
*/
|
||||
struct Time {
|
||||
u8 sec;
|
||||
u8 min;
|
||||
u8 hour;
|
||||
u8 mday;
|
||||
u8 mon;
|
||||
u16 year;
|
||||
u8 wday;
|
||||
u16 yday;
|
||||
bool isdst;
|
||||
} [[sealed]];
|
||||
|
||||
/**
|
||||
A helper type to convert between Time and u128.
|
||||
*/
|
||||
union TimeConverter {
|
||||
Time time;
|
||||
u128 value;
|
||||
};
|
||||
/**
|
||||
A helper type to convert between Time and u128.
|
||||
*/
|
||||
union TimeConverter {
|
||||
Time time;
|
||||
u128 value;
|
||||
};
|
||||
|
||||
/**
|
||||
A type to represent a time in seconds since the epoch.
|
||||
*/
|
||||
using EpochTime = u32;
|
||||
/**
|
||||
A type to represent a time in seconds since the epoch.
|
||||
*/
|
||||
using EpochTime = u32;
|
||||
|
||||
/**
|
||||
A type to represent a time zone.
|
||||
*/
|
||||
enum TimeZone : u8 {
|
||||
Local,
|
||||
UTC
|
||||
};
|
||||
/**
|
||||
A type to represent a time zone.
|
||||
*/
|
||||
enum TimeZone : u8 {
|
||||
Local,
|
||||
UTC
|
||||
};
|
||||
|
||||
/**
|
||||
A type to represent a DOS date.
|
||||
*/
|
||||
bitfield DOSDate {
|
||||
day: 5;
|
||||
month: 4;
|
||||
year: 7;
|
||||
} [[sealed]];
|
||||
/**
|
||||
A type to represent a DOS date.
|
||||
*/
|
||||
bitfield DOSDate {
|
||||
day: 5;
|
||||
month: 4;
|
||||
year: 7;
|
||||
} [[sealed]];
|
||||
|
||||
/**
|
||||
A type to represent a DOS time.
|
||||
*/
|
||||
bitfield DOSTime {
|
||||
seconds: 5;
|
||||
minutes: 6;
|
||||
hours: 5;
|
||||
} [[sealed]];
|
||||
/**
|
||||
A type to represent a DOS time.
|
||||
*/
|
||||
bitfield DOSTime {
|
||||
seconds: 5;
|
||||
minutes: 6;
|
||||
hours: 5;
|
||||
} [[sealed]];
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
union DOSDateConverter {
|
||||
DOSDate date;
|
||||
u16 value;
|
||||
};
|
||||
union DOSDateConverter {
|
||||
DOSDate date;
|
||||
u16 value;
|
||||
};
|
||||
|
||||
union DOSTimeConverter {
|
||||
DOSTime time;
|
||||
u16 value;
|
||||
};
|
||||
union DOSTimeConverter {
|
||||
DOSTime time;
|
||||
u16 value;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns the current time in seconds since the epoch.
|
||||
@return The current time in seconds since the epoch.
|
||||
*/
|
||||
fn epoch() {
|
||||
return builtin::std::time::epoch();
|
||||
};
|
||||
/**
|
||||
Returns the current time in seconds since the epoch.
|
||||
@return The current time in seconds since the epoch.
|
||||
*/
|
||||
fn epoch() {
|
||||
return builtin::std::time::epoch();
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a time in seconds since the epoch to a local time.
|
||||
@param epoch_time The time in seconds since the epoch.
|
||||
@return The local time.
|
||||
*/
|
||||
fn to_local(EpochTime epoch_time) {
|
||||
le TimeConverter converter;
|
||||
/**
|
||||
Converts a time in seconds since the epoch to a local time.
|
||||
@param epoch_time The time in seconds since the epoch.
|
||||
@return The local time.
|
||||
*/
|
||||
fn to_local(EpochTime epoch_time) {
|
||||
le TimeConverter converter;
|
||||
|
||||
converter.value = builtin::std::time::to_local(epoch_time);
|
||||
converter.value = builtin::std::time::to_local(epoch_time);
|
||||
|
||||
return converter.time;
|
||||
};
|
||||
return converter.time;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a time in seconds since the epoch to a UTC time.
|
||||
@param epoch_time The time in seconds since the epoch.
|
||||
@return The UTC time.
|
||||
*/
|
||||
fn to_utc(EpochTime epoch_time) {
|
||||
le TimeConverter converter;
|
||||
/**
|
||||
Converts a time in seconds since the epoch to a UTC time.
|
||||
@param epoch_time The time in seconds since the epoch.
|
||||
@return The UTC time.
|
||||
*/
|
||||
fn to_utc(EpochTime epoch_time) {
|
||||
le TimeConverter converter;
|
||||
|
||||
converter.value = builtin::std::time::to_utc(epoch_time);
|
||||
converter.value = builtin::std::time::to_utc(epoch_time);
|
||||
|
||||
return converter.time;
|
||||
};
|
||||
return converter.time;
|
||||
};
|
||||
|
||||
/**
|
||||
Queries the current time in the specified time zone.
|
||||
@param time_zone The time zone to query.
|
||||
@return The current time in the specified time zone.
|
||||
*/
|
||||
fn now(TimeZone time_zone = TimeZone::Local) {
|
||||
le TimeConverter converter;
|
||||
/**
|
||||
Queries the current time in the specified time zone.
|
||||
@param [time_zone] The time zone to query. Defaults to local.
|
||||
@return The current time in the specified time zone.
|
||||
*/
|
||||
fn now(TimeZone time_zone = TimeZone::Local) {
|
||||
le TimeConverter converter;
|
||||
|
||||
if (time_zone == TimeZone::Local)
|
||||
converter.value = builtin::std::time::to_local(std::time::epoch());
|
||||
else if (time_zone == TimeZone::UTC)
|
||||
converter.value = builtin::std::time::to_utc(std::time::epoch());
|
||||
else
|
||||
converter.value = 0x00;
|
||||
if (time_zone == TimeZone::Local)
|
||||
converter.value = builtin::std::time::to_local(std::time::epoch());
|
||||
else if (time_zone == TimeZone::UTC)
|
||||
converter.value = builtin::std::time::to_utc(std::time::epoch());
|
||||
else
|
||||
converter.value = 0x00;
|
||||
|
||||
return converter.time;
|
||||
};
|
||||
return converter.time;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a value to a DOS date.
|
||||
@param value The value to convert.
|
||||
@return The DOS date.
|
||||
*/
|
||||
fn to_dos_date(u16 value) {
|
||||
le impl::DOSDateConverter converter;
|
||||
/**
|
||||
Converts a value to a DOS date.
|
||||
@param value The value to convert.
|
||||
@return The DOS date.
|
||||
*/
|
||||
fn to_dos_date(u16 value) {
|
||||
le impl::DOSDateConverter converter;
|
||||
|
||||
converter.value = value;
|
||||
converter.value = value;
|
||||
|
||||
return converter.date;
|
||||
};
|
||||
return converter.date;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a value to a DOS time.
|
||||
@param value The value to convert.
|
||||
@return The DOS time.
|
||||
*/
|
||||
fn to_dos_time(u16 value) {
|
||||
le impl::DOSTimeConverter converter;
|
||||
/**
|
||||
Converts a value to a DOS time.
|
||||
@param value The value to convert.
|
||||
@return The DOS time.
|
||||
*/
|
||||
fn to_dos_time(u16 value) {
|
||||
le impl::DOSTimeConverter converter;
|
||||
|
||||
converter.value = value;
|
||||
converter.value = value;
|
||||
|
||||
return converter.time;
|
||||
};
|
||||
return converter.time;
|
||||
};
|
||||
|
||||
/**
|
||||
Converts a FILETIME to unix time.
|
||||
@param value The value to convert.
|
||||
@return Timestamp formatted as unix time.
|
||||
*/
|
||||
fn filetime_to_unix(u64 value) {
|
||||
return value / 10000000 - 11644473600;
|
||||
};
|
||||
/**
|
||||
Converts a FILETIME to unix time.
|
||||
@param value The value to convert.
|
||||
@return Timestamp formatted as unix time.
|
||||
*/
|
||||
fn filetime_to_unix(u64 value) {
|
||||
return value / 10000000 - 11644473600;
|
||||
};
|
||||
|
||||
/**
|
||||
Formats a time according to the specified format string.
|
||||
@param time The time to format.
|
||||
@param format_string The format string to use.
|
||||
@return The formatted time.
|
||||
*/
|
||||
fn format(Time time, str format_string = "%c") {
|
||||
le TimeConverter converter;
|
||||
converter.time = time;
|
||||
/**
|
||||
Formats a time according to the specified format string.
|
||||
@param time The time to format.
|
||||
@param [format_string] The format string to use. Defaults to "%c".
|
||||
@return The formatted time.
|
||||
*/
|
||||
fn format(Time time, str format_string = "%c") {
|
||||
le TimeConverter converter;
|
||||
converter.time = time;
|
||||
|
||||
return builtin::std::time::format(format_string, converter.value);
|
||||
};
|
||||
return builtin::std::time::format(format_string, converter.value);
|
||||
};
|
||||
|
||||
/**
|
||||
Formats a DOS date according to the specified format string.
|
||||
@param date The DOS date to format.
|
||||
@param format_string The format string to use.
|
||||
@return The formatted DOS date.
|
||||
*/
|
||||
fn format_dos_date(DOSDate date, str format_string = "{}/{}/{}") {
|
||||
return std::format(format_string, date.day, date.month, date.year + 1980);
|
||||
};
|
||||
/**
|
||||
Formats a DOS date according to the specified format string.
|
||||
@param date The DOS date to format.
|
||||
@param [format_string] The format string to use. Defaults to "{}/{}/{}".
|
||||
@return The formatted DOS date.
|
||||
*/
|
||||
fn format_dos_date(DOSDate date, str format_string = "{}/{}/{}") {
|
||||
return std::format(format_string, date.day, date.month, date.year + 1980);
|
||||
};
|
||||
|
||||
/**
|
||||
Formats a DOS time according to the specified format string.
|
||||
@param time The DOS time to format.
|
||||
@param format_string The format string to use.
|
||||
@return The formatted DOS time.
|
||||
*/
|
||||
fn format_dos_time(DOSTime time, str format_string = "{:02}:{:02}:{:02}") {
|
||||
return std::format(format_string, time.hours, time.minutes, time.seconds * 2);
|
||||
};
|
||||
/**
|
||||
Formats a DOS time according to the specified format string.
|
||||
@param time The DOS time to format.
|
||||
@param [format_string] The format string to use. Defaults to "{:02}:{:02}:{:02}".
|
||||
@return The formatted DOS time.
|
||||
*/
|
||||
fn format_dos_time(DOSTime time, str format_string = "{:02}:{:02}:{:02}") {
|
||||
return std::format(format_string, time.hours, time.minutes, time.seconds * 2);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/math.pat>
|
||||
import std.io;
|
||||
import std.math;
|
||||
|
||||
/*!
|
||||
Types used to change the base of the displayed integer value.
|
||||
Used like `type::Hex<u32> hexNumber;`, `type::Oct<u16> octalNumber;`
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Integer type representing a Hexadecimal value. Displays its value in hexadecimal format.
|
||||
@@ -34,7 +34,7 @@ namespace type {
|
||||
*/
|
||||
using Bin<T> = T [[format("type::impl::format_bin")]];
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
fn format_number(auto value, str fmt) {
|
||||
bool negative = value < 0;
|
||||
@@ -50,6 +50,6 @@ namespace type {
|
||||
fn format_dec(auto value) { return type::impl::format_number(value, "{}"); };
|
||||
fn format_bin(auto value) { return type::impl::format_number(value, "0b{:08b}"); };
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <std/io.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.string;
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Type representing a Base64 encoded string
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type representing a Base64 encoded string
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Type to decode a BCD (Binary Coded Decimal) number
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Decodes a BCD value where one byte represents a single digit
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Types to display single bytes using various different representations
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type visualizing the value of each individual bit
|
||||
@@ -40,7 +40,7 @@ namespace type {
|
||||
} [[format("type::impl::format_byte"), single_color]];
|
||||
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
fn format_byte(Byte byte) {
|
||||
return std::format("0x{0:02X} (0b{1:08b}) LSB:{2}, MSB:{3}",
|
||||
@@ -66,6 +66,6 @@ namespace type {
|
||||
return std::format("{{ {0:0X}, {1:0X} }}", nibbles.high, nibbles.low);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
import std.io;
|
||||
import std.core;
|
||||
|
||||
/*!
|
||||
Types representing RGB or RGBA colors. The decoded color will be displayed in their color field
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type representing a generic RGBA color with a variable number of bits for each color
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/math.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.math;
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Type representing a 16 bit half precision floating point number
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type representing a 16 bit half precision floating point number
|
||||
@@ -22,7 +22,7 @@ namespace type {
|
||||
float floatValue;
|
||||
};
|
||||
|
||||
fn format_float16(float16 value) {
|
||||
fn format_float16(float16 value) {
|
||||
u32 sign = value >> 15;
|
||||
u32 exponent = (value >> 10) & 0x1F;
|
||||
u32 mantissa = value & 0x3FF;
|
||||
|
||||
42
includes/type/fmt.pat
Normal file
42
includes/type/fmt.pat
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Type that allows specifying its format value using a format string.
|
||||
## Usage
|
||||
|
||||
The following code reads a u32 from the data and formats it as an upper case hexadecimal value with
|
||||
a minimum of 8 digits which is prefixed by 0x.
|
||||
|
||||
The format string is the same as passed to `std::format()` and follows the libfmt specification.
|
||||
|
||||
```rust
|
||||
type::Formatted<u32, "0x{:08X}"> hex_formatted_integer @ 0x00;
|
||||
```
|
||||
*/
|
||||
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Arbitrarily formatted type
|
||||
@tparam T Type to format
|
||||
@tparam FormatString libfmt format string to format the value
|
||||
*/
|
||||
struct Formatted<T, auto FormatString> {
|
||||
T value;
|
||||
} [[sealed, format("type::impl::format_formatted"), transform("type::impl::transform_formatted")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_formatted(ref auto formatted) {
|
||||
return std::format(std::format("{{0:{}}}", formatted.FormatString), formatted.value);
|
||||
};
|
||||
|
||||
fn transform_formatted(ref auto formatted) {
|
||||
return formatted.value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Types to deal with UUIDs (Universally Unique Identifiers) / GUIDs (Globally Unique Identifiers) as described in RFC 4122
|
||||
Types to deal with UUIDs (Universally Unique Identifiers) / GUIDs (Globally Unique Identifiers) as described in RFC 4122
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type representing a GUID value
|
||||
*/
|
||||
struct GUID {
|
||||
/**
|
||||
Type representing a GUID value
|
||||
*/
|
||||
struct GUID {
|
||||
u32 time_low;
|
||||
u16 time_mid;
|
||||
u16 time_high_and_version;
|
||||
@@ -20,31 +20,31 @@ namespace type {
|
||||
u8 node[6];
|
||||
} [[sealed, format("type::impl::format_guid")]];
|
||||
|
||||
/**
|
||||
Alias name for GUID
|
||||
*/
|
||||
using UUID = GUID;
|
||||
/**
|
||||
Alias name for GUID
|
||||
*/
|
||||
using UUID = GUID;
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
fn format_guid(GUID guid) {
|
||||
bool valid = ((le u16(guid.time_high_and_version) >> 12) <= 5) && (((guid.clock_seq_and_reserved >> 4) >= 8) || ((guid.clock_seq_and_reserved >> 4) == 0));
|
||||
|
||||
return std::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
|
||||
valid ? "" : "Invalid ",
|
||||
le u32(guid.time_low),
|
||||
le u16(guid.time_mid),
|
||||
le u16(guid.time_high_and_version),
|
||||
guid.clock_seq_and_reserved,
|
||||
guid.clock_seq_low,
|
||||
guid.node[0],
|
||||
guid.node[1],
|
||||
guid.node[2],
|
||||
guid.node[3],
|
||||
guid.node[4],
|
||||
guid.node[5]);
|
||||
};
|
||||
fn format_guid(GUID guid) {
|
||||
bool valid = ((le u16(guid.time_high_and_version) >> 12) <= 5) && (((guid.clock_seq_and_reserved >> 4) >= 8) || ((guid.clock_seq_and_reserved >> 4) == 0));
|
||||
|
||||
return std::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
|
||||
valid ? "" : "Invalid ",
|
||||
le u32(guid.time_low),
|
||||
le u16(guid.time_mid),
|
||||
le u16(guid.time_high_and_version),
|
||||
guid.clock_seq_and_reserved,
|
||||
guid.clock_seq_low,
|
||||
guid.node[0],
|
||||
guid.node[1],
|
||||
guid.node[2],
|
||||
guid.node[3],
|
||||
guid.node[4],
|
||||
guid.node[5]);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/string.pat>
|
||||
import std.io;
|
||||
import std.string;
|
||||
|
||||
/*!
|
||||
Types used to decode IP addresses
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
A 4 byte IPv4 Address as described in RFC 791
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Types used to decode Little Endian Base 128 numbers used to store large numbers as space efficiently as possible
|
||||
Types used to decode Little Endian Base 128 numbers used to store large numbers as space efficiently as possible
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
|
||||
/**
|
||||
Base LEB128 type. Use `uLEB128` and `sLEB128` instead.
|
||||
*/
|
||||
struct LEB128Base {
|
||||
u8 array[while($ == addressof(this) || std::mem::read_unsigned($-1, 1) & 0x80 != 0)] [[hidden]];
|
||||
} [[sealed]];
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Base LEB128 type. Use `uLEB128` and `sLEB128` instead.
|
||||
*/
|
||||
struct LEB128Base {
|
||||
u8 array[while($ == addressof(this) || std::mem::read_unsigned($-1, 1) & 0x80 != 0)] [[hidden]];
|
||||
} [[sealed]];
|
||||
|
||||
/**
|
||||
A unsigned variant of a LEB128 number
|
||||
*/
|
||||
using uLEB128 = LEB128Base [[format("type::impl::format_uleb128"), transform("type::impl::transform_uleb128")]];
|
||||
/**
|
||||
A unsigned variant of a LEB128 number
|
||||
*/
|
||||
using uLEB128 = LEB128Base [[format("type::impl::format_uleb128"), transform("type::impl::transform_uleb128")]];
|
||||
|
||||
/**
|
||||
A signed variant of a LEB128 number
|
||||
*/
|
||||
using sLEB128 = LEB128Base [[format("type::impl::format_sleb128"), transform("type::impl::transform_sleb128")]];
|
||||
/**
|
||||
A signed variant of a LEB128 number
|
||||
*/
|
||||
using sLEB128 = LEB128Base [[format("type::impl::format_sleb128"), transform("type::impl::transform_sleb128")]];
|
||||
|
||||
/**
|
||||
Legacy alias for uLEB128
|
||||
*/
|
||||
using LEB128 = uLEB128;
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn transform_uleb128_array(ref auto array) {
|
||||
u128 res = array[0] & 0x7f;
|
||||
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
|
||||
res |= u128(array[i] & 0x7f) << 7 * i;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
/**
|
||||
Legacy alias for uLEB128
|
||||
*/
|
||||
using LEB128 = uLEB128;
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn transform_uleb128_array(ref auto array) {
|
||||
u128 res = array[0] & 0x7f;
|
||||
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
|
||||
res |= u128(array[i] & 0x7f) << 7 * i;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn transform_sleb128_array(ref auto array) {
|
||||
s128 res = type::impl::transform_uleb128_array(array);
|
||||
if (res & 0x40 != 0) {
|
||||
res |= ~0 << (sizeof(array) / sizeof(u8)) * 7;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn format_uleb128(ref auto leb128) {
|
||||
u128 res = type::impl::transform_uleb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_uleb128(ref auto leb128) {
|
||||
return type::impl::transform_uleb128_array(leb128.array);
|
||||
};
|
||||
fn transform_sleb128_array(ref auto array) {
|
||||
s128 res = type::impl::transform_uleb128_array(array);
|
||||
if (res & 0x40 != 0) {
|
||||
res |= ~0 << (sizeof(array) / sizeof(u8)) * 7;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn format_uleb128(ref auto leb128) {
|
||||
u128 res = type::impl::transform_uleb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_uleb128(ref auto leb128) {
|
||||
return type::impl::transform_uleb128_array(leb128.array);
|
||||
};
|
||||
|
||||
fn format_sleb128(ref auto leb128) {
|
||||
s128 res = type::impl::transform_sleb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_sleb128(ref auto leb128) {
|
||||
return type::impl::transform_sleb128_array(leb128.array);
|
||||
};
|
||||
fn format_sleb128(ref auto leb128) {
|
||||
s128 res = type::impl::transform_sleb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_sleb128(ref auto leb128) {
|
||||
return type::impl::transform_sleb128_array(leb128.array);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Types used to decode MAC Addresses
|
||||
Types used to decode MAC Addresses
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
A MAC Address as used in the Internet Protocol
|
||||
*/
|
||||
struct MACAddress {
|
||||
u8 bytes[6];
|
||||
} [[sealed, format("type::impl::format_mac_address")]];
|
||||
/**
|
||||
A MAC Address as used in the Internet Protocol
|
||||
*/
|
||||
struct MACAddress {
|
||||
u8 bytes[6];
|
||||
} [[sealed, format("type::impl::format_mac_address")]];
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
fn format_mac_address(MACAddress address) {
|
||||
return std::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}",
|
||||
address.bytes[0],
|
||||
address.bytes[1],
|
||||
address.bytes[2],
|
||||
address.bytes[3],
|
||||
address.bytes[4],
|
||||
address.bytes[5]);
|
||||
};
|
||||
return std::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}",
|
||||
address.bytes[0],
|
||||
address.bytes[1],
|
||||
address.bytes[2],
|
||||
address.bytes[3],
|
||||
address.bytes[4],
|
||||
address.bytes[5]);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +1,43 @@
|
||||
#include <std/string.pat>
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/ctype.pat>
|
||||
import std.string;
|
||||
import std.sys;
|
||||
import std.io;
|
||||
import std.ctype;
|
||||
|
||||
/*!
|
||||
Types used to parse and enforce specific magic numbers
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type
|
||||
{
|
||||
fn fm(ref auto value)
|
||||
{
|
||||
str result;
|
||||
for (u32 i = 0, i < sizeof(value), i += 1)
|
||||
{
|
||||
char c = value[i];
|
||||
|
||||
if (std::ctype::isprint(c))
|
||||
result += c;
|
||||
else
|
||||
result += std::format("\\x{:02X}", u8(c));
|
||||
}
|
||||
return std::format("\"{}\"", result);
|
||||
};
|
||||
|
||||
/**
|
||||
A Magic number. Throws an error if the magic number does not match the expected value
|
||||
@tparam ExpectedValue A string representing the expected value
|
||||
*/
|
||||
struct Magic<auto ExpectedValue> {
|
||||
struct Magic<auto ExpectedValue>
|
||||
{
|
||||
char value[std::string::length(ExpectedValue)];
|
||||
std::assert(value == ExpectedValue, std::format("Invalid magic value! Expected \"{}\", got \"{}\".", ExpectedValue, value));
|
||||
std::assert_warn(value == ExpectedValue, std::format("Invalid magic value! Expected {}, got {} at position 0x{:X}", type::fm(ExpectedValue), type::fm(value), $ - std::string::length(ExpectedValue)));
|
||||
} [[sealed, format("type::impl::format_magic")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_magic(ref auto magic) {
|
||||
str result;
|
||||
for (u32 i = 0, i < sizeof(magic.value), i += 1) {
|
||||
char c = magic.value[i];
|
||||
|
||||
if (std::ctype::isprint(c))
|
||||
result += c;
|
||||
else
|
||||
result += std::format("\\x{:02X}", u8(c));
|
||||
}
|
||||
return std::format("\"{}\"", result);
|
||||
namespace impl
|
||||
{
|
||||
fn format_magic(ref auto magic)
|
||||
{
|
||||
return type::fm(magic.value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +1,53 @@
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
/*!
|
||||
Types dealing with various kinds of resource paths
|
||||
Types dealing with various kinds of resource paths
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
Type representing a single path segment. Use the `Path` type instead of using this on its own
|
||||
@tparam Delimeter The delimeter sequence used to separate two path segments
|
||||
*/
|
||||
struct PathSegment<auto Delimeter> {
|
||||
char string[while(std::mem::read_string($, std::string::length(Delimeter)) != Delimeter && std::mem::read_unsigned($, 1) != 0x00)];
|
||||
char separator [[hidden]];
|
||||
|
||||
if (separator == 0x00) {
|
||||
$ -= 1;
|
||||
break;
|
||||
}
|
||||
} [[sealed, format("type::impl::format_path_segment")]];
|
||||
|
||||
/**
|
||||
A generic type representing a path with an arbitrary delimeter
|
||||
@tparam Delimeter The delimeter sequence used to separate two path segments
|
||||
*/
|
||||
struct Path<auto Delimeter> {
|
||||
PathSegment<Delimeter> segments[while(true)];
|
||||
} [[format("type::impl::format_path")]];
|
||||
|
||||
/**
|
||||
A type representing a Unix path using a '/' forwardslash as delimeter
|
||||
*/
|
||||
using UnixPath = Path<"/">;
|
||||
/**
|
||||
Type representing a single path segment. Use the `Path` type instead of using this on its own
|
||||
@tparam Delimeter The delimeter sequence used to separate two path segments
|
||||
*/
|
||||
struct PathSegment<auto Delimeter> {
|
||||
char string[while(std::mem::read_string($, std::string::length(Delimeter)) != Delimeter && std::mem::read_unsigned($, 1) != 0x00)];
|
||||
char separator [[hidden]];
|
||||
|
||||
if (separator == 0x00) {
|
||||
$ -= 1;
|
||||
break;
|
||||
}
|
||||
} [[sealed, format("type::impl::format_path_segment")]];
|
||||
|
||||
/**
|
||||
A generic type representing a path with an arbitrary delimeter
|
||||
@tparam Delimeter The delimeter sequence used to separate two path segments
|
||||
*/
|
||||
struct Path<auto Delimeter> {
|
||||
PathSegment<Delimeter> segments[while(true)];
|
||||
} [[format("type::impl::format_path")]];
|
||||
|
||||
/**
|
||||
A type representing a Unix path using a '/' forwardslash as delimeter
|
||||
*/
|
||||
using UnixPath = Path<"/">;
|
||||
|
||||
/**
|
||||
A type representing a DOS path using a '\' backslash as delimeter
|
||||
*/
|
||||
using DOSPath = Path<"\\">;
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_path_segment(ref auto segment) {
|
||||
return segment.string;
|
||||
};
|
||||
|
||||
fn format_path(ref auto path) {
|
||||
return std::mem::read_string($, sizeof(path));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
A type representing a DOS path using a '\\' backslash as delimeter
|
||||
*/
|
||||
using DOSPath = Path<"\\">;
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_path_segment(ref auto segment) {
|
||||
return segment.string;
|
||||
};
|
||||
|
||||
fn format_path(ref auto path) {
|
||||
return std::mem::read_string($, sizeof(path));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
/*!
|
||||
Types used to pretty print size values
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
A generic size type which displays its value in Bytes (or kiB, MiB, GiB, TiB, PiB, EiB if larger)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/time.pat>
|
||||
import std.io;
|
||||
import std.time;
|
||||
|
||||
/*!
|
||||
Types used to decode various different time formats
|
||||
*/
|
||||
|
||||
namespace type {
|
||||
namespace auto type {
|
||||
|
||||
/**
|
||||
A 32 bit Unix time value
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
// namespace auto type {
|
||||
|
||||
// using char = s8;
|
||||
using byte = s8;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
// namespace auto type {
|
||||
|
||||
using uint8_t = u8;
|
||||
using uint16_t = u16;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
// namespace auto type {
|
||||
|
||||
using le16 = le u16;
|
||||
using be16 = be u16;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
// namespace auto type {
|
||||
|
||||
// using u8 = u8;
|
||||
// using u16 = u16;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
// namespace auto type {
|
||||
|
||||
using BYTE = u8;
|
||||
using WORD = u16;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Autodesk 3DS Max Model file
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <type/base.pat>
|
||||
import std.io;
|
||||
import type.base;
|
||||
|
||||
#pragma MIME image/x-3ds
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma description 7z File Format
|
||||
#pragma MIME application/x-7z-compressed
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/math.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import std.math;
|
||||
|
||||
|
||||
enum Type:u8{
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#pragma author AdventureT
|
||||
#pragma description Crash Bandicoot - Back in Time (fan game) User created level format
|
||||
// Supports all versions till 0.94c, newer versions might be compatible!
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/array.pat>
|
||||
#pragma history
|
||||
#pragma 0.3 2024-05-15 Added support for version 0.95
|
||||
#pragma 0.2 2023-10-29 Added support for version 0.94c
|
||||
#pragma 0.1 2023-04-25 Initial support
|
||||
// Supports all versions till 0.95, newer versions might be compatible!
|
||||
|
||||
import type.magic;
|
||||
import std.string;
|
||||
import std.array;
|
||||
|
||||
struct Header {
|
||||
type::Magic<"CRASHLVL"> magic;
|
||||
@@ -17,8 +20,6 @@ struct Header {
|
||||
std::string::SizedString<u8> author;
|
||||
};
|
||||
|
||||
Header header @ 0x0;
|
||||
|
||||
// Background Music
|
||||
enum BGM : u32 {
|
||||
None,
|
||||
@@ -37,6 +38,56 @@ enum BGM : u32 {
|
||||
};
|
||||
|
||||
enum BGMV2 : u32 {
|
||||
None,
|
||||
N_TropyBGM,
|
||||
CrashCreatorBGM,
|
||||
MainMenuBGM,
|
||||
WarpRoomBGM,
|
||||
Jungle01BGM,
|
||||
SnowBGM,
|
||||
RiverBGM,
|
||||
FutureBGM,
|
||||
LabBGM,
|
||||
SewerBGM,
|
||||
EgyptBGM,
|
||||
NBrioBGM,
|
||||
AdventureBGM,
|
||||
SpyBGM,
|
||||
ChaseBGM,
|
||||
TrialsBGM,
|
||||
SpaceBGM,
|
||||
Jungle02BGM,
|
||||
RipperBGM,
|
||||
TheGreatWallBGM,
|
||||
RoadToSomewhereBGM,
|
||||
LavaKoalaBGM,
|
||||
CortexBGM,
|
||||
CyberCortexBGM,
|
||||
ArabicBGM,
|
||||
N_Tropy2BGM,
|
||||
JazzBGM,
|
||||
Space2BGM,
|
||||
TawnaBonusBGM,
|
||||
CortexPowerBGM,
|
||||
ArabicBonusBGM,
|
||||
EgyptBonusBGM,
|
||||
FutureBonusBGM,
|
||||
LostCityBGM,
|
||||
PolarBGM,
|
||||
RiverBonusBGM,
|
||||
RuinsBonusBGM,
|
||||
SewerBonusBGM,
|
||||
SnowBonusBGM,
|
||||
RoadToRuinBGM,
|
||||
NGinBGM,
|
||||
Arabia01BGM,
|
||||
Arabia02BGM,
|
||||
BashBGM,
|
||||
Cortex02BGM
|
||||
};
|
||||
|
||||
// v0.95
|
||||
enum BGMV3 : BGMV2 {
|
||||
None,
|
||||
N_TropyBGM,
|
||||
CrashCreatorBGM,
|
||||
@@ -83,12 +134,19 @@ enum BGMV2 : u32 {
|
||||
Arabia02BGM,
|
||||
BashBGM,
|
||||
Cortex02BGM,
|
||||
MedievalBGM,
|
||||
PreHistoricBGM,
|
||||
UnderWaterBGM,
|
||||
BrioRevisitedBGM,
|
||||
EgyptChaseBGM,
|
||||
RuinsLoopBGM,
|
||||
DingoSynthBGM
|
||||
};
|
||||
|
||||
enum Type : u32 {
|
||||
Unset,
|
||||
Flashback,
|
||||
Trial,
|
||||
Trial
|
||||
};
|
||||
|
||||
enum TypeV2 : u32 {
|
||||
@@ -118,13 +176,31 @@ enum SkyboxV2 : u32 {
|
||||
Black
|
||||
};
|
||||
|
||||
// 0.95
|
||||
enum SkyboxV3 : u32 {
|
||||
Default = 1,
|
||||
Briolab,
|
||||
Fort,
|
||||
Moon,
|
||||
Toxic,
|
||||
AboutRight,
|
||||
Crash1Island,
|
||||
Arabia,
|
||||
RoadToRuin,
|
||||
MotorcycleDay,
|
||||
MotorcycleNoon,
|
||||
MotorcycleMoon,
|
||||
MotorcycleNight,
|
||||
Black
|
||||
};
|
||||
|
||||
enum Scenery : u32 {
|
||||
None,
|
||||
FutureTense,
|
||||
Forest,
|
||||
Waterfall,
|
||||
Snow,
|
||||
Fortress,
|
||||
Fortress
|
||||
};
|
||||
|
||||
enum SceneryV2 : u32 {
|
||||
@@ -165,44 +241,102 @@ enum SceneryV4 : u32 {
|
||||
Pipes
|
||||
};
|
||||
|
||||
// 0.95
|
||||
enum SceneryV5 : u32 {
|
||||
None,
|
||||
FutureTense,
|
||||
Forest,
|
||||
Waterfall,
|
||||
Snow,
|
||||
Fortress,
|
||||
None2,
|
||||
Lava,
|
||||
TheGreatGate,
|
||||
Mountain,
|
||||
KoalaKong,
|
||||
SunsetVista,
|
||||
HangemHigh,
|
||||
Sphynxinator,
|
||||
Tunnel,
|
||||
Pipes,
|
||||
Medieval,
|
||||
FutureCity,
|
||||
TinyArena,
|
||||
HeavyMachinery,
|
||||
CrystalCave,
|
||||
MedievalWithHouses,
|
||||
CortexBonusChamber
|
||||
};
|
||||
|
||||
enum Weather : u32 {
|
||||
Default,
|
||||
Snow,
|
||||
Rain
|
||||
};
|
||||
|
||||
// 0.95
|
||||
enum WeatherV2 : u32 {
|
||||
Default,
|
||||
Snow,
|
||||
Rain,
|
||||
Night,
|
||||
UnderWater
|
||||
};
|
||||
|
||||
|
||||
struct Options {
|
||||
|
||||
if (header.version > 1)
|
||||
// Type
|
||||
if (header.version > 1) {
|
||||
TypeV2 type;
|
||||
else
|
||||
Type type;
|
||||
|
||||
if (header.version > 1)
|
||||
SkyboxV2 skybox;
|
||||
else
|
||||
Skybox skybox;
|
||||
|
||||
if (header.version == 1)
|
||||
Scenery scenery;
|
||||
else if (header.version > 1 && header.version < 4)
|
||||
SceneryV2 scenery;
|
||||
else
|
||||
SceneryV4 scenery;
|
||||
|
||||
if (header.version > 2)
|
||||
{
|
||||
Weather weather;
|
||||
}
|
||||
|
||||
if (header.version > 1)
|
||||
else {
|
||||
Type type;
|
||||
}
|
||||
// Skybox
|
||||
if (header.version > 1) {
|
||||
if (header.gameVersion == "0.95") {
|
||||
SkyboxV3 skybox;
|
||||
}
|
||||
else {
|
||||
SkyboxV2 skybox;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Skybox skybox;
|
||||
}
|
||||
// Scenery
|
||||
if (header.version == 1) {
|
||||
Scenery scenery;
|
||||
}
|
||||
else if (header.version > 1 && header.version < 4) {
|
||||
SceneryV2 scenery;
|
||||
}
|
||||
else {
|
||||
if (header.gameVersion == "0.95") {
|
||||
SceneryV5 skybox;
|
||||
}
|
||||
else {
|
||||
SceneryV4 skybox;
|
||||
}
|
||||
}
|
||||
// Weather
|
||||
if (header.version > 2) {
|
||||
if (header.gameVersion == "0.95") {
|
||||
WeatherV2 weather;
|
||||
}
|
||||
else {
|
||||
Weather weather;
|
||||
}
|
||||
}
|
||||
// Background music
|
||||
if (header.version > 1) {
|
||||
BGMV2 bgm;
|
||||
else
|
||||
}
|
||||
else {
|
||||
BGM bgm;
|
||||
|
||||
|
||||
if (type == Type::Trial)
|
||||
{
|
||||
}
|
||||
// Time Trial
|
||||
if (type == Type::Trial) {
|
||||
u32 timeTrialTicksBronze;
|
||||
u32 timeTrialTicksSilver;
|
||||
u32 timeTrialTicksGold;
|
||||
@@ -210,22 +344,17 @@ struct Options {
|
||||
};
|
||||
|
||||
struct Object {
|
||||
|
||||
std::string::SizedString<u8> objName;
|
||||
|
||||
if (header.version > 1)
|
||||
{
|
||||
if (header.version > 1) {
|
||||
u16 x;
|
||||
u16 y;
|
||||
bool hasMetafields;
|
||||
if (hasMetafields)
|
||||
{
|
||||
if (hasMetafields) {
|
||||
u16 numOfMetafields;
|
||||
u8 metafields[numOfMetafields];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else {
|
||||
u32 x;
|
||||
u32 y;
|
||||
}
|
||||
@@ -236,9 +365,6 @@ struct Objects{
|
||||
std::Array<Object, objCount> objArray;
|
||||
};
|
||||
|
||||
|
||||
Header header @ $;
|
||||
Options options @ $;
|
||||
Objects objects @ $;
|
||||
|
||||
|
||||
|
||||
Objects objects @ $;
|
||||
198
patterns/adts.hexpat
Normal file
198
patterns/adts.hexpat
Normal file
@@ -0,0 +1,198 @@
|
||||
#pragma authors: zhoubo
|
||||
#pragma version: 0.4
|
||||
#pragma description: Parse AAC's ADTS(Audio Data Transport Stream) audio files.
|
||||
#pragma category: Audio
|
||||
#pragma filemask: *.aac
|
||||
#pragma IDBytes: FF F //ADTS Syncword
|
||||
#pragma history:
|
||||
#pragma 0.4 2024-02-12 zhoubo: Porting from 010 Editor Templates.
|
||||
#pragma 0.3 2024-02-09 zhoubo: use BitfieldDisablePadding(Unpadded Bitfields) for odd header bytes(7,9 bytes) color, and remove FSeek.
|
||||
#pragma 0.2 2024-02-05 zhoubo: fix some comment & color.
|
||||
#pragma 0.1 2022-06-13 zhoubo: Init release. only ADTS, not support ADIF,LATM.
|
||||
|
||||
// More information available at:
|
||||
// 1. https://wiki.multimedia.cx/index.php?title=ADTS
|
||||
// 2. https://en.wikipedia.org/wiki/Advanced_Audio_Coding
|
||||
// 3. https://en.wikipedia.org/wiki/AAC
|
||||
// 4. https://juejin.cn/post/7032170229732442148
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
fn GetMPEGVersionComment(auto MPEG_Version)
|
||||
{
|
||||
str comment = "";
|
||||
match (MPEG_Version)
|
||||
{
|
||||
(0): comment = "MPEG-4";
|
||||
(1): comment = "MPEG-2";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetProtectionAbsentComment(auto Protection_absence)
|
||||
{
|
||||
str comment = "";
|
||||
match (Protection_absence)
|
||||
{
|
||||
(0): comment = "ADTS has 9 bytes with CRC";
|
||||
(1): comment = "ADTS has 7 bytes without CRC";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetProfileComment(auto Profile)
|
||||
{
|
||||
str comment = "";
|
||||
match (Profile)
|
||||
{
|
||||
(0x00): comment = "AAC Main";
|
||||
(0x01): comment = "AAC LC (Low Complexity)";
|
||||
(0x10): comment = "AAC SSR (Scalable Sample Rate)";
|
||||
(0x11): comment = "AAC LTP (Long Term Prediction)";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetSamplingFrequencyIndexComment(auto Sampling_frequency_index)
|
||||
{
|
||||
str comment = "";
|
||||
match (Sampling_frequency_index)
|
||||
{
|
||||
(0x0): comment = "96000Hz";
|
||||
(0x1): comment = "88200Hz";
|
||||
(0x2): comment = "64000Hz";
|
||||
(0x3): comment = "48000Hz";
|
||||
(0x4): comment = "44100Hz";
|
||||
(0x5): comment = "32000Hz";
|
||||
(0x6): comment = "24000Hz";
|
||||
(0x7): comment = "22050Hz";
|
||||
(0x8): comment = "16000Hz";
|
||||
(0x9): comment = "12000Hz";
|
||||
(0xa): comment = "11025Hz";
|
||||
(0xb): comment = "8000Hz";
|
||||
(0xc): comment = "7350Hz";
|
||||
(0xd): comment = "Reserved";
|
||||
(0xe): comment = "Reserved";
|
||||
(0xf): comment = "FORBIDDEN (malformed)";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetChannelConfigurationComment(auto Channel_configuration)
|
||||
{
|
||||
str comment = "";
|
||||
match (Channel_configuration)
|
||||
{
|
||||
(0): comment = "Defined in AOT Specifc Config";
|
||||
(1): comment = "1 channel: front-center";
|
||||
(2): comment = "2 channels: front-left, front-right";
|
||||
(3): comment = "3 channels: front-center, front-left, front-right";
|
||||
(4): comment = "4 channels: front-center, front-left, front-right, back-center";
|
||||
(5): comment = "5 channels: front-center, front-left, front-right, back-left, back-right";
|
||||
(6): comment = "6 channels: front-center, front-left, front-right, back-left, back-right, LFE-channel";
|
||||
(7): comment = "8 channels: front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetBufferFullnessComment(auto ADTS_buffer_fullness)
|
||||
{
|
||||
str comment = "";
|
||||
match (ADTS_buffer_fullness)
|
||||
{
|
||||
(0x7FF): comment = "VBR (most software ignore this field)";
|
||||
(_): comment = "rate..?? (most software ignore this field)";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
fn GetRawDataBlockComment(auto Number_of_AAC_frames_minus_1)
|
||||
{
|
||||
str comment = "";
|
||||
match (Number_of_AAC_frames_minus_1)
|
||||
{
|
||||
(0x0): comment = "has 1 AAC data block";
|
||||
(_): comment = "data block number + 1";
|
||||
}
|
||||
return comment;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------
|
||||
// Define structures used in AAC files
|
||||
//
|
||||
// [1.adts_fixed_header information]
|
||||
// Syncword: 12bits, sync header, always 0xFFF。
|
||||
// MPEG_Version: 1bit, 0 means MPGE-4, 1 means MPGE-2
|
||||
// Layer: 2bits, alwayas ”00”
|
||||
// Protection_absence: 1bit, 0 means ADTS Header 9 bytes; 1 means ADTS Header 7 bytes
|
||||
// Profile: 2bit, AAC level : Main,LC,SSR,LTP
|
||||
// Sampling_frequency_index: 4bits, Sampling Frequencies
|
||||
// Private_bit: 1bit
|
||||
// Channel_configuration: 3bits, channel number...
|
||||
// Originality: 1bit
|
||||
// Home: 1bit
|
||||
//
|
||||
// [2.adts_variable_header information]
|
||||
// Copyright_id_bit: 1bit
|
||||
// Copyright_id_start: 1bit
|
||||
// AAC_frame_length: 13bits, AAC frame length : ADTS Header(7 or 9 bytes) + sizeof(AAC Frame)
|
||||
// ADTS_buffer_fullness: 11bits, 0x7FF means VBR
|
||||
// Number_of_AAC_frames_minus_1: 2bits, ADTS Frame numbers : Number_of_AAC_frames_minus_1 + 1
|
||||
//
|
||||
// [3.CRC information]
|
||||
// CRC16: 16bits, when Protection_absence=0
|
||||
|
||||
bitfield ADTS_HEADER
|
||||
{
|
||||
// ADTS_FIXED_HEADER
|
||||
Syncword : 12 [[color("00FF00"), comment("always 0xFFF")]];
|
||||
MPEG_Version : 1 [[color("00FF00"), comment(GetMPEGVersionComment(this))]];
|
||||
Layer : 2 [[color("00FF00"), comment("always 0")]];
|
||||
Protection_absence : 1 [[color("00FF00"), comment(GetProtectionAbsentComment(this))]];
|
||||
|
||||
Profile : 2 [[color("0000FF"), comment(GetProfileComment(this))]];
|
||||
Sampling_frequency_index : 4 [[color("0000FF"), comment(GetSamplingFrequencyIndexComment(this))]];
|
||||
Private_bit : 1 [[color("0000FF")]];
|
||||
Channel_configuration : 3 [[color("0000FF"), comment(GetChannelConfigurationComment(this))]];
|
||||
Originality : 1 [[color("0000FF")]];
|
||||
Home : 1 [[color("0000FF")]];
|
||||
|
||||
// ADTS_VARIABLE_HEADER
|
||||
Copyright_id_bit : 1 [[color("0000FF")]];
|
||||
Copyright_id_start : 1 [[color("0000FF")]];
|
||||
AAC_frame_length : 13 [[color("0000FF")]];
|
||||
ADTS_buffer_fullness : 11 [[color("0000FF"), comment(GetBufferFullnessComment(this))]];
|
||||
Number_of_AAC_frames_minus_1 : 2 [[color("0000FF"), comment(GetRawDataBlockComment(this))]];
|
||||
|
||||
// ADTS_CRC_HEADER
|
||||
if (0 == Protection_absence) // Header with CRC
|
||||
{
|
||||
u16 CRC16 [[color("FFFF00")]];
|
||||
}
|
||||
else // Header without CRC
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ADTS_FRAME
|
||||
{
|
||||
ADTS_HEADER Header;
|
||||
|
||||
if (0 == Header.Protection_absence) // Header with CRC 2 bytes
|
||||
{
|
||||
u8 Data[Header.AAC_frame_length - 9] [[color("000000")]];
|
||||
}
|
||||
else // Header without CRC
|
||||
{
|
||||
u8 Data[Header.AAC_frame_length - 7] [[color("000000")]];
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
ADTS_FRAME adtsFrame[while(!std::mem::eof())] @ 0x00;
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/sys.pat>
|
||||
import std.io;
|
||||
import std.sys;
|
||||
|
||||
#define ATMOSPHERE_REBOOT_TO_FATAL_MAGIC "AFE2"
|
||||
#define ATMOSPHERE_REBOOT_TO_FATAL_MAGIC_1 "AFE1"
|
||||
|
||||
66
patterns/ani.hexpat
Normal file
66
patterns/ani.hexpat
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma description Windows animated cursor
|
||||
#pragma MIME application/x-navi-animation
|
||||
#pragma endian little
|
||||
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
bitfield HeaderFlags {
|
||||
icon : 1;
|
||||
sequence : 1;
|
||||
padding: 30;
|
||||
};
|
||||
|
||||
struct anih {
|
||||
u32 struct_size;
|
||||
u32 stored_frames;
|
||||
u32 animation_steps;
|
||||
u32 w;
|
||||
u32 h;
|
||||
u32 bits;
|
||||
u32 planes;
|
||||
u32 default_jiffies;
|
||||
HeaderFlags flags;
|
||||
};
|
||||
|
||||
struct rate {
|
||||
u32 jiffies[parent.size / 4];
|
||||
};
|
||||
|
||||
struct seq {
|
||||
u32 index[parent.size / 4];
|
||||
};
|
||||
|
||||
struct RiffChunk {
|
||||
char signature[4];
|
||||
u32 size;
|
||||
if (signature == "RIFF" || signature == "LIST") {
|
||||
char type[4];
|
||||
RiffChunk chunks[while($ - addressof(type) < size)];
|
||||
} else if (signature[0] == 'I' && parent.type == "INFO") {
|
||||
char info[size];
|
||||
} else if (signature == "anih") {
|
||||
anih anih [[inline]];
|
||||
} else if (signature == "rate") {
|
||||
rate rate [[inline]];
|
||||
} else if (signature == "seq ") {
|
||||
seq seq [[inline]];
|
||||
} else {
|
||||
std::mem::Bytes<size> data;
|
||||
}
|
||||
padding[size % 2];
|
||||
} [[format_read("read_chunk")]];
|
||||
|
||||
fn read_chunk(RiffChunk chunk) {
|
||||
if (chunk.signature == "RIFF" || chunk.signature == "LIST") {
|
||||
return std::format("{}<{}> ({})", chunk.signature, chunk.type, chunk.size);
|
||||
} else {
|
||||
str ret = std::format("{} ({})", chunk.signature, chunk.size);
|
||||
try {
|
||||
ret += std::format(" \"{}\"", chunk.info);
|
||||
} catch {}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
RiffChunk riff @ 0;
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#pragma MIME application/x-archive
|
||||
|
||||
#include <std/string.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/sys.pat>
|
||||
import std.string;
|
||||
import std.mem;
|
||||
import std.sys;
|
||||
|
||||
struct ARFile {
|
||||
char file_name[16];
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
#define VTOR 0x00000000
|
||||
#define EXTERNAL_INTERRUPT_COUNT 64
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#pragma MIME application/x-bittorrent
|
||||
|
||||
#include <std/ctype.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
import std.ctype;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
|
||||
namespace bencode {
|
||||
|
||||
|
||||
80
patterns/bgcode.hexpat
Normal file
80
patterns/bgcode.hexpat
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma author Shadlock0133 (aka Aurora)
|
||||
#pragma description Binary G-Code from Prusa
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
enum ChecksumType : u16 {
|
||||
None,
|
||||
CRC32,
|
||||
};
|
||||
|
||||
enum BlockType : u16 {
|
||||
FileMetadata,
|
||||
GCode,
|
||||
SlicerMetadata,
|
||||
PrinterMetadata,
|
||||
PrintMetadata,
|
||||
Thumbnail,
|
||||
};
|
||||
|
||||
enum Compression : u16 {
|
||||
None,
|
||||
Deflate,
|
||||
Heatshrink11_4,
|
||||
Heatshrink12_4,
|
||||
};
|
||||
|
||||
enum Encoding : u16 {
|
||||
Ini,
|
||||
};
|
||||
|
||||
enum ImageFormat : u16 {
|
||||
Png,
|
||||
Jpg,
|
||||
Qoi,
|
||||
};
|
||||
|
||||
struct Header {
|
||||
type::Magic<"GCDE"> magic;
|
||||
u32 version;
|
||||
ChecksumType checksum_type;
|
||||
};
|
||||
|
||||
Header header @ 0;
|
||||
std::assert(header.version == 1, "only version 1 supported");
|
||||
|
||||
struct Block {
|
||||
BlockType type;
|
||||
Compression compression;
|
||||
u32 uncompressed_size;
|
||||
auto size = uncompressed_size;
|
||||
if (compression != Compression::None) {
|
||||
u32 compressed_size;
|
||||
size = compressed_size;
|
||||
}
|
||||
match (type) {
|
||||
(BlockType::FileMetadata
|
||||
| BlockType::PrinterMetadata
|
||||
| BlockType::PrintMetadata
|
||||
| BlockType::SlicerMetadata): {
|
||||
Encoding encoding;
|
||||
}
|
||||
(BlockType::Thumbnail): {
|
||||
ImageFormat image_format;
|
||||
u16 width;
|
||||
u16 height;
|
||||
}
|
||||
(BlockType::GCode): {
|
||||
u16;
|
||||
}
|
||||
(_): { std::assert(false, "unknown type"); }
|
||||
}
|
||||
u8 data[size];
|
||||
match (header.checksum_type) {
|
||||
(ChecksumType::None): {}
|
||||
(ChecksumType::CRC32): { u32 checksum; }
|
||||
}
|
||||
};
|
||||
|
||||
Block blocks[while(!std::mem::eof())] @ $;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#pragma MIME image/bmp
|
||||
#pragma endian little
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
struct BitmapFileHeader {
|
||||
u8 bfType[2];
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <std/math.pat>
|
||||
#include <std/core.pat>
|
||||
#include <type/magic.pat>
|
||||
#include <type/time.pat>
|
||||
#pragma description TODO
|
||||
|
||||
import std.math;
|
||||
import std.core;
|
||||
import type.magic;
|
||||
import type.time;
|
||||
|
||||
using CFBinaryPlistObject;
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma MIME application/bson
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <type/time.pat>
|
||||
import std.mem;
|
||||
import type.time;
|
||||
|
||||
enum Type : u8 {
|
||||
Double = 0x01,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma description GoldSrc engine maps format (used in Half-Life 1)
|
||||
|
||||
#include <std/ptr.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/sys.pat>
|
||||
import std.ptr;
|
||||
import std.mem;
|
||||
import std.sys;
|
||||
|
||||
#pragma endian little
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Windows HtmlHelp Data (ITSF / CHM)
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/guid.pat>
|
||||
#include <type/leb128.pat>
|
||||
#include <std/sys.pat>
|
||||
import type.magic;
|
||||
import type.size;
|
||||
import type.guid;
|
||||
import type.leb128;
|
||||
import std.sys;
|
||||
|
||||
enum WindowsLanguageId : u32 {
|
||||
Arabic_SaudiArabia = 0x401,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma MIME application/x-coff
|
||||
|
||||
#include <type/time.pat>
|
||||
#include <type/size.pat>
|
||||
import type.time;
|
||||
import type.size;
|
||||
|
||||
enum Machine : u16 {
|
||||
Unknown = 0x0000,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Old Binary CPIO Format
|
||||
|
||||
#include <type/base.pat>
|
||||
import type.base;
|
||||
|
||||
#include <std/time.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.time;
|
||||
import std.core;
|
||||
import std.sys;
|
||||
import std.mem;
|
||||
|
||||
#pragma MIME application/x-cpio
|
||||
|
||||
|
||||
@@ -167,16 +167,26 @@ bitfield Caps2Flags {
|
||||
};
|
||||
|
||||
bitfield PixelFormatFlags {
|
||||
alphaPixels : 1;
|
||||
alpha : 1;
|
||||
fourCC : 1;
|
||||
padding : 3;
|
||||
rgb : 1; // 0x40
|
||||
padding : 2;
|
||||
yuv : 1; // 0x200
|
||||
padding : 3;
|
||||
luminance : 1; // 0x20000
|
||||
padding : 17;
|
||||
alphaPixels : 1; // DDPF_ALPHAPIXELS
|
||||
alpha : 1; // DDPF_ALPHA
|
||||
fourCC : 1; // DDPF_FOURCC
|
||||
paletteIndexed4 : 1; // DDPF_PALETTEINDEXED4
|
||||
paletteIndexedTo8 : 1; // DDPF_PALETTEINDEXEDTO8
|
||||
paletteIndexed8 : 1; // DDPF_PALETTEINDEXED8
|
||||
rgb : 1; // DDPF_RGB
|
||||
compressed : 1; // DDPF_COMPRESSED
|
||||
rgbToYuv : 1; // DDPF_RGBTOYUV
|
||||
yuv : 1; // DDPF_YUV
|
||||
zBuffer : 1; // DDPF_ZBUFFER
|
||||
paletteIndexed1 : 1; // DDPF_PALETTEINDEXED1
|
||||
paletteIndexed2 : 1; // DDPF_PALETTEINDEXED2
|
||||
zPixels : 1; // DDPF_ZPIXELS
|
||||
stencilBuffer : 1; // DDPF_STENCILBUFFER
|
||||
alphaResult : 1; // DDPF_ALPHARESULT
|
||||
luminance : 1; // DDPF_LUMINANCE
|
||||
bumpLuminance : 1; // DDPF_BUMPLUMINANCE
|
||||
bumpDudv : 1; // DDPF_BUMPDUDV
|
||||
padding : 13; // Padding bits to complete 32-bit structure
|
||||
};
|
||||
|
||||
enum DX10ResourceDimension : u32 {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma description Dalvik EXecutable Format
|
||||
|
||||
#include <type/leb128.pat>
|
||||
import type.leb128;
|
||||
|
||||
struct header_item {
|
||||
u8 magic[8];
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#pragma MIME application/dicom
|
||||
#pragma endian little
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/sys.pat>
|
||||
#include <type/magic.pat>
|
||||
import std.core;
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
import std.sys;
|
||||
import type.magic;
|
||||
|
||||
u32 UNDEFINED_LENGTH = 0xffffffff;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/guid.pat>
|
||||
#include <std/mem.pat>
|
||||
import type.magic;
|
||||
import type.size;
|
||||
import type.guid;
|
||||
import std.mem;
|
||||
|
||||
// Parse DMG Structure per http://newosxbook.com/DMG.html
|
||||
//
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// Apple macOS .DS_Store format
|
||||
#pragma endian big
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
struct RecordEntry {
|
||||
u32 length;
|
||||
|
||||
117
patterns/dted.hexpat
Normal file
117
patterns/dted.hexpat
Normal file
@@ -0,0 +1,117 @@
|
||||
#pragma description Digital Terrain Elevation Data
|
||||
#pragma endian big
|
||||
|
||||
import std.core;
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
|
||||
|
||||
enum Magic:u24 {
|
||||
UHL = 0x55484C,
|
||||
DSI = 0x445349,
|
||||
ACC = 0x414343,
|
||||
};
|
||||
|
||||
struct UHL {
|
||||
Magic magic;
|
||||
char one;
|
||||
char lon[8];
|
||||
char lat[8];
|
||||
char lon_data_interval[4];
|
||||
char lat_data_interval[4];
|
||||
char accuracy[4];
|
||||
char security_code[3];
|
||||
char uniq_ref[12];
|
||||
char lon_lines[4];
|
||||
char lat_points[4];
|
||||
char multi_accuracy;
|
||||
char reserved[24];
|
||||
};
|
||||
|
||||
struct DSI {
|
||||
Magic magic;
|
||||
char classification;
|
||||
char stuff1[29];
|
||||
char stuff2[26];
|
||||
char product_level[5];
|
||||
char uniq_ref[15];
|
||||
char reserved[8];
|
||||
char data_edition[2];
|
||||
char match_version;
|
||||
char maint_date[4];
|
||||
char match_date[4];
|
||||
char main_desc_code[4];
|
||||
char producer_code[8];
|
||||
char reserved2[16];
|
||||
char product_spec[9];
|
||||
char numbers[2];
|
||||
char product_spec_date[4];
|
||||
char vertical_datum[3];
|
||||
char horizontal_datum[5];
|
||||
char digitizing_system[10];
|
||||
char compilation_date[4];
|
||||
char reserved3[22];
|
||||
char lat_origin[9];
|
||||
char lon_origin[10];
|
||||
char lat_sw_corner[7];
|
||||
char lon_sw_corner[8];
|
||||
char lat_nw_corner[7];
|
||||
char lon_nw_corner[8];
|
||||
char lat_ne_corner[7];
|
||||
char lon_ne_corner[8];
|
||||
char lat_se_corner[7];
|
||||
char lon_se_corner[8];
|
||||
char clockwise_orientation[9];
|
||||
char lat_interval[4];
|
||||
char lon_interval[4];
|
||||
char lat_lines[4];
|
||||
char lon_lines[4];
|
||||
char partial_cell[2];
|
||||
char reserved4[101];
|
||||
char reserved5[100];
|
||||
char reserved6[156];
|
||||
};
|
||||
|
||||
struct ACCSub {
|
||||
char abs_vertical_accuracy[4];
|
||||
char abs_horizontal_accuracy[4];
|
||||
char rel_vertical_accuracy[4];
|
||||
char rel_horizontal_accuracy[4];
|
||||
char num_coords[2];
|
||||
char pairs[19*14];
|
||||
};
|
||||
|
||||
struct ACC {
|
||||
Magic magic;
|
||||
char abs_horizontal_accuracy[4];
|
||||
char abs_vertical_accuracy[4];
|
||||
char rel_horizontal_accuracy[4];
|
||||
char rel_vertical_accuracy[4];
|
||||
char reserved1[4];
|
||||
char reserved2[1];
|
||||
char reserved3[31];
|
||||
char multi_accuracy_outline[2]; // determines sub regions
|
||||
ACCSub subs[9];
|
||||
char reserved4[18];
|
||||
char reserved5[69];
|
||||
|
||||
};
|
||||
|
||||
struct DataRecords {
|
||||
char magic;
|
||||
s24 data_block_count;
|
||||
s16 lon_count;
|
||||
s16 lat_count;
|
||||
s16 elevation[std::string::parse_int(parent.dsi.lat_lines, 10)];
|
||||
u32 checksum;
|
||||
};
|
||||
|
||||
struct DTED {
|
||||
UHL uhl;
|
||||
DSI dsi;
|
||||
ACC acc;
|
||||
DataRecords records[std::string::parse_int(this.dsi.lon_lines, 10)];
|
||||
};
|
||||
|
||||
DTED dted @ 0x00;
|
||||
@@ -7,9 +7,9 @@
|
||||
#pragma MIME application/x-object
|
||||
#pragma MIME application/x-sharedlib
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.core;
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
import std.sys;
|
||||
import std.io;
|
||||
import std.core;
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
import type.magic;
|
||||
import type.size;
|
||||
|
||||
// These are used in order for the children to be able to find strings
|
||||
u64 fdt_addr;
|
||||
|
||||
Submodule patterns/ffx updated: ad18b0259f...199879e24a
@@ -1,9 +1,9 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Free Lossless Audio Codec, FLAC Audio Format
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
import std.sys;
|
||||
import std.core;
|
||||
import std.io;
|
||||
|
||||
#pragma endian big
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Drive File System
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
struct DiskTimeStamp {
|
||||
u8 seconds, minutes, hours;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#pragma MIME application/x-gameboy-rom
|
||||
|
||||
#include <type/size.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/mem.pat>
|
||||
import type.size;
|
||||
import std.string;
|
||||
import std.mem;
|
||||
|
||||
bool uppercaseROMFeatures in;
|
||||
bool brandedROMFeatures in;
|
||||
|
||||
215
patterns/gguf.hexpat
Normal file
215
patterns/gguf.hexpat
Normal file
@@ -0,0 +1,215 @@
|
||||
// https://github.com/ggerganov/ggml/blob/master/docs/gguf.md
|
||||
// https://github.com/openxla/iree/blob/main/runtime/src/iree/io/formats/gguf/gguf_parser.c
|
||||
|
||||
#pragma description GGUF v3 File Format Patter
|
||||
#pragma authors @leonjza, jessie @ imhex discord
|
||||
|
||||
#pragma pattern_limit 300000
|
||||
|
||||
enum ggml_type: u32 {
|
||||
GGML_TYPE_F32 = 0,
|
||||
GGML_TYPE_F16 = 1,
|
||||
GGML_TYPE_Q4_0 = 2,
|
||||
GGML_TYPE_Q4_1 = 3,
|
||||
// GGML_TYPE_Q4_2 = 4, support has been removed
|
||||
// GGML_TYPE_Q4_3 = 5, support has been removed
|
||||
GGML_TYPE_Q5_0 = 6,
|
||||
GGML_TYPE_Q5_1 = 7,
|
||||
GGML_TYPE_Q8_0 = 8,
|
||||
GGML_TYPE_Q8_1 = 9,
|
||||
GGML_TYPE_Q2_K = 10,
|
||||
GGML_TYPE_Q3_K = 11,
|
||||
GGML_TYPE_Q4_K = 12,
|
||||
GGML_TYPE_Q5_K = 13,
|
||||
GGML_TYPE_Q6_K = 14,
|
||||
GGML_TYPE_Q8_K = 15,
|
||||
GGML_TYPE_IQ2_XXS = 16,
|
||||
GGML_TYPE_IQ2_XS = 17,
|
||||
GGML_TYPE_IQ3_XXS = 18,
|
||||
GGML_TYPE_IQ1_S = 19,
|
||||
GGML_TYPE_IQ4_NL = 20,
|
||||
GGML_TYPE_IQ3_S = 21,
|
||||
GGML_TYPE_IQ2_S = 22,
|
||||
GGML_TYPE_IQ4_XS = 23,
|
||||
GGML_TYPE_I8 = 24,
|
||||
GGML_TYPE_I16 = 25,
|
||||
GGML_TYPE_I32 = 26,
|
||||
GGML_TYPE_I64 = 27,
|
||||
GGML_TYPE_F64 = 28,
|
||||
GGML_TYPE_IQ1_M = 29,
|
||||
GGML_TYPE_COUNT,
|
||||
};
|
||||
|
||||
enum gguf_metadata_value_type: u32 {
|
||||
// The value is a 8-bit unsigned integer.
|
||||
GGUF_METADATA_VALUE_TYPE_UINT8 = 0,
|
||||
// The value is a 8-bit signed integer.
|
||||
GGUF_METADATA_VALUE_TYPE_INT8 = 1,
|
||||
// The value is a 16-bit unsigned little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_UINT16 = 2,
|
||||
// The value is a 16-bit signed little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_INT16 = 3,
|
||||
// The value is a 32-bit unsigned little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_UINT32 = 4,
|
||||
// The value is a 32-bit signed little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_INT32 = 5,
|
||||
// The value is a 32-bit IEEE754 floating point number.
|
||||
GGUF_METADATA_VALUE_TYPE_FLOAT32 = 6,
|
||||
// The value is a boolean.
|
||||
// 1-byte value where 0 is false and 1 is true.
|
||||
// Anything else is invalid, and should be treated as either the model being invalid or the reader being buggy.
|
||||
GGUF_METADATA_VALUE_TYPE_BOOL = 7,
|
||||
// The value is a UTF-8 non-null-terminated string, with length prepended.
|
||||
GGUF_METADATA_VALUE_TYPE_STRING = 8,
|
||||
// The value is an array of other values, with the length and type prepended.
|
||||
///
|
||||
// Arrays can be nested, and the length of the array is the number of elements in the array, not the number of bytes.
|
||||
GGUF_METADATA_VALUE_TYPE_ARRAY = 9,
|
||||
// The value is a 64-bit unsigned little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_UINT64 = 10,
|
||||
// The value is a 64-bit signed little-endian integer.
|
||||
GGUF_METADATA_VALUE_TYPE_INT64 = 11,
|
||||
// The value is a 64-bit IEEE754 floating point number.
|
||||
GGUF_METADATA_VALUE_TYPE_FLOAT64 = 12,
|
||||
};
|
||||
|
||||
// A string in GGUF.
|
||||
struct gguf_string_t {
|
||||
// The length of the string, in bytes.
|
||||
u64 len;
|
||||
// The string as a UTF-8 non-null-terminated string.
|
||||
char string[len];
|
||||
};
|
||||
|
||||
|
||||
struct gguf_metadata_value_t {
|
||||
gguf_metadata_value_type type;
|
||||
u64 length;
|
||||
|
||||
match(type) {
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT8): u8 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT8): s8 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT16): u16 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT16): s16 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT32): u32 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT32): s32 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_FLOAT32): float value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_BOOL): bool value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_STRING): gguf_string_t value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT64): u64 value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_FLOAT64): double value[length];
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_ARRAY): double value[length];
|
||||
}
|
||||
};
|
||||
|
||||
struct gguf_metadata_value {
|
||||
gguf_metadata_value_type type;
|
||||
|
||||
match(type) {
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT8): u8 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT8): s8 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT16): u16 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT16): s16 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT32): u32 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_INT32): s32 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_FLOAT32): float value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_BOOL): bool value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_STRING): gguf_string_t value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_UINT64): u64 value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_FLOAT64): double value;
|
||||
(gguf_metadata_value_type::GGUF_METADATA_VALUE_TYPE_ARRAY): gguf_metadata_value_t value;
|
||||
}
|
||||
};
|
||||
|
||||
struct gguf_metadata_kv_t {
|
||||
// The key of the metadata. It is a standard GGUF string, with the following caveats:
|
||||
// - It must be a valid ASCII string.
|
||||
// - It must be a hierarchical key, where each segment is `lower_snake_case` and separated by a `.`.
|
||||
// - It must be at most 2^16-1/65535 bytes long.
|
||||
// Any keys that do not follow these rules are invalid.
|
||||
gguf_string_t key;
|
||||
|
||||
// The type of the value.
|
||||
// Must be one of the `gguf_metadata_value_type` values.
|
||||
// gguf_metadata_value_type value_type;
|
||||
|
||||
// The value.
|
||||
gguf_metadata_value value;
|
||||
};
|
||||
|
||||
struct gguf_header_t {
|
||||
// Magic number to announce that this is a GGUF file.
|
||||
// Must be `GGUF` at the byte level: `0x47` `0x47` `0x55` `0x46`.
|
||||
// Your executor might do little-endian byte order, so it might be
|
||||
// check for 0x46554747 and letting the endianness cancel out.
|
||||
// Consider being *very* explicit about the byte order here.
|
||||
u32 magic;
|
||||
// The version of the format implemented.
|
||||
// Must be `3` for version described in this spec, which introduces big-endian support.
|
||||
//
|
||||
// This version should only be increased for structural changes to the format.
|
||||
// Changes that do not affect the structure of the file should instead update the metadata
|
||||
// to signify the change.
|
||||
u32 version;
|
||||
// The number of tensors in the file.
|
||||
// This is explicit, instead of being included in the metadata, to ensure it is always present
|
||||
// for loading the tensors.
|
||||
u64 tensor_count;
|
||||
// The number of metadata key-value pairs.
|
||||
u64 metadata_kv_count;
|
||||
// The metadata key-value pairs.
|
||||
gguf_metadata_kv_t metadata_kv[metadata_kv_count];
|
||||
};
|
||||
|
||||
struct gguf_tensor_info_t {
|
||||
// The name of the tensor. It is a standard GGUF string, with the caveat that
|
||||
// it must be at most 64 bytes long.
|
||||
gguf_string_t name;
|
||||
// The number of dimensions in the tensor.
|
||||
// Currently at most 4, but this may change in the future.
|
||||
u32 n_dimensions;
|
||||
// The dimensions of the tensor.
|
||||
u64 dimensions[n_dimensions];
|
||||
// The type of the tensor.
|
||||
ggml_type type;
|
||||
// The offset of the tensor's data in this file in bytes.
|
||||
//
|
||||
// This offset is relative to `tensor_data`, not to the start
|
||||
// of the file, to make it easier for writers to write the file.
|
||||
// Readers should consider exposing this offset relative to the
|
||||
// file to make it easier to read the data.
|
||||
//
|
||||
// Must be a multiple of `ALIGNMENT`. That is, `align_offset(offset) == offset`.
|
||||
u64 offset;
|
||||
};
|
||||
|
||||
struct gguf_file_t {
|
||||
// The header of the file.
|
||||
gguf_header_t header;
|
||||
|
||||
// Tensor infos, which can be used to locate the tensor data.
|
||||
gguf_tensor_info_t tensor_infos[header.tensor_count];
|
||||
|
||||
// Padding to the nearest multiple of `ALIGNMENT`.
|
||||
//
|
||||
// That is, if `sizeof(header) + sizeof(tensor_infos)` is not a multiple of `ALIGNMENT`,
|
||||
// this padding is added to make it so.
|
||||
//
|
||||
// This can be calculated as `align_offset(position) - position`, where `position` is
|
||||
// the position of the end of `tensor_infos` (i.e. `sizeof(header) + sizeof(tensor_infos)`).
|
||||
u8 _padding[];
|
||||
|
||||
// Tensor data.
|
||||
//
|
||||
// This is arbitrary binary data corresponding to the weights of the model. This data should be close
|
||||
// or identical to the data in the original model file, but may be different due to quantization or
|
||||
// other optimizations for inference. Any such deviations should be recorded in the metadata or as
|
||||
// part of the architecture definition.
|
||||
//
|
||||
// Each tensor's data must be stored within this array, and located through its `tensor_infos` entry.
|
||||
// The offset of each tensor's data must be a multiple of `ALIGNMENT`, and the space between tensors
|
||||
// should be padded to `ALIGNMENT` bytes.
|
||||
u8 tensor_data[];
|
||||
};
|
||||
|
||||
gguf_file_t GGUF @ 0x00;
|
||||
@@ -13,13 +13,13 @@
|
||||
#define EXTENSION_INTRODUCER_MAGIC 0x21
|
||||
#define GIF_TRAILER_MAGIC 0x3B
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/math.pat>
|
||||
import std.io;
|
||||
import std.core;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
import std.math;
|
||||
|
||||
#include <type/magic.pat>
|
||||
import type.magic;
|
||||
|
||||
bitfield GCT_Flags {
|
||||
size : 3 [[comment("physical size = 2^(flags.size + 1)")]];
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/io.pat>
|
||||
#pragma description TODO
|
||||
|
||||
import std.mem;
|
||||
import std.io;
|
||||
|
||||
/**
|
||||
* @brief The glTF magic section.
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#pragma MIME application/gzip
|
||||
|
||||
#include <type/time.pat>
|
||||
#include <type/size.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
import type.time;
|
||||
import type.size;
|
||||
import std.core;
|
||||
import std.mem;
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <std/mem.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/string.pat>
|
||||
#pragma description TODO
|
||||
|
||||
import std.mem;
|
||||
import std.io;
|
||||
import std.string;
|
||||
|
||||
struct Header {
|
||||
u32 magic;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma author Surasia
|
||||
#pragma description Halo Infinite HavokScript 5.1 "luas" file
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/string.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import std.core;
|
||||
import std.string;
|
||||
|
||||
struct String32 {
|
||||
s32 length;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/sys.pat>
|
||||
import std.sys;
|
||||
|
||||
#pragma MIME image/vnd.microsoft.icon
|
||||
#pragma MIME image/x-icon
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#pragma MIME audio/mpeg
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
namespace v1 {
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
#pragma endian big
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
enum FileType: u16 {
|
||||
Data = 0x3030,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
import std.sys;
|
||||
import std.io;
|
||||
|
||||
struct MAC {
|
||||
u8 octets[6];
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
import std.mem;
|
||||
import std.string;
|
||||
|
||||
struct Hunk {
|
||||
u24 offset;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
import std.io;
|
||||
|
||||
enum VolumeDescriptorTypes : u8 {
|
||||
BootRecord,
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#pragma pattern_limit 100000000
|
||||
#pragma MIME application/x-java-applet
|
||||
|
||||
#include <std/string.pat>
|
||||
#include <std/math.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/sys.pat>
|
||||
import std.string;
|
||||
import std.math;
|
||||
import std.core;
|
||||
import std.io;
|
||||
import std.sys;
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description JPEG Image Format
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <type/magic.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import type.magic;
|
||||
#pragma endian big
|
||||
|
||||
#pragma MIME image/jpeg
|
||||
@@ -41,7 +41,8 @@ enum Marker : u8 {
|
||||
APP13 = 0xED,
|
||||
APP14 = 0xEE,
|
||||
APP15 = 0xEF,
|
||||
COM = 0xFE
|
||||
COM = 0xFE,
|
||||
UNKNOWN = 0X00
|
||||
};
|
||||
|
||||
enum DensityUnit : u8 {
|
||||
@@ -103,6 +104,15 @@ fn sof0_component_read(SOF0Component c) {
|
||||
return std::format("({}, {}, {})", c.componentId, c.samplingFactors, c.quantizationTableId);
|
||||
};
|
||||
|
||||
fn get_eoi_marker_position() {
|
||||
u32 pos = std::mem::find_sequence_in_range(0, $, std::mem::size(), 0xFF);
|
||||
while (std::mem::read_unsigned(pos + 1, 1) != 0xD9) {
|
||||
pos = std::mem::find_sequence_in_range(0, pos + 1, std::mem::size() + 1, 0xFF);
|
||||
}
|
||||
return pos;
|
||||
|
||||
};
|
||||
|
||||
struct SOF0 {
|
||||
u8 bitsPerSample;
|
||||
u16 imageHeight, imageWidth;
|
||||
@@ -121,30 +131,34 @@ struct SOS {
|
||||
u8 startSpectralSelection;
|
||||
u8 endSpectral;
|
||||
u8 apprBitPos;
|
||||
|
||||
u8 image_data[std::mem::size() - $ - 2] [[sealed]];
|
||||
u8 image_data[get_eoi_marker_position() - $] [[sealed]];
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
type::Magic<"\xff"> magic;
|
||||
Marker marker;
|
||||
|
||||
if (marker == Marker::SOI || marker == Marker::EOI) {
|
||||
|
||||
if (std::mem::read_unsigned($, 1) != 0xFF) {
|
||||
Marker marker = Marker::UNKNOWN;
|
||||
u8 data[get_eoi_marker_position() - $];
|
||||
} else {
|
||||
u16 length;
|
||||
if (marker == Marker::APP0) {
|
||||
APP0 data;
|
||||
} else if (marker == Marker::APP14) {
|
||||
APP14 data;
|
||||
} else if (marker == Marker::COM) {
|
||||
char data[length - sizeof(length)];
|
||||
} else if (marker == Marker::SOF0) {
|
||||
SOF0 data;
|
||||
} else if (marker == Marker::SOS) {
|
||||
SOS data;
|
||||
type::Magic<"\xff"> magic;
|
||||
Marker marker;
|
||||
|
||||
if (marker == Marker::SOI || marker == Marker::EOI) {
|
||||
|
||||
} else {
|
||||
u8 data[length - sizeof(length)] [[sealed]];
|
||||
u16 length;
|
||||
if (marker == Marker::APP0) {
|
||||
APP0 data;
|
||||
} else if (marker == Marker::APP14) {
|
||||
APP14 data;
|
||||
} else if (marker == Marker::COM) {
|
||||
char data[length - sizeof(length)];
|
||||
} else if (marker == Marker::SOF0) {
|
||||
SOF0 data;
|
||||
} else if (marker == Marker::SOS) {
|
||||
SOS data;
|
||||
} else {
|
||||
u8 data[length - sizeof(length)] [[sealed]];
|
||||
}
|
||||
}
|
||||
}
|
||||
} [[format_read("segment_read")]];
|
||||
@@ -153,4 +167,4 @@ fn segment_read(Segment s) {
|
||||
return std::format("{}", s.marker);
|
||||
};
|
||||
|
||||
Segment segments[while(!std::mem::eof())] @ 0x00 [[hex::visualize("image", this)]];
|
||||
Segment segments[while(!std::mem::eof())] @ 0x00 [[hex::visualize("image", this)]];
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#pragma MIME application/x-ms-shortcut
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
import std.core;
|
||||
import type.guid;
|
||||
import type.size;
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma description Lua 5.4 bytecode
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
|
||||
namespace impl {
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma MIME application/x-mach-binary
|
||||
|
||||
#include <type/size.pat>
|
||||
import type.size;
|
||||
|
||||
enum Magic : u32 {
|
||||
_32BitMagic = 0xFEEDFACE,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma description Mechanized Assault and Exploration v1.04 (strategy game) save file format
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
import std.sys;
|
||||
import std.mem;
|
||||
|
||||
#pragma array_limit 12544
|
||||
#pragma pattern_limit 2000000
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma description MIDI header, event fields provided
|
||||
|
||||
#include <std/core.pat>
|
||||
import std.core;
|
||||
|
||||
#pragma MIME audio/midi
|
||||
#pragma endian big
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#pragma MIME application/x-dmp
|
||||
|
||||
#include <type/time.pat>
|
||||
#include <type/types/win32.pat>
|
||||
#include <type/size.pat>
|
||||
import type.time;
|
||||
import type.types.win32;
|
||||
import type.size;
|
||||
|
||||
using RVA = ULONG32;
|
||||
using RVA64 = ULONG64;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#pragma MIME video/mp4
|
||||
#pragma MIME application/mp4
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
import std.io;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
|
||||
fn to_string(auto var) {
|
||||
return str(var);
|
||||
@@ -18,15 +18,23 @@ fn format_string(auto string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
fn format_fixed32(auto fp32) {
|
||||
return fp32.integer + fp32.fraction / 65536.0;
|
||||
};
|
||||
|
||||
fn format_fixed16(auto fp16) {
|
||||
return fp16.integer + fp16.fraction / 256.0;
|
||||
};
|
||||
|
||||
struct FixedPoint16 {
|
||||
u8 integer;
|
||||
u8 fraction;
|
||||
};
|
||||
} [[format("format_fixed16")]];
|
||||
|
||||
struct FixedPoint32 {
|
||||
u16 integer;
|
||||
u16 fraction;
|
||||
};
|
||||
} [[format("format_fixed32")]];
|
||||
|
||||
struct string {
|
||||
char value[std::mem::find_sequence_in_range(0, $, std::mem::size(), 0x00) - $];
|
||||
@@ -122,8 +130,8 @@ struct TrackHeaderBox : FullBox {
|
||||
s16 volume;
|
||||
u16 reserved_3;
|
||||
s32 matrix[9];
|
||||
u32 width;
|
||||
u32 height;
|
||||
FixedPoint32 width;
|
||||
FixedPoint32 height;
|
||||
};
|
||||
|
||||
struct DataEntryBox : FullBox {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
import std.sys;
|
||||
import std.io;
|
||||
|
||||
struct ApplicationTitle {
|
||||
char name[0x200];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Minecraft NBT format
|
||||
|
||||
#include <std/sys.pat>
|
||||
import std.sys;
|
||||
|
||||
#pragma endian big
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma description NE header and Standard NE fields
|
||||
|
||||
#include <std/mem.pat>
|
||||
import std.mem;
|
||||
|
||||
struct DOSHeader {
|
||||
char signature[2];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma author gmestanley
|
||||
#pragma description .nes file format
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
import std.mem;
|
||||
import std.string;
|
||||
|
||||
bitfield iNES07Flags {
|
||||
mirroringIsVertical : 1;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user