mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-31 13:25:58 -05:00
Compare commits
9 Commits
ImHex-v1.2
...
ImHex-v1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0128ea87db | ||
|
|
fe231436d9 | ||
|
|
7a9ac44577 | ||
|
|
74e9d8f2e7 | ||
|
|
2f39a62d85 | ||
|
|
e21063d58b | ||
|
|
8f1a6bdd75 | ||
|
|
b9af43e08b | ||
|
|
2ffa4e0161 |
119
README.md
119
README.md
@@ -22,75 +22,78 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
||||
|
||||
| Name | MIME | Path | Description |
|
||||
|------|------|------|-------------|
|
||||
| BMP | `image/bmp` | [`patterns/bmp.hexpat`](patterns/bmp.hexpat) | OS2/Windows Bitmap files |
|
||||
| ELF | `application/x-executable` | [`patterns/elf.hexpat`](patterns/elf.hexpat) | ELF header in elf binaries |
|
||||
| PE | `application/x-dosexec` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
|
||||
| NE | | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
|
||||
| Intel HEX | | [`patterns/intel_hex.hexpat`](patterns/intel_hex.hexpat) | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
|
||||
| MIDI | `audio/midi` | [`patterns/midi.hexpat`](patterns/midi.hexpat) | MIDI header, event fields provided |
|
||||
| WAV | `audio/wav` | [`patterns/wav.hexpat`](patterns/wav.hexpat) | RIFF header, WAVE header, PCM header |
|
||||
| ZIP | `application/zip` | [`patterns/zip.hexpat`](patterns/zip.hexpat) | End of Central Directory Header, Central Directory File Headers |
|
||||
| PCAP | `application/vnd.tcpdump.pcap` | [`patterns/pcap.hexpat`](patterns/pcap.hexpat) | pcap header and packets |
|
||||
| SPIRV | | [`patterns/spirv.hexpat`](patterns/spirv.hexpat) | SPIR-V header and instructions |
|
||||
| AFE2 | | [`patterns/afe2.hexpat`](patterns/afe2.hexpat) | Nintendo Switch Atmosphère CFW Fatal Error log |
|
||||
| AR | `application/x-archive` | [`patterns/ar.hexpat`](patterns/ar.hexpat) | Static library archive files |
|
||||
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
|
||||
| NRO | | [`patterns/nro.hexpat`](patterns/nro.hexpat) | Nintendo Switch NRO files |
|
||||
| PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO |
|
||||
| Java Class | `application/x-java-applet` | [`patterns/java_class.hexpat`](patterns/java_class.hexpat) | Java Class files |
|
||||
| ARM VTOR | | [`patterns/arm_cm_vtor.hexpat`](patterns/arm_cm_vtor.hexpat) | ARM Cortex M Vector Table Layout |
|
||||
| ICO | | [`patterns/ico.hexpat`](patterns/ico.hexpat) | Icon (.ico) or Cursor (.cur) files |
|
||||
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
|
||||
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
|
||||
| DDS | `image/vnd-ms.dds` | [`patterns/dds.hexpat`](patterns/dds.hexpat) | DirectDraw Surface |
|
||||
| TGA | `image/tga` | [`patterns/tga.hexpat`](patterns/tga.hexpat) | Truevision TGA/TARGA image |
|
||||
| ISO | | [`patterns/iso.hexpat`](patterns/iso.hexpat) | ISO 9660 file system |
|
||||
| VDF | | [`patterns/vdf.hexpat`](patterns/vdf.hexpat) | Binary Value Data Format (.vdf) files |
|
||||
| IP | | [`patterns/ip.hexpat`](patterns/ip.hexpat) | Ethernet II Frames (IP Packets) |
|
||||
| UF2 | | [`patterns/uf2.hexpat`](patterns/uf2.hexpat) | [USB Flashing Format](https://github.com/microsoft/uf2) |
|
||||
| File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System |
|
||||
| Bencode | `application/x-bittorrent` | [`patterns/bencode.hexpat`](patterns/bencode.hexpat) | Bencode encoding, used by Torrent files |
|
||||
| Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding |
|
||||
| OGG | `audio/ogg` | [`patterns/ogg.hexpat`](patterns/ogg.hexpat) | OGG Audio format |
|
||||
| STL | `model/stl` | [`patterns/stl.hexpat`](patterns/stl.hexpat) | STL 3D Model format |
|
||||
| VHDX | | [`patterns/vhdx.hexpat`](patterns/vhdx.hexpat) | Microsoft Hyper-V Virtual Hard Disk format |
|
||||
| NTAG | | [`patterns/ntag.hexpat`](patterns/ntag.hexpat) | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC |
|
||||
| Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format |
|
||||
| Xilinx BIT | | [`patterns/xilinx_bit.hexpat`](patterns/xilinx_bit.hexpat) | Xilinx FPGA Bitstreams |
|
||||
| FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format |
|
||||
| BMP | `image/bmp` | [`patterns/bmp.hexpat`](patterns/bmp.hexpat) | OS2/Windows Bitmap files |
|
||||
| BSON | `application/bson` | [`patterns/bson.hexpat`](patterns/bson.hexpat) | BSON (Binary JSON) format |
|
||||
| msgpack | `application/x-msgpack` | [`patterns/msgpack.hexpat`](patterns/msgpack.hexpat) | MessagePack binary serialization format |
|
||||
| MiniDump | `application/x-dmp` | [`patterns/minidump.hexpat`](patterns/minidump.hexpat) | Windows MiniDump files |
|
||||
| ID3 | `audio/mpeg` | [`patterns/id3.hexpat`](patterns/id3.hexpat) | ID3 tags in MP3 files |
|
||||
| TAR | `application/x-tar` | [`patterns/tar.hexpat`](patterns/tar.hexpat) | Tar file format |
|
||||
| CPIO | `application/x-cpio` | [`patterns/cpio.hexpat`](patterns/cpio.hexpat) | Old Binary CPIO Format |
|
||||
| FDT | | [`patterns/fdt.hexpat`](patterns/fdt.hexpat) | Flat Linux Device Tree blob |
|
||||
| StuffItV5 | `application/x-stuffit` | [`patterns/sit5.hexpat`](patterns/sit5.hexpat) | StuffIt V5 archive |
|
||||
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
|
||||
| PCX | `application/x-pcx` | [`patterns/pcx.hexpat`](patterns/pcx.hexpat) | PCX Image format |
|
||||
| GZIP | `application/gzip` | [`patterns/gzip.hexpat`](patterns/gzip.hexpat) | GZip compressed data format |
|
||||
| PFS0 | | [`patterns/pfs0.hexpat`](patterns/pfs0.hexpat) | Nintendo Switch PFS0 archive (NSP files) |
|
||||
| XCI | | [`patterns/xci.hexpat`](patterns/xci.hexpat) | Nintendo Switch XCI cardridge ROM |
|
||||
| WAD | | [`patterns/wad.hexpat`](patterns/wad.hexpat) | DOOM WAD Archive |
|
||||
| GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files |
|
||||
| ZSTD | `application/zstd` | [`patterns/zstd.hexpat`](patterns/zstd.hexpat) | Zstandard compressed data format |
|
||||
| COFF | `application/x-coff` | [`patterns/coff.hexpat`](patterns/coff.hexpat) | Common Object File Format (COFF) executable |
|
||||
| Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable |
|
||||
| CHM | | [`patterns/chm.hexpat`](patterns/chm.hexpat) | Windows HtmlHelp Data (ITSF / CHM) |
|
||||
| DMG | | [`patterns/dmg.hexpat`](patterns/dmg.hexpat) | Apple Disk Image Trailer (DMG) |
|
||||
| XBEH | `audio/x-xbox-executable` | [`patterns/xbeh.hexpat`](patterns/xbeh.hexpat) | Xbox executable |
|
||||
| QBCL | | [`patterns/qbcl.hexpat`](patterns/qbcl.hexpat) | Qubicle voxel scene project file |
|
||||
| BSP | | [`patterns/bsp_goldsrc.hexpat`](patterns/bsp_goldsrc.hexpat) | GoldSrc engine maps format (used in Half-Life 1) |
|
||||
| CCHVA | | [`patterns/cchva.hexpat`](patterns/cchva.hexpat) | Command and Conquer Voxel Animation |
|
||||
| CCVXL | | [`patterns/ccvxl.hexpat`](patterns/ccvxl.hexpat) | Command and Conquer Voxel Model |
|
||||
| CCPAL | | [`patterns/ccpal.hexpat`](patterns/ccpal.hexpat) | Command and Conquer Voxel Palette |
|
||||
| PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format |
|
||||
| CHM | | [`patterns/chm.hexpat`](patterns/chm.hexpat) | Windows HtmlHelp Data (ITSF / CHM) |
|
||||
| COFF | `application/x-coff` | [`patterns/coff.hexpat`](patterns/coff.hexpat) | Common Object File Format (COFF) executable |
|
||||
| CPIO | `application/x-cpio` | [`patterns/cpio.hexpat`](patterns/cpio.hexpat) | Old Binary CPIO Format |
|
||||
| CrashLvl | | [`patterns/Crashlvl.hexpat`](patterns/Crashlvl.hexpat) | Crash Bandicoot - Back in Time (fan game) User created flashback tapes level format |
|
||||
| DDS | `image/vnd-ms.dds` | [`patterns/dds.hexpat`](patterns/dds.hexpat) | DirectDraw Surface |
|
||||
| DEX | | [`patterns/dex.hexpat`](patterns/dex.hexpat) | Dalvik EXecutable Format |
|
||||
| DMG | | [`patterns/dmg.hexpat`](patterns/dmg.hexpat) | Apple Disk Image Trailer (DMG) |
|
||||
| DS_Store | `application/octet-stream` | [`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 |
|
||||
| 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 |
|
||||
| FDT | | [`patterns/fdt.hexpat`](patterns/fdt.hexpat) | Flat Linux Device Tree blob |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| ICO | | [`patterns/ico.hexpat`](patterns/ico.hexpat) | Icon (.ico) or Cursor (.cur) files |
|
||||
| ID3 | `audio/mpeg` | [`patterns/id3.hexpat`](patterns/id3.hexpat) | ID3 tags in MP3 files |
|
||||
| Intel HEX | | [`patterns/intel_hex.hexpat`](patterns/intel_hex.hexpat) | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
|
||||
| IP | | [`patterns/ip.hexpat`](patterns/ip.hexpat) | Ethernet II Frames (IP Packets) |
|
||||
| ISO | | [`patterns/iso.hexpat`](patterns/iso.hexpat) | ISO 9660 file system |
|
||||
| Java Class | `application/x-java-applet` | [`patterns/java_class.hexpat`](patterns/java_class.hexpat) | Java Class files |
|
||||
| JPEG | `image/jpeg` | [`patterns/jpeg.hexpat`](patterns/jpeg.hexpat) | JPEG Image Format |
|
||||
| Lua 5.4 | | [`patterns/lua54.hexpat`](patterns/lua54.hexpat) | Lua 5.4 bytecode |
|
||||
| DEX | | [`patterns/dex.hexpat`](patterns/dex.hexpat) | Dalvik EXecutable Format |
|
||||
| DS_Store | `application/octet-stream` | [`patterns/dsstore.hexpat`](patterns/dsstore.hexpat) | .DS_Store file format |
|
||||
| Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable |
|
||||
| MIDI | `audio/midi` | [`patterns/midi.hexpat`](patterns/midi.hexpat) | MIDI header, event fields provided |
|
||||
| MiniDump | `application/x-dmp` | [`patterns/minidump.hexpat`](patterns/minidump.hexpat) | Windows MiniDump files |
|
||||
| msgpack | `application/x-msgpack` | [`patterns/msgpack.hexpat`](patterns/msgpack.hexpat) | MessagePack binary serialization format |
|
||||
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
|
||||
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
|
||||
| NE | | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
|
||||
| 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 |
|
||||
| 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` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
|
||||
| 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 |
|
||||
| QBCL | | [`patterns/qbcl.hexpat`](patterns/qbcl.hexpat) | Qubicle voxel scene project file |
|
||||
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
|
||||
| Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format |
|
||||
| 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 |
|
||||
| TAR | `application/x-tar` | [`patterns/tar.hexpat`](patterns/tar.hexpat) | Tar file format |
|
||||
| TGA | `image/tga` | [`patterns/tga.hexpat`](patterns/tga.hexpat) | Truevision TGA/TARGA image |
|
||||
| UEFI | | [`patterns/uefi.hexpat`](patterns/uefi.hexpat)` | UEFI structs for parsing efivars |
|
||||
| EVTX | | [`patterns/evtx.hexpat`](patterns/evtx.hexpat) | MS Windows Vista Event Log |
|
||||
| BSP | | [`patterns/bsp_goldsrc.hexpat`](patterns/bsp_goldsrc.hexpat) | GoldSrc engine maps format (used in Half-Life 1) |
|
||||
| UF2 | | [`patterns/uf2.hexpat`](patterns/uf2.hexpat) | [USB Flashing Format](https://github.com/microsoft/uf2) |
|
||||
| VDF | | [`patterns/vdf.hexpat`](patterns/vdf.hexpat) | Binary Value Data Format (.vdf) files |
|
||||
| VHDX | | [`patterns/vhdx.hexpat`](patterns/vhdx.hexpat) | Microsoft Hyper-V Virtual Hard Disk format |
|
||||
| WAV | `audio/x-wav` | [`patterns/wav.hexpat`](patterns/wav.hexpat) | RIFF header, WAVE header, PCM header |
|
||||
| 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 |
|
||||
| Xilinx BIT | | [`patterns/xilinx_bit.hexpat`](patterns/xilinx_bit.hexpat) | Xilinx FPGA Bitstreams |
|
||||
| ZIP | `application/zip` | [`patterns/zip.hexpat`](patterns/zip.hexpat) | End of Central Directory Header, Central Directory File Headers |
|
||||
| ZSTD | `application/zstd` | [`patterns/zstd.hexpat`](patterns/zstd.hexpat) | Zstandard compressed data format |
|
||||
|
||||
### Scripts
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ namespace std::file {
|
||||
/**
|
||||
Writes the content of a string into a file
|
||||
@param handle The file handle to write to
|
||||
@param data String to write to the file
|
||||
@param data String or Pattern to write to the file
|
||||
*/
|
||||
fn write(Handle handle, str data) {
|
||||
fn write(Handle handle, auto data) {
|
||||
builtin::std::file::write(handle, data);
|
||||
};
|
||||
|
||||
|
||||
@@ -178,7 +178,6 @@ namespace std::math {
|
||||
/**
|
||||
Calculates the natural logarithm of `value`.
|
||||
@param value Value
|
||||
@param base Base
|
||||
@return Logarithm of `value` with base `e`
|
||||
*/
|
||||
fn ln(auto value) { return builtin::std::math::ln(value); };
|
||||
@@ -198,6 +197,13 @@ namespace std::math {
|
||||
*/
|
||||
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
|
||||
|
||||
73
patterns/Crashlvl.hexpat
Normal file
73
patterns/Crashlvl.hexpat
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <type/magic.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/array.pat>
|
||||
|
||||
// Crash Bandicoot - Back in Time (fan game) user created tapes
|
||||
// author AdventureT
|
||||
|
||||
struct Header {
|
||||
type::Magic<"CRASHLVL"> magic;
|
||||
u8 version;
|
||||
std::string::SizedString<u8> levelName;
|
||||
std::string::SizedString<u8> author;
|
||||
};
|
||||
|
||||
enum Music : u32 {
|
||||
None,
|
||||
BonusBGM,
|
||||
CrashCreatorBGM,
|
||||
MainMenuBGM,
|
||||
WarpRoomBGM,
|
||||
Level01BGM,
|
||||
Level02BGM,
|
||||
Level03BGM,
|
||||
Level04BGM,
|
||||
Level05BGM,
|
||||
SewerBGM,
|
||||
EgyptBGM,
|
||||
NBrioBGM
|
||||
};
|
||||
|
||||
enum Type : u32 {
|
||||
Unset,
|
||||
Flashback,
|
||||
Trial
|
||||
};
|
||||
|
||||
enum Time : u32 {
|
||||
Night,
|
||||
Day,
|
||||
Storm,
|
||||
Dawn
|
||||
};
|
||||
|
||||
enum Terrain : u32 {
|
||||
None,
|
||||
Machines,
|
||||
Trees,
|
||||
Waterfall,
|
||||
Snow,
|
||||
Fortress,
|
||||
};
|
||||
|
||||
struct Options {
|
||||
Type type;
|
||||
Time time;
|
||||
Terrain terrain;
|
||||
Music music;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
std::string::SizedString<u8> objName;
|
||||
u32 x;
|
||||
u32 y;
|
||||
};
|
||||
|
||||
struct Objects{
|
||||
u32 objCount;
|
||||
std::Array<Object, objCount> objArray;
|
||||
};
|
||||
|
||||
Header header @ 0x0;
|
||||
Options options @ $;
|
||||
Objects objects @ $;
|
||||
337
patterns/gb.hexpat
Normal file
337
patterns/gb.hexpat
Normal file
@@ -0,0 +1,337 @@
|
||||
#include <type/size.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
#pragma MIME application/x-gameboy-rom
|
||||
|
||||
namespace format {
|
||||
|
||||
fn rom_type(u8 romType) {
|
||||
u32 romSize = 32768 * (1 << romType);
|
||||
u16 romBanks = 2 * (1 << romType);
|
||||
if(romType == 0x52) {
|
||||
romSize = 1153434;
|
||||
romBanks = 72;
|
||||
}
|
||||
if(romType == 0x53) {
|
||||
romSize = 1258291;
|
||||
romBanks = 80;
|
||||
}
|
||||
return std::format("size: {}, banks: {}", type::impl::size_formatter(romSize), romBanks);
|
||||
};
|
||||
|
||||
fn ram_type(u8 ramType) {
|
||||
u16 ramSize;
|
||||
u16 ramBanks;
|
||||
if(ramType == 2) {
|
||||
ramSize = 8192;
|
||||
ramBanks = 1;
|
||||
}
|
||||
if(ramType == 3) {
|
||||
ramSize = 32768;
|
||||
ramBanks = 4;
|
||||
}
|
||||
if(ramType == 4) {
|
||||
ramSize = 131072;
|
||||
ramBanks = 16;
|
||||
}
|
||||
if(ramType == 5) {
|
||||
ramSize = 65536;
|
||||
ramBanks = 8;
|
||||
}
|
||||
return std::format("size: {}, banks: {}", type::impl::size_formatter(ramSize), ramBanks);
|
||||
};
|
||||
|
||||
fn rom_features(u8 type) {
|
||||
str result = "( ";
|
||||
match(type) {
|
||||
(0x00): result += "no_mbc ";
|
||||
(0x01): result += "mbc1 ";
|
||||
(0x02): result += "mbc1 | ram ";
|
||||
(0x03): result += "mbc1 | ram | battery ";
|
||||
(0x05): result += "mbc2 ";
|
||||
(0x06): result += "mbc2 | battery ";
|
||||
(0x08): result += "no_mbc | ram ";
|
||||
(0x09): result += "no_mbc | ram | battery ";
|
||||
(0x0B): result += "mmm01 ";
|
||||
(0x0C): result += "mmm01 | ram ";
|
||||
(0x0D): result += "mmm01 | ram | battery ";
|
||||
(0x0F): result += "mbc3 | timer | battery ";
|
||||
(0x10): result += "mbc3 | timer | ram | battery ";
|
||||
(0x11): result += "mbc3 ";
|
||||
(0x12): result += "mbc3 | ram ";
|
||||
(0x13): result += "mbc3 | ram | battery ";
|
||||
(0x19): result += "mbc5 ";
|
||||
(0x1A): result += "mbc5 | ram ";
|
||||
(0x1B): result += "mbc5 | ram | battery ";
|
||||
(0x1C): result += "mbc5 | rumble ";
|
||||
(0x1D): result += "mbc5 | rumble | ram ";
|
||||
(0x1E): result += "mbc5 | rumble | ram | battery ";
|
||||
(0x20): result += "mbc6 ";
|
||||
(0x22): result += "mbc7 | sensor | rumble ";
|
||||
(0xFC): result += "camera ";
|
||||
(0xFD): result += "tama5 ";
|
||||
(0xFE): result += "huc3 ";
|
||||
(0xFF): result += "huc1 | ram | battery ";
|
||||
}
|
||||
return result + ")";
|
||||
};
|
||||
|
||||
fn licensee_code(u8 code) {
|
||||
match(code) {
|
||||
(0x00): return "None";
|
||||
(0x01 | 0x31): return "Nintendo";
|
||||
(0x08 | 0x38): return "Capcom";
|
||||
(0x09): return "Hot-B";
|
||||
(0x0A | 0xE0): return "Jaleco";
|
||||
(0x0B): return "Coconuts Japan";
|
||||
(0x0C | 0x6E): return "Elite Systems";
|
||||
(0x13 | 0x69): return "EA (Electronic Arts)";
|
||||
(0x18): return "Hudsonsoft";
|
||||
(0x19): return "ITC Entertainment";
|
||||
(0x1A): return "Yanoman";
|
||||
(0x1D): return "Japan Clary";
|
||||
(0x1F | 0x4A | 0x61): return "Virgin Interactive";
|
||||
(0x24): return "PCM Complete";
|
||||
(0x25): return "San-X";
|
||||
(0x28): return "Kotobuki Systems";
|
||||
(0x29): return "Seta";
|
||||
(0x30 | 0x70): return "Infogrames";
|
||||
(0x32 | 0xA2 | 0xB2 | 0xC4): return "Bandai";
|
||||
(0x33): return "See new licensee";
|
||||
(0x34 | 0xA4): return "Konami";
|
||||
(0x35): return "HectorSoft";
|
||||
(0x39 | 0x9D): return "Banpresto";
|
||||
(0x3C): return ".Entertainment i";
|
||||
(0x3E): return "Gremlin";
|
||||
(0x41): return "Ubisoft";
|
||||
(0x42 | 0xEB): return "Atlus";
|
||||
(0x44 | 0x4D): return "Malibu";
|
||||
(0x46 | 0xCF): return "Angel";
|
||||
(0x47): return "Spectrum Holoby";
|
||||
(0x49): return "Irem";
|
||||
(0x50): return "Absolute";
|
||||
(0x51 | 0xB0): return "Acclaim";
|
||||
(0x52): return "Activision";
|
||||
(0x53): return "American Sammy";
|
||||
(0x54): return "GameTek";
|
||||
(0x55): return "Park Place";
|
||||
(0x56 | 0xDB | 0xFF): return "LJN";
|
||||
(0x57): return "Matchbox";
|
||||
(0x59): return "Milton Bradley";
|
||||
(0x5A): return "Mindscape";
|
||||
(0x5B): return "Romstar";
|
||||
(0x5C | 0xD6): return "Naxat Soft";
|
||||
(0x5D): return "Tradewest";
|
||||
(0x60): return "Titus";
|
||||
(0x67): return "Ocean Interactive";
|
||||
(0x6F): return "Electro Brain";
|
||||
(0x71): return "Interplay";
|
||||
(0x72 | 0xAA): return "Broderbund";
|
||||
(0x73): return "Sculptered Soft";
|
||||
(0x75): return "The Sales Curve";
|
||||
(0x78): return "t.hq";
|
||||
(0x79): return "Accolade";
|
||||
(0x7A): return "Triffix Entertainment";
|
||||
(0x7C): return "Microprose";
|
||||
(0x7F | 0xC2): return "Kemco";
|
||||
(0x80): return "Misawa Entertainment";
|
||||
(0x83): return "Lozc";
|
||||
(0x86 | 0xC4): return "Tokuma Shoten Intermedia";
|
||||
(0x8B): return "Bullet-Proof Software";
|
||||
(0x8C): return "Vic Tokai";
|
||||
(0x8E): return "Ape";
|
||||
(0x8F): return "I'Max";
|
||||
(0x91): return "Chunksoft Co.";
|
||||
(0x92): return "Video System";
|
||||
(0x93): return "Tsubaraya Productions Co.";
|
||||
(0x95): return "Varie Corporation";
|
||||
(0x96): return "Yonezawa/S’Pal";
|
||||
(0x97): return "Kaneko";
|
||||
(0x99): return "Arc";
|
||||
(0x9A): return "Nihon Bussan";
|
||||
(0x9B): return "Tecmo";
|
||||
(0x9C): return "Imagineer";
|
||||
(0x9F): return "Nova";
|
||||
(0xA1): return "Hori Electric";
|
||||
(0xA6): return "Kawada";
|
||||
(0xA7): return "Takara";
|
||||
(0xA9): return "Technos Japan";
|
||||
(0xAC): return "Toei Animation";
|
||||
(0xAD): return "Toho";
|
||||
(0xAF): return "Namco";
|
||||
(0xB1): return "ASCII or Nexsoft";
|
||||
(0xB4): return "Square Enix";
|
||||
(0xB6): return "HAL Laboratory";
|
||||
(0xB7): return "SNK";
|
||||
(0xB9 | 0xCE): return "Pony Canyon";
|
||||
(0xBA): return "Culture Brain";
|
||||
(0xBB): return "Sunsoft";
|
||||
(0xBD): return "Sony Imagesoft";
|
||||
(0xBF): return "Sammy";
|
||||
(0xC0 | 0xD0): return "Taito";
|
||||
(0xC3): return "Squaresoft";
|
||||
(0xC5): return "Data East";
|
||||
(0xC6): return "Tonkinhouse";
|
||||
(0xC8): return "Koei";
|
||||
(0xC9): return "UFL";
|
||||
(0xCA): return "Ultra";
|
||||
(0xCB): return "Vap";
|
||||
(0xCC): return "Use Corporation";
|
||||
(0xCD): return "Meldac";
|
||||
(0xD1): return "Sofel";
|
||||
(0xD2): return "Quest";
|
||||
(0xD3): return "Sigma Enterprises";
|
||||
(0xD4): return "ASK Kodansha Co.";
|
||||
(0xD7): return "Copya System";
|
||||
(0xDA): return "Tomy";
|
||||
(0xDD): return "NCS";
|
||||
(0xDE): return "Human";
|
||||
(0xDF): return "Altron";
|
||||
(0xE1): return "Towa Chiki";
|
||||
(0xE2): return "Yutaka";
|
||||
(0xE3): return "Varie";
|
||||
(0xE5): return "Epoch";
|
||||
(0xE7): return "Athena";
|
||||
(0xE8): return "Asmik";
|
||||
(0xE9): return "Natsume";
|
||||
(0xEA): return "King Records";
|
||||
(0xEE): return "IGS";
|
||||
(0xF0): return "A Wave";
|
||||
(0xF3): return "Extreme Entertainment";
|
||||
}
|
||||
return "Unknown Licensee";
|
||||
};
|
||||
|
||||
fn new_licensee_code(str a) {
|
||||
if(a[0] == 0 && a[1] == 0) return "See old licensee";
|
||||
match(a) {
|
||||
("00"): return "None";
|
||||
("01"): return "Nintendo R&D1";
|
||||
("08"): return "Capcom";
|
||||
("13"): return "Electronic Arts";
|
||||
("18"): return "Hudson Soft";
|
||||
("19"): return "b-ai";
|
||||
("20"): return "kss";
|
||||
("22"): return "pow";
|
||||
("24"): return "PCM Complete";
|
||||
("25"): return "san-x";
|
||||
("28"): return "Kemco Japan";
|
||||
("29"): return "seta";
|
||||
("30"): return "Viacom";
|
||||
("31"): return "Nintendo";
|
||||
("32"): return "Bandai";
|
||||
("33"): return "Ocean/Acclaim";
|
||||
("34"): return "Konami";
|
||||
("35"): return "Hector";
|
||||
("37"): return "Taito";
|
||||
("38"): return "Hudson";
|
||||
("39"): return "Banpresto";
|
||||
("41"): return "Ubi Soft";
|
||||
("42"): return "Atlus";
|
||||
("44"): return "Malibu";
|
||||
("46"): return "angel";
|
||||
("47"): return "Bullet-Proof";
|
||||
("49"): return "irem";
|
||||
("50"): return "Absolute";
|
||||
("51"): return "Acclaim";
|
||||
("52"): return "Activision";
|
||||
("53"): return "American sammy";
|
||||
("54"): return "Konami";
|
||||
("55"): return "Hi tech entertainment";
|
||||
("56"): return "LJN";
|
||||
("57"): return "Matchbox";
|
||||
("58"): return "Mattel";
|
||||
("59"): return "Milton Bradley";
|
||||
("60"): return "Titus";
|
||||
("61"): return "Virgin";
|
||||
("64"): return "LucasArts";
|
||||
("67"): return "Ocean";
|
||||
("69"): return "Electronic Arts";
|
||||
("70"): return "Infogrames";
|
||||
("71"): return "Interplay";
|
||||
("72"): return "Broderbund";
|
||||
("73"): return "sculptured";
|
||||
("75"): return "sci";
|
||||
("78"): return "THQ";
|
||||
("79"): return "Accolade";
|
||||
("80"): return "misawa";
|
||||
("83"): return "lozc";
|
||||
("86"): return "Tokuma Shoten Intermedia";
|
||||
("87"): return "Tsukuda Original";
|
||||
("91"): return "Chunksoft";
|
||||
("92"): return "Video system";
|
||||
("93"): return "Ocean/Acclaim";
|
||||
("95"): return "Varie";
|
||||
("96"): return "Yonezawa/s’pal";
|
||||
("97"): return "Kaneko";
|
||||
("99"): return "Pack in soft";
|
||||
("A4"): return "Konami (Yu-Gi-Oh!)";
|
||||
}
|
||||
return "Unknown";
|
||||
};
|
||||
}
|
||||
|
||||
bitfield pixel_packed {
|
||||
p1 : 1;
|
||||
p2 : 1;
|
||||
p3 : 1;
|
||||
p4 : 1;
|
||||
p5 : 1;
|
||||
p6 : 1;
|
||||
p7 : 1;
|
||||
p8 : 1;
|
||||
};
|
||||
|
||||
enum CGB : u8 {
|
||||
NO_CGB = 0x00 ... 0x7F,
|
||||
BACKWARDS_COMPATIBLE = 0x80,
|
||||
CGB_ONLY = 0xC0
|
||||
};
|
||||
|
||||
|
||||
struct Logo {
|
||||
pixel_packed rawData[0x30];
|
||||
};
|
||||
|
||||
struct JumpVectors {
|
||||
u8 rst1[8] [[comment("rst $1")]];
|
||||
u8 rst2[8] [[comment("rst $2")]];
|
||||
u8 rst3[8] [[comment("rst $3")]];
|
||||
u8 rst4[8] [[comment("rst $4")]];
|
||||
u8 rst5[8] [[comment("rst $5")]];;
|
||||
u8 rst6[8] [[comment("rst $6")]];
|
||||
u8 rst7[8] [[comment("rst $7")]];
|
||||
u8 rst8[8] [[comment("rst $8")]];
|
||||
u8 int1[8] [[comment("vblank")]];
|
||||
u8 int2[8] [[comment("lcd stat")]];
|
||||
u8 int3[8] [[comment("timer")]];
|
||||
u8 int4[8] [[comment("serial")]];
|
||||
u8 int5[8] [[comment("joypad")]];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
u32 jmpInstruction;
|
||||
Logo logo;
|
||||
char title[0xF];
|
||||
CGB cgb;
|
||||
char newLicenseeCode[2] [[format("format::new_licensee_code")]];
|
||||
bool sgbFlag;
|
||||
u8 type [[format("format::rom_features")]];
|
||||
u8 romType [[format("format::rom_type")]];
|
||||
u8 ramType [[format("format::ram_type")]];
|
||||
bool japanOnly;
|
||||
u8 licenseeCode [[format("format::licensee_code")]];
|
||||
u8 version;
|
||||
u8 checksum [[comment("Checksum for: $134-$14C")]];
|
||||
u16 gloalChecksum [[comment("Checksum for entire range")]];
|
||||
};
|
||||
|
||||
struct Cartrige {
|
||||
JumpVectors jumpVectors [[comment("Instructions called on interupts or rst instructions")]];
|
||||
padding[0x100 - sizeof(JumpVectors)];
|
||||
Header header;
|
||||
};
|
||||
|
||||
|
||||
Cartrige cart @ 0x00;
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma endian big
|
||||
#pragma MIME application/x-java-applet
|
||||
|
||||
#pragma pattern_limit 100000000
|
||||
#include <std/string.pat>
|
||||
#include <std/math.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/sys.pat>
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
// The Java documentations use the number of bytes instead of the number of bits for its type names
|
||||
using u1 = u8;
|
||||
using u2 = u16;
|
||||
using u4 = u32;
|
||||
@@ -15,24 +15,182 @@ using u4 = u32;
|
||||
using f4 = float;
|
||||
using f8 = double;
|
||||
|
||||
enum cp_tag : u8 {
|
||||
CONSTANT_Utf8 = 1,
|
||||
CONSTANT_Integer = 3,
|
||||
CONSTANT_Float = 4,
|
||||
CONSTANT_Long = 5,
|
||||
CONSTANT_Double = 6,
|
||||
CONSTANT_Class = 7,
|
||||
CONSTANT_String = 8,
|
||||
CONSTANT_Fieldref = 9,
|
||||
CONSTANT_Methodref = 10,
|
||||
CONSTANT_InterfaceMethodref = 11,
|
||||
CONSTANT_NameAndType = 12,
|
||||
CONSTANT_MethodHandle = 15,
|
||||
CONSTANT_MethodType = 16,
|
||||
CONSTANT_InvokeDynamic = 18,
|
||||
CONSTANT_Module = 19,
|
||||
CONSTANT_Package = 20
|
||||
};
|
||||
using cp_ref = u16 [[format("fmt::const_ref_top")]];
|
||||
|
||||
bool applyPadding = false;
|
||||
|
||||
struct cp_info {
|
||||
bool isTop = false;
|
||||
if(applyPadding) {
|
||||
isTop = true;
|
||||
applyPadding = false;
|
||||
}
|
||||
else {
|
||||
u1 tag;
|
||||
match(tag) {
|
||||
(1): { /* cp_utf8 */
|
||||
u2 length;
|
||||
char bytes[length];
|
||||
}
|
||||
(3): { /* cp_integer */
|
||||
u4 bytes;
|
||||
}
|
||||
(4): { /* cp_float */
|
||||
float bytes;
|
||||
}
|
||||
(5): { /* cp_long */
|
||||
u64 bytes;
|
||||
applyPadding = true;
|
||||
}
|
||||
(6): { /* cp_double */
|
||||
double bytes;
|
||||
applyPadding = true;
|
||||
}
|
||||
(7): { /* cp_class */
|
||||
cp_ref name_index;
|
||||
}
|
||||
(8): { /* cp_string */
|
||||
cp_ref string_index;
|
||||
}
|
||||
(9): { /* cp_fieldref */
|
||||
cp_ref class_index;
|
||||
cp_ref name_and_type_index;
|
||||
}
|
||||
(10): { /* cp_methodref */
|
||||
cp_ref class_index;
|
||||
cp_ref name_and_type_index;
|
||||
}
|
||||
(11): { /* cp_interface_methodref */
|
||||
cp_ref class_index;
|
||||
cp_ref name_and_type_index;
|
||||
}
|
||||
(12): { /* cp_name_and_type */
|
||||
cp_ref name_index;
|
||||
cp_ref descriptor_index;
|
||||
}
|
||||
(15): { /* cp_method_handle */
|
||||
u1 reference_kind;
|
||||
cp_ref reference_index;
|
||||
}
|
||||
(16): { /* cp_method_type */
|
||||
cp_ref descriptor_index;
|
||||
}
|
||||
(18): { /* cp_invoke_dynamic */
|
||||
u2 bootstrap_method_attr_index;
|
||||
cp_ref name_and_type_index;
|
||||
}
|
||||
(19): { /* cp_module */
|
||||
cp_ref name_index;
|
||||
}
|
||||
(20): { /* cp_package */
|
||||
cp_ref name_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
} [[format("fmt::const_name")]];
|
||||
|
||||
namespace fmt {
|
||||
fn const_name(auto tag) {
|
||||
if(tag.isTop) return "Top";
|
||||
match(tag.tag) {
|
||||
(1): return "Utf8";
|
||||
(3): return "Integer";
|
||||
(4): return "Float";
|
||||
(5): return "Long";
|
||||
(6): return "Double";
|
||||
(7): return "Class";
|
||||
(8): return "String";
|
||||
(9): return "Fieldref";
|
||||
(10): return "Methodref";
|
||||
(11): return "InterfaceMethodref";
|
||||
(12): return "NameAndType";
|
||||
(15): return "MethodHandle";
|
||||
(16): return "MethodType";
|
||||
(18): return "InvokeDynamic";
|
||||
(_): return "Unknown";
|
||||
}
|
||||
};
|
||||
|
||||
fn const_ref(u2 index) {
|
||||
cp_info info = file.constant_pool[index-1];
|
||||
match(info.tag) {
|
||||
(1): return info.bytes;
|
||||
(3): return std::format("{:d} [{:d}]", index, info.bytes);
|
||||
(4): return std::format("{:d} [{:f}]", index, info.bytes);
|
||||
(5): return std::format("{:d} [{:d}", index, info.bytes);
|
||||
(6): return std::format("{:d} [{:f}", index, info.bytes);
|
||||
(7): return std::format("{:d} [Class({})]", index, fmt::const_ref(info.name_index));
|
||||
(8): return std::format("{:d} [String({})]", index, fmt::const_ref(info.string_index));
|
||||
(9): return std::format("{:d} [Fieldref({}, {})]", index, fmt::const_ref(info.class_index), fmt::const_ref(info.name_and_type_index));
|
||||
(10): return std::format("{:d} [Methodref({}, {})]", index, fmt::const_ref(info.class_index), fmt::const_ref(info.name_and_type_index));
|
||||
(11): return std::format("{:d} [InterfaceMethodref({}, {})]", index, fmt::const_ref(info.class_index), fmt::const_ref(info.name_and_type_index));
|
||||
(12): return std::format("{:d} [NameAndType({}, {})]", index, fmt::const_ref(info.name_index), fmt::const_ref(info.descriptor_index));
|
||||
(15): return std::format("{:d} [MethodHandle({}, {})]", index, info.reference_kind, fmt::const_ref(info.reference_index));
|
||||
(16): return std::format("{:d} [MethodType({})]", index, fmt::const_ref(info.descriptor_index));
|
||||
(18): return std::format("{:d} [InvokeDynamic({}, {})]", index, info.bootstrap_method_attr_index, fmt::const_ref(info.name_and_type_index));
|
||||
(19): return std::format("{:d} [Module({})]", index, fmt::const_ref(info.name_index));
|
||||
(20): return std::format("{:d} [Package({})]", index, fmt::const_ref(info.name_index));
|
||||
(_): return std::format("{:d} [Unknown]", index);
|
||||
}
|
||||
};
|
||||
|
||||
fn const_ref_top(u2 index) {
|
||||
cp_info info = file.constant_pool[index-1];
|
||||
match(info.tag) {
|
||||
(1): return std::format("{:d} [{:s}]", index, info.bytes);
|
||||
(_): return fmt::const_ref(index);
|
||||
}
|
||||
};
|
||||
|
||||
fn attribute(auto info) {
|
||||
return file.constant_pool[info.attribute_name_index-1].bytes;
|
||||
};
|
||||
|
||||
fn verif_type_info(auto info) {
|
||||
match(info.tag) {
|
||||
(0): return "TOP";
|
||||
(1): return "INTEGER";
|
||||
(2): return "FLOAT";
|
||||
(3): return "DOUBLE";
|
||||
(4): return "LONG";
|
||||
(5): return "NULL";
|
||||
(6): return "UNINITIALIZED_THIS";
|
||||
(7): return std::format("Object({})", fmt::const_ref(info.cpool_index));
|
||||
(8): return std::format("Uninitialized({})", info.offset);
|
||||
(_): return "Unknown";
|
||||
}
|
||||
};
|
||||
|
||||
fn stack_map_frame(auto frame) {
|
||||
match(frame.frame_type) {
|
||||
(0 ... 63): return std::format("SAME [{}]", frame.frame_type);
|
||||
(64 ... 127): return std::format("SAME_LOCALS_1_STACK_ITEM [{}]", frame.frame_type);
|
||||
(247): return std::format("SAME_LOCALS_1_STACK_ITEM_EXTENDED [{}]", frame.frame_type);
|
||||
(248 ... 250): return std::format("CHOP [{}]", frame.frame_type);
|
||||
(251): return std::format("SAME_FRAME_EXTENDED [{}]", frame.frame_type);
|
||||
(252 ... 254): return std::format("APPEND [{}]", frame.frame_type);
|
||||
(255): return std::format("FULL_FRAME [{}]", frame.frame_type);
|
||||
}
|
||||
};
|
||||
|
||||
fn element_value(auto element) {
|
||||
match(element.tag) {
|
||||
('B'): return std::format("byte [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('C'): return std::format("char [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('D'): return std::format("double [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('F'): return std::format("float [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('I'): return std::format("int [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('J'): return std::format("long [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('S'): return std::format("short [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('Z'): return std::format("boolean [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('s'): return std::format("String [{:s}]", fmt::const_ref(element.const_value_index));
|
||||
('e'): return std::format("Enum [{:s}, {:s}]", fmt::const_ref(element.type_name_index), fmt::const_ref(element.const_name_index));
|
||||
('c'): return std::format("Class [{:s}]", fmt::const_ref(element.class_info_index));
|
||||
('@'): return std::format("Annotation [{:s}]", fmt::const_ref(element.annotation_value.type_index));
|
||||
('['): return std::format("Array [{:s}]", fmt::const_ref(element.num_values));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
enum major_version : u2 {
|
||||
JDK_1_1 = 45,
|
||||
@@ -55,143 +213,6 @@ enum major_version : u2 {
|
||||
Java_SE_17 = 61,
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Utf8
|
||||
struct CONSTANT_Utf8_info {
|
||||
u2 length;
|
||||
char bytes[length]; // u1 in documentation. Changed to char to improve readability
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Integer
|
||||
struct CONSTANT_Integer_info {
|
||||
u4 bytes;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Float
|
||||
struct CONSTANT_Float_info {
|
||||
f4 bytes; // u4 in documentation. Changed to f4 to improve readablilty
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Long
|
||||
struct CONSTANT_Long_info {
|
||||
u4 high_bytes;
|
||||
u4 low_bytes;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Double
|
||||
struct CONSTANT_Double_info {
|
||||
u4 high_bytes;
|
||||
u4 low_bytes;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Class
|
||||
struct CONSTANT_Class_info {
|
||||
u2 name_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_String
|
||||
struct CONSTANT_String_info {
|
||||
u2 string_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Fieldref
|
||||
struct CONSTANT_Fieldref_info {
|
||||
u2 class_index;
|
||||
u2 name_and_type_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Methodref
|
||||
struct CONSTANT_Methodref_info {
|
||||
u2 class_index;
|
||||
u2 name_and_type_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_InterfaceMethodref
|
||||
struct CONSTANT_InterfaceMethodref_info {
|
||||
u2 class_index;
|
||||
u2 name_and_type_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_NameAndType
|
||||
struct CONSTANT_NameAndType_info {
|
||||
u2 name_index;
|
||||
u2 descriptor_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_MethodHandle
|
||||
struct CONSTANT_MethodHandle_info {
|
||||
u1 reference_kind;
|
||||
u2 reference_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_MethodType
|
||||
struct CONSTANT_MethodType_info {
|
||||
u2 descriptor_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_InvokeDynamic
|
||||
struct CONSTANT_InvokeDynamic_info {
|
||||
u2 bootstrap_method_attr_index;
|
||||
u2 name_and_type_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Module
|
||||
struct CONSTANT_Module_info {
|
||||
u2 name_index;
|
||||
};
|
||||
|
||||
// Tag == CONSTANT_Package
|
||||
struct CONSTANT_Package_info {
|
||||
u2 name_index;
|
||||
};
|
||||
|
||||
// All 8-byte constants take up two entries in the constant_pool table of the class file
|
||||
u1 padding_entry_flag = 0;
|
||||
|
||||
struct cp_info {
|
||||
if (padding_entry_flag == 0) {
|
||||
cp_tag tag;
|
||||
|
||||
if (tag == cp_tag::CONSTANT_Utf8)
|
||||
CONSTANT_Utf8_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Integer)
|
||||
CONSTANT_Integer_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Float)
|
||||
CONSTANT_Float_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Long) {
|
||||
CONSTANT_Long_info info [[inline]];
|
||||
padding_entry_flag = 1;
|
||||
}
|
||||
else if (tag == cp_tag::CONSTANT_Double) {
|
||||
CONSTANT_Double_info info [[inline]];
|
||||
padding_entry_flag = 1;
|
||||
}
|
||||
else if (tag == cp_tag::CONSTANT_Class)
|
||||
CONSTANT_Class_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_String)
|
||||
CONSTANT_String_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Fieldref)
|
||||
CONSTANT_Fieldref_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Methodref)
|
||||
CONSTANT_Methodref_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_InterfaceMethodref)
|
||||
CONSTANT_InterfaceMethodref_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_NameAndType)
|
||||
CONSTANT_NameAndType_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_MethodHandle)
|
||||
CONSTANT_MethodHandle_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_MethodType)
|
||||
CONSTANT_MethodType_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_InvokeDynamic)
|
||||
CONSTANT_InvokeDynamic_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Module)
|
||||
CONSTANT_Module_info info [[inline]];
|
||||
else if (tag == cp_tag::CONSTANT_Package)
|
||||
CONSTANT_Package_info info [[inline]];
|
||||
} else {
|
||||
padding_entry_flag = 0;
|
||||
}
|
||||
};
|
||||
|
||||
bitfield access_flags_method {
|
||||
ACC_PUBLIC : 1; // 0x0001
|
||||
ACC_PRIVATE : 1; // 0x0002
|
||||
@@ -249,122 +270,529 @@ bitfield access_flags_class {
|
||||
ACC_MODULE : 1; // 0x8000
|
||||
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 16)]];
|
||||
|
||||
struct attribute_info {
|
||||
u2 attribute_name_info;
|
||||
bitfield access_flags_module {
|
||||
padding : 1; // 0x0001
|
||||
padding : 1; // 0x0002
|
||||
padding : 1; // 0x0004
|
||||
padding : 1; // 0x0008
|
||||
padding : 1; // 0x0010
|
||||
ACC_TRANSITIVE : 1; // 0x0020
|
||||
ACC_STATIC_PHASE : 1; // 0x0040
|
||||
padding : 1; // 0x0080
|
||||
padding : 1; // 0x0100
|
||||
padding : 1; // 0x0200
|
||||
padding : 1; // 0x0400
|
||||
padding : 1; // 0x0800
|
||||
ACC_SYNTHETIC : 1; // 0x1000
|
||||
padding : 1; // 0x2000
|
||||
padding : 1; // 0x4000
|
||||
ACC_MANDATED : 1; // 0x8000
|
||||
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 16)]];
|
||||
|
||||
using attribute_code;
|
||||
|
||||
u4 attribute_length;
|
||||
struct attribute_constant_value {
|
||||
cp_ref constantvalue_index;
|
||||
} [[static]];
|
||||
|
||||
u1 info[attribute_length];
|
||||
|
||||
struct verification_type_info {
|
||||
u1 tag;
|
||||
match(tag) {
|
||||
(0): { /* Top_variable_info */
|
||||
}
|
||||
(1): { /* Integer_variable_info */
|
||||
}
|
||||
(2): { /* Float_variable_info */
|
||||
}
|
||||
(3): { /* Long_variable_info */
|
||||
}
|
||||
(4): { /* Double_variable_info */
|
||||
}
|
||||
(5): { /* Null_variable_info */
|
||||
}
|
||||
(6): { /* UninitializedThis_variable_info */
|
||||
}
|
||||
(7): { /* Object_variable_info */
|
||||
cp_ref cpool_index;
|
||||
}
|
||||
(8): { /* Uninitialized_variable_info */
|
||||
u2 offset;
|
||||
}
|
||||
}
|
||||
} [[format("fmt::verif_type_info")]];
|
||||
|
||||
struct same_locals_1_stack_item_frame {
|
||||
verification_type_info stack[1];
|
||||
};
|
||||
|
||||
struct field_info {
|
||||
access_flags_field access_flags;
|
||||
u2 name_index;
|
||||
u2 descriptor_index;
|
||||
struct same_locals_1_stack_item_frame_extended {
|
||||
u2 offset_delta;
|
||||
verification_type_info stack[1];
|
||||
};
|
||||
|
||||
u2 attribute_count;
|
||||
attribute_info attributes[attribute_count];
|
||||
struct chop_frame {
|
||||
u2 offset_delta;
|
||||
};
|
||||
|
||||
struct same_frame_extended {
|
||||
u2 offset_delta;
|
||||
} [[static]];
|
||||
|
||||
struct append_frame<auto frame_type> {
|
||||
u2 offset_delta;
|
||||
verification_type_info locals[frame_type - 251];
|
||||
};
|
||||
|
||||
struct full_frame {
|
||||
u2 offset_delta;
|
||||
u2 number_of_locals;
|
||||
verification_type_info locals[number_of_locals];
|
||||
u2 number_of_stack_items;
|
||||
verification_type_info stack[number_of_stack_items];
|
||||
};
|
||||
|
||||
struct stack_map_frame {
|
||||
u1 frame_type;
|
||||
match(frame_type) {
|
||||
(0 ... 63): {} /* nothing */
|
||||
(64 ... 127): same_locals_1_stack_item_frame child [[inline]];
|
||||
(247): same_locals_1_stack_item_frame_extended child [[inline]];
|
||||
(248 ... 250): chop_frame child [[inline]];
|
||||
(251): same_frame_extended child [[inline]];
|
||||
(252 ... 254): append_frame<frame_type> child [[inline]];
|
||||
(255): full_frame child [[inline]];
|
||||
}
|
||||
} [[format("fmt::stack_map_frame")]];
|
||||
|
||||
struct same_frame {
|
||||
u1 frame_type = SAME; /* 0-63 */
|
||||
};
|
||||
|
||||
struct attribute_stack_map_table {
|
||||
u2 number_of_entries;
|
||||
stack_map_frame entries[number_of_entries];
|
||||
};
|
||||
|
||||
struct attribute_exception {
|
||||
u2 number_of_exceptions;
|
||||
cp_ref exception_index_table[number_of_exceptions];
|
||||
};
|
||||
|
||||
struct inner_class {
|
||||
cp_ref inner_class_info_index;
|
||||
u16 __ [[hidden]];
|
||||
if(__ != 0) {
|
||||
cp_ref outer_class_info_index @ addressof(__);
|
||||
}
|
||||
u16 ___ [[hidden]];
|
||||
if(___ != 0) {
|
||||
cp_ref inner_name_index @ addressof(___);
|
||||
}
|
||||
u2 inner_class_access_flags;
|
||||
};
|
||||
|
||||
struct attribute_inner_classes {
|
||||
u2 number_of_classes;
|
||||
inner_class classes[number_of_classes];
|
||||
};
|
||||
|
||||
struct attribute_enclosing_method {
|
||||
cp_ref class_index;
|
||||
cp_ref method_index;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_synthetic {
|
||||
};
|
||||
|
||||
struct attribute_signature {
|
||||
cp_ref signature_index;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_source_file {
|
||||
cp_ref sourcefile_index;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_source_debug_extension {
|
||||
u1 debug_extension[attribute_length];
|
||||
};
|
||||
|
||||
struct line_number_table_entry {
|
||||
u2 start_pc;
|
||||
u2 line_number;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_line_number_table {
|
||||
u2 line_number_table_length;
|
||||
line_number_table_entry line_number_table[line_number_table_length];
|
||||
};
|
||||
|
||||
struct local_variable_table_entry {
|
||||
u2 start_pc;
|
||||
u2 length;
|
||||
cp_ref name_index;
|
||||
cp_ref descriptor_index;
|
||||
u2 index;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_local_variable_table {
|
||||
u2 local_variable_table_length;
|
||||
local_variable_table_entry local_variable_table[local_variable_table_length];
|
||||
};
|
||||
|
||||
struct local_variable_type_table_entry {
|
||||
u2 start_pc;
|
||||
u2 length;
|
||||
cp_ref name_index;
|
||||
cp_ref signature_index;
|
||||
u2 index;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_local_variable_type_table {
|
||||
u2 local_variable_type_table_length;
|
||||
local_variable_type_table_entry local_variable_type_table[local_variable_type_table_length];
|
||||
};
|
||||
|
||||
struct attribute_deprecated {
|
||||
};
|
||||
|
||||
using annotation;
|
||||
using element_value;
|
||||
|
||||
struct element_value {
|
||||
char tag;
|
||||
match(tag) {
|
||||
('B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z' | 's'): {
|
||||
cp_ref const_value_index;
|
||||
}
|
||||
('e'): {
|
||||
cp_ref type_name_index;
|
||||
cp_ref const_name_index;
|
||||
}
|
||||
('c'): {
|
||||
cp_ref class_info_index;
|
||||
}
|
||||
('@'): {
|
||||
annotation annotation_value;
|
||||
}
|
||||
('['): {
|
||||
u2 num_values;
|
||||
element_value values[num_values];
|
||||
}
|
||||
(_): {
|
||||
std::error("Unknown element_value tag: %c", tag);
|
||||
}
|
||||
}
|
||||
} [[format("fmt::element_value")]];
|
||||
|
||||
struct element_value_pair {
|
||||
cp_ref element_name_index;
|
||||
element_value value;
|
||||
};
|
||||
|
||||
struct annotation {
|
||||
cp_ref type_index;
|
||||
u2 num_element_value_pairs;
|
||||
element_value_pair element_value_pairs[num_element_value_pairs];
|
||||
};
|
||||
|
||||
struct annotation_base {
|
||||
u2 num_annotations;
|
||||
annotation annotations[num_annotations];
|
||||
};
|
||||
|
||||
struct attribute_runtime_visible_annotations {
|
||||
annotation_base [[inline]];
|
||||
};
|
||||
|
||||
struct attribute_runtime_invisible_annotations {
|
||||
annotation_base [[inline]];
|
||||
};
|
||||
|
||||
struct attribute_runtime_visible_parameter_annotations {
|
||||
u1 num_parameters;
|
||||
annotation_base parameter_annotations[num_parameters];
|
||||
};
|
||||
|
||||
struct attribute_runtime_invisible_parameter_annotations {
|
||||
u1 num_parameters;
|
||||
annotation_base parameter_annotations[num_parameters];
|
||||
};
|
||||
|
||||
struct path_element {
|
||||
u1 type_path_kind;
|
||||
u1 type_argument_index;
|
||||
};
|
||||
|
||||
struct type_path {
|
||||
u1 path_length;
|
||||
path_element path[path_length];
|
||||
};
|
||||
|
||||
struct localvar_target_entry {
|
||||
u2 start_pc;
|
||||
u2 length;
|
||||
u2 index;
|
||||
};
|
||||
|
||||
struct target_info<auto target_type> {
|
||||
match(target_type) {
|
||||
(0x00 | 0x01): { /* type_parameter_target */
|
||||
u1 type_parameter_index;
|
||||
}
|
||||
(0x10): { /* supertype_target */
|
||||
u2 supertype_index;
|
||||
}
|
||||
(0x11 | 0x12): { /* type_parameter_bound_target */
|
||||
u1 type_parameter_index;
|
||||
u1 bound_index;
|
||||
}
|
||||
(0x13 | 0x14 | 0x15): { /* empty_target */ }
|
||||
(0x16): { /* formal_parameter_target */
|
||||
u1 formal_parameter_index;
|
||||
}
|
||||
(0x17): { /* throws_target */
|
||||
u2 throws_type_index;
|
||||
}
|
||||
(0x40 | 0x41): { /* localvar_target */
|
||||
u2 table_length;
|
||||
localvar_target_entry table[table_length];
|
||||
}
|
||||
(0x42): { /* catch_target */
|
||||
u2 exception_table_index;
|
||||
}
|
||||
(0x43 | 0x44 | 0x45 | 0x46): { /* offset_target */
|
||||
u2 offset;
|
||||
}
|
||||
(0x47 | 0x48 | 0x49 | 0x4A): { /* type_argument_target */
|
||||
u2 offset;
|
||||
u1 type_argument_index;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct type_annotation {
|
||||
u1 target_type;
|
||||
target_info<target_type> target_info;
|
||||
type_path type_path;
|
||||
annotation annotation [[inline]];
|
||||
};
|
||||
|
||||
struct attribute_runtime_visible_type_annotations {
|
||||
u2 num_annotations;
|
||||
type_annotation annotations[num_annotations];
|
||||
};
|
||||
|
||||
struct attribute_runtime_invisible_type_annotations {
|
||||
u2 num_annotations;
|
||||
type_annotation annotations[num_annotations];
|
||||
};
|
||||
|
||||
struct attribute_annotation_default {
|
||||
element_value default_value;
|
||||
};
|
||||
|
||||
struct bootstrap_method {
|
||||
cp_ref bootstrap_method_ref;
|
||||
u2 num_bootstrap_arguments;
|
||||
cp_ref bootstrap_arguments[num_bootstrap_arguments];
|
||||
};
|
||||
|
||||
struct attribute_bootstrap_methods {
|
||||
u2 num_bootstrap_methods;
|
||||
bootstrap_method bootstrap_methods[num_bootstrap_methods];
|
||||
};
|
||||
|
||||
struct method_parameter {
|
||||
u2 name_index [[hidden]];
|
||||
if (name_index != 0) {
|
||||
cp_ref name_index @ addressof(name_index);
|
||||
}
|
||||
u2 access_flags;
|
||||
};
|
||||
|
||||
struct attribute_method_parameters {
|
||||
u1 parameters_count;
|
||||
method_parameter parameters[parameters_count];
|
||||
};
|
||||
|
||||
struct require {
|
||||
cp_ref require_index;
|
||||
access_flags_module require_flags;
|
||||
u2 require_version_index [[hidden]];
|
||||
if (require_version_index != 0) {
|
||||
cp_ref require_version_index @ addressof(require_version_index);
|
||||
}
|
||||
};
|
||||
|
||||
struct export {
|
||||
cp_ref exports_index;
|
||||
access_flags_module exports_flags;
|
||||
u2 exports_to_count;
|
||||
cp_ref exports_to_index[exports_to_count];
|
||||
};
|
||||
|
||||
struct open {
|
||||
cp_ref opens_index;
|
||||
access_flags_module opens_flags;
|
||||
u2 opens_to_count;
|
||||
cp_ref opens_to_index[opens_to_count];
|
||||
};
|
||||
|
||||
struct provide {
|
||||
cp_ref provides_index;
|
||||
u2 provides_with_count;
|
||||
cp_ref provides_with_index[provides_with_count];
|
||||
};
|
||||
|
||||
struct attribute_module {
|
||||
cp_ref module_name_index;
|
||||
u2 module_flags;
|
||||
u2 module_version_index [[hidden]];
|
||||
if (module_version_index != 0) {
|
||||
cp_ref module_version_index @ addressof(module_version_index);
|
||||
}
|
||||
u2 requires_count;
|
||||
require requires[requires_count];
|
||||
u2 exports_count;
|
||||
export exports[exports_count];
|
||||
u2 opens_count;
|
||||
open opens[opens_count];
|
||||
u2 uses_count;
|
||||
cp_ref uses_index[uses_count];
|
||||
u2 provides_count;
|
||||
provide provides[provides_count];
|
||||
};
|
||||
|
||||
struct attribute_module_packages {
|
||||
u2 package_count;
|
||||
cp_ref package_index[package_count];
|
||||
};
|
||||
|
||||
struct attribute_module_main_class {
|
||||
cp_ref main_class_index;
|
||||
};
|
||||
|
||||
struct attribute_nest_host {
|
||||
cp_ref host_class_index;
|
||||
};
|
||||
|
||||
struct attribute_nest_members {
|
||||
u2 number_of_classes;
|
||||
cp_ref classes[number_of_classes];
|
||||
};
|
||||
|
||||
using record_component_info;
|
||||
|
||||
struct attribute_record {
|
||||
u2 component_count;
|
||||
record_component_info components[component_count];
|
||||
};
|
||||
|
||||
struct attribute_permitted_subclasses {
|
||||
u2 number_of_classes;
|
||||
cp_ref classes[number_of_classes];
|
||||
};
|
||||
|
||||
struct attribute_info<auto constant_pool> {
|
||||
cp_ref attribute_name_index;
|
||||
u4 attribute_length;
|
||||
match(constant_pool[attribute_name_index-1].bytes) {
|
||||
("Code"): attribute_code child [[inline]];
|
||||
("ConstantValue"): attribute_constant_value [[inline]];
|
||||
("StackMapTable"): attribute_stack_map_table [[inline]];
|
||||
("Exceptions"): attribute_exception [[inline]];
|
||||
("InnerClasses"): attribute_inner_classes [[inline]];
|
||||
("EnclosingMethod"): attribute_enclosing_method [[inline]];
|
||||
("Synthetic"): attribute_synthetic [[inline]];
|
||||
("Signature"): attribute_signature [[inline]];
|
||||
("SourceFile"): attribute_source_file [[inline]];
|
||||
("SourceDebugExtension"): attribute_source_debug_extension [[inline]];
|
||||
("LineNumberTable"): attribute_line_number_table [[inline]];
|
||||
("LocalVariableTable"): attribute_local_variable_table [[inline]];
|
||||
("LocalVariableTypeTable"): attribute_local_variable_type_table [[inline]];
|
||||
("Deprecated"): attribute_deprecated [[inline]];
|
||||
("RuntimeVisibleAnnotations"): attribute_runtime_visible_annotations [[inline]];
|
||||
("RuntimeInvisibleAnnotations"): attribute_runtime_invisible_annotations [[inline]];
|
||||
("RuntimeVisibleParameterAnnotations"): attribute_runtime_visible_parameter_annotations [[inline]];
|
||||
("RuntimeInvisibleParameterAnnotations"): attribute_runtime_invisible_parameter_annotations [[inline]];
|
||||
("RuntimeVisibleTypeAnnotations"): attribute_runtime_visible_type_annotations [[inline]];
|
||||
("RuntimeInvisibleTypeAnnotations"): attribute_runtime_invisible_type_annotations [[inline]];
|
||||
("AnnotationDefault"): attribute_annotation_default [[inline]];
|
||||
("BootstrapMethods"): attribute_bootstrap_methods [[inline]];
|
||||
("MethodParameters"): attribute_method_parameters [[inline]];
|
||||
("Module"): attribute_module [[inline]];
|
||||
("ModulePackages"): attribute_module_packages [[inline]];
|
||||
("ModuleMainClass"): attribute_module_main_class [[inline]];
|
||||
("NestHost"): attribute_nest_host [[inline]];
|
||||
("NestMembers"): attribute_nest_members [[inline]];
|
||||
("Record"): attribute_record [[inline]];
|
||||
(_): u1 info[attribute_length];
|
||||
}
|
||||
if(($-(addressof(this)+6)) != attribute_length) std::warning("Invalid attribute length at "
|
||||
+ std::format("{:x}", addressof(this))
|
||||
+ " " + std::string::to_string($-(addressof(this)+6)) + "!=" + std::string::to_string(attribute_length));
|
||||
} [[format("fmt::attribute")]];
|
||||
|
||||
struct record_component_info {
|
||||
cp_ref name_index;
|
||||
cp_ref descriptor_index;
|
||||
u2 attributes_count;
|
||||
attribute_info<parent.parent.parent.constant_pool> attributes[attributes_count];
|
||||
};
|
||||
|
||||
struct exception {
|
||||
u2 start_pc;
|
||||
u2 end_pc;
|
||||
u2 handler_pc;
|
||||
u2 catch_type;
|
||||
} [[static]];
|
||||
|
||||
struct attribute_code {
|
||||
u2 max_stack;
|
||||
u2 max_locals;
|
||||
u4 code_length;
|
||||
u1 code[code_length];
|
||||
u2 exception_table_length;
|
||||
exception exception_table[exception_table_length];
|
||||
u2 attributes_count;
|
||||
attribute_info<parent.parent.parent.constant_pool> attributes[attributes_count];
|
||||
};
|
||||
|
||||
|
||||
struct field_info {
|
||||
access_flags_field access_flags;
|
||||
cp_ref name_index;
|
||||
cp_ref descriptor_index;
|
||||
u2 attribute_count;
|
||||
attribute_info<parent.constant_pool> attributes[attribute_count];
|
||||
};
|
||||
|
||||
struct method_info {
|
||||
access_flags_method access_flags;
|
||||
u2 name_index;
|
||||
u2 descriptor_index;
|
||||
u2 attributes_count;
|
||||
attribute_info attributes[attributes_count];
|
||||
access_flags_method access_flags;
|
||||
cp_ref name_index;
|
||||
cp_ref descriptor_index;
|
||||
u2 attribute_count;
|
||||
attribute_info<parent.constant_pool> attributes[attribute_count];
|
||||
};
|
||||
|
||||
struct ClassFile {
|
||||
u4 magic;
|
||||
|
||||
u2 minor_version;
|
||||
major_version major_version;
|
||||
|
||||
u2 constant_pool_count;
|
||||
cp_info constant_pool[constant_pool_count - 1];
|
||||
|
||||
access_flags_class access_flags;
|
||||
u2 this_class;
|
||||
u2 super_class;
|
||||
|
||||
u2 interfaces_count;
|
||||
u2 interfaces[interfaces_count];
|
||||
|
||||
u2 fields_count;
|
||||
field_info fields[fields_count];
|
||||
|
||||
u2 methods_count;
|
||||
method_info methods[methods_count];
|
||||
|
||||
u2 attribute_count;
|
||||
attribute_info attributes[attribute_count];
|
||||
u1 magic[4];
|
||||
u2 minor_version;
|
||||
major_version major_version;
|
||||
u2 constant_pool_count;
|
||||
cp_info constant_pool[constant_pool_count-1];
|
||||
access_flags_class access_flags;
|
||||
cp_ref this_class;
|
||||
cp_ref super_class;
|
||||
u2 interfaces_count;
|
||||
cp_ref interfaces[interfaces_count];
|
||||
u2 fields_count;
|
||||
field_info fields[fields_count];
|
||||
u2 methods_count;
|
||||
method_info methods[methods_count];
|
||||
u2 attributes_count;
|
||||
attribute_info<constant_pool> attributes[attributes_count];
|
||||
};
|
||||
|
||||
ClassFile class_file @ 0x00;
|
||||
|
||||
fn main() {
|
||||
|
||||
std::assert(class_file.magic == 0xCAFEBABE, "File is not a valid Java Class file! Invalid header magic");
|
||||
|
||||
|
||||
std::print("Fields:");
|
||||
for (le u16 i = 0, i < class_file.fields_count, i = i + 1) {
|
||||
str field_string = " ";
|
||||
|
||||
if (class_file.fields[i].access_flags.ACC_PUBLIC)
|
||||
field_string = field_string + "public ";
|
||||
if (class_file.fields[i].access_flags.ACC_PRIVATE)
|
||||
field_string = field_string + "private ";
|
||||
if (class_file.fields[i].access_flags.ACC_PROTECTED)
|
||||
field_string = field_string + "protected ";
|
||||
if (class_file.fields[i].access_flags.ACC_STATIC)
|
||||
field_string = field_string + "static ";
|
||||
if (class_file.fields[i].access_flags.ACC_FINAL)
|
||||
field_string = field_string + "final ";
|
||||
if (class_file.fields[i].access_flags.ACC_VOLATILE)
|
||||
field_string = field_string + "volatile ";
|
||||
if (class_file.fields[i].access_flags.ACC_TRANSIENT)
|
||||
field_string = field_string + "transient ";
|
||||
if (class_file.fields[i].access_flags.ACC_ENUM)
|
||||
field_string = field_string + "enum ";
|
||||
|
||||
field_string = field_string + class_file.constant_pool[class_file.fields[i].name_index - 1].info.bytes;
|
||||
field_string = field_string + " [ " + class_file.constant_pool[class_file.fields[i].descriptor_index - 1].info.bytes + " ]";
|
||||
|
||||
std::print("{}", field_string);
|
||||
}
|
||||
|
||||
std::print("Methods:");
|
||||
for (le u16 i = 0, i < class_file.methods_count, i = i + 1) {
|
||||
str method_string = " ";
|
||||
|
||||
if (class_file.methods[i].access_flags.ACC_PUBLIC)
|
||||
method_string = method_string + "public ";
|
||||
if (class_file.methods[i].access_flags.ACC_PRIVATE)
|
||||
method_string = method_string + "private ";
|
||||
if (class_file.methods[i].access_flags.ACC_PROTECTED)
|
||||
method_string = method_string + "protected ";
|
||||
if (class_file.methods[i].access_flags.ACC_STATIC)
|
||||
method_string = method_string + "static ";
|
||||
if (class_file.methods[i].access_flags.ACC_FINAL)
|
||||
method_string = method_string + "final ";
|
||||
if (class_file.methods[i].access_flags.ACC_SYNCHRONIZED)
|
||||
method_string = method_string + "synchronized ";
|
||||
if (class_file.methods[i].access_flags.ACC_NATIVE)
|
||||
method_string = method_string + "native ";
|
||||
if (class_file.methods[i].access_flags.ACC_ABSTRACT)
|
||||
method_string = method_string + "abstract ";
|
||||
if (class_file.methods[i].access_flags.ACC_STRICT)
|
||||
method_string = method_string + "strictfp ";
|
||||
|
||||
method_string = method_string + class_file.constant_pool[class_file.methods[i].name_index - 1].info.bytes;
|
||||
method_string = method_string + " [ " + class_file.constant_pool[class_file.methods[i].descriptor_index - 1].info.bytes + " ]";
|
||||
|
||||
std::print("{}", method_string);
|
||||
}
|
||||
|
||||
std::print("Class Attributes:");
|
||||
for (le u16 i = 0, i < class_file.attribute_count, i = i + 1) {
|
||||
std::print(" {}", class_file.constant_pool[class_file.attributes[i].attribute_name_info - 1].info.bytes);
|
||||
}
|
||||
};
|
||||
ClassFile file @ 0x0;
|
||||
831
patterns/max_v104.hexpat
Normal file
831
patterns/max_v104.hexpat
Normal file
@@ -0,0 +1,831 @@
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
#pragma array_limit 12544
|
||||
#pragma pattern_limit 2000000
|
||||
#pragma eval_depth 32
|
||||
|
||||
enum FileType : u8
|
||||
{
|
||||
Custom,
|
||||
Tutorial,
|
||||
Campaign,
|
||||
Hot_seat,
|
||||
Multiplayer,
|
||||
Demo,
|
||||
Debug,
|
||||
Text,
|
||||
Scenario,
|
||||
Multi_scenario
|
||||
};
|
||||
|
||||
enum PlanetType : u8
|
||||
{
|
||||
Snowcrab,
|
||||
Frigia,
|
||||
Ice_Berg,
|
||||
The_Cooler,
|
||||
Ultima_Thule,
|
||||
Long_Floes,
|
||||
Iron_Cross,
|
||||
Splatterscape,
|
||||
Peak_a_boo,
|
||||
Valentines_Planet,
|
||||
Three_Rings,
|
||||
Great_divide,
|
||||
New_Luzon,
|
||||
Middle_Sea,
|
||||
High_Impact,
|
||||
Sanctuary,
|
||||
Islandia,
|
||||
Hammerhead,
|
||||
Freckles,
|
||||
Sandspit,
|
||||
Great_Circle,
|
||||
Long_Passage,
|
||||
Flash_Point,
|
||||
Bottleneck
|
||||
};
|
||||
|
||||
enum TeamType : u8
|
||||
{
|
||||
None = 0,
|
||||
Human = 1,
|
||||
Computer = 2,
|
||||
Remote = 3,
|
||||
Eliminated = 4
|
||||
};
|
||||
|
||||
enum TeamIndex : u8
|
||||
{
|
||||
Red = 0,
|
||||
Green = 1,
|
||||
Blue = 2,
|
||||
Gray = 3
|
||||
};
|
||||
|
||||
enum TeamIndex16 : u16
|
||||
{
|
||||
Red = 0,
|
||||
Green = 1,
|
||||
Blue = 2,
|
||||
Gray = 3
|
||||
};
|
||||
|
||||
enum PlayMode : u8
|
||||
{
|
||||
Turn_Based = 0,
|
||||
Simultaneous_Moves = 1
|
||||
};
|
||||
|
||||
enum TeamClan : u8
|
||||
{
|
||||
None = 0,
|
||||
The_Chosen = 1,
|
||||
Crimson_Path = 2,
|
||||
Von_Griffin = 3,
|
||||
Ayers_Hand = 4,
|
||||
Musashi = 5,
|
||||
Sacred_Eights = 6,
|
||||
Seven_Knights = 7,
|
||||
Axis_Inc = 8
|
||||
};
|
||||
|
||||
enum OpponentType : u8
|
||||
{
|
||||
Clueless = 0,
|
||||
Apprentice = 1,
|
||||
Average = 2,
|
||||
Expert = 3,
|
||||
Master = 4,
|
||||
God = 5
|
||||
};
|
||||
|
||||
enum VictoryType : u8
|
||||
{
|
||||
Duration = 0,
|
||||
Score = 1
|
||||
};
|
||||
|
||||
struct IniOptions
|
||||
{
|
||||
s32 world;
|
||||
s32 turn_timer;
|
||||
s32 endturn;
|
||||
s32 start_gold;
|
||||
s32 play_mode;
|
||||
s32 victory_type;
|
||||
s32 victory_limit;
|
||||
s32 opponent;
|
||||
s32 raw_resource;
|
||||
s32 fuel_resource;
|
||||
s32 gold_resource;
|
||||
s32 alien_derelicts;
|
||||
};
|
||||
|
||||
struct IniPreferences
|
||||
{
|
||||
s32 effects;
|
||||
s32 click_scroll;
|
||||
s32 quick_scroll;
|
||||
s32 fast_movement;
|
||||
s32 follow_unit;
|
||||
s32 auto_select;
|
||||
s32 enemy_halt;
|
||||
};
|
||||
|
||||
enum SurfaceType : u8
|
||||
{
|
||||
Land = 1,
|
||||
Water = 2,
|
||||
Coast = 4,
|
||||
Air = 8
|
||||
};
|
||||
|
||||
enum AiStrategy : u8
|
||||
{
|
||||
Random,
|
||||
Defensive,
|
||||
Missiles,
|
||||
Air,
|
||||
Sea,
|
||||
Scout_horde,
|
||||
Tank_horde,
|
||||
Fast_attack,
|
||||
Combined_arms,
|
||||
Espionage
|
||||
};
|
||||
|
||||
bitfield GridResourceMapEntry
|
||||
{
|
||||
padding : 2;
|
||||
team_visibility_gray : 1;
|
||||
team_visibility_blue : 1;
|
||||
team_visibility_green : 1;
|
||||
team_visibility_red : 1;
|
||||
padding : 2;
|
||||
cargo_amount : 5;
|
||||
cargo_type_fuel : 1;
|
||||
cargo_type_gold : 1;
|
||||
cargo_type_material : 1;
|
||||
};
|
||||
|
||||
bitfield UnitFlags
|
||||
{
|
||||
// MSB
|
||||
requires_slab: 1;
|
||||
turret_sprite: 1;
|
||||
sentry_unit: 1;
|
||||
spinning_turret: 1;
|
||||
padding: 4;
|
||||
|
||||
hovering: 1;
|
||||
has_firing_sprite: 1;
|
||||
fires_missiles: 1;
|
||||
constructor_unit: 1;
|
||||
padding: 1;
|
||||
electronic_unit: 1;
|
||||
selectable: 1;
|
||||
standalone: 1;
|
||||
|
||||
mobile_land_unit: 1;
|
||||
stationary: 1;
|
||||
padding: 4;
|
||||
upgradeable: 1;
|
||||
padding: 1;
|
||||
|
||||
// LSB
|
||||
ground_cover : 1;
|
||||
exploding: 1;
|
||||
animated: 1;
|
||||
connector_unit: 1;
|
||||
building: 1;
|
||||
missile_unit: 1;
|
||||
mobile_air_unit: 1;
|
||||
mobile_sea_unit: 1;
|
||||
};
|
||||
|
||||
struct Point
|
||||
{
|
||||
s16 x;
|
||||
s16 y;
|
||||
};
|
||||
|
||||
struct ResearchTopicInfo
|
||||
{
|
||||
u32 research_level;
|
||||
u32 turns_to_complete;
|
||||
s32 allocation;
|
||||
};
|
||||
|
||||
struct ScreenLocation
|
||||
{
|
||||
s8 x;
|
||||
s8 y;
|
||||
};
|
||||
|
||||
struct TeamInfo
|
||||
{
|
||||
Point markers[10];
|
||||
TeamType team_type;
|
||||
s8 field_41;
|
||||
TeamClan team_clan;
|
||||
ResearchTopicInfo research_topics[8];
|
||||
u32 victory_points;
|
||||
u16 next_unit_id;
|
||||
u8 unit_counters[93];
|
||||
ScreenLocation screen_location[6];
|
||||
u16 score_graph[50];
|
||||
u16 selected_unit;
|
||||
u16 zoom_level;
|
||||
Point screen_position;
|
||||
bool gui_button_state_range;
|
||||
bool gui_button_state_scan;
|
||||
bool gui_button_state_status;
|
||||
bool gui_button_state_colors;
|
||||
bool gui_button_state_hits;
|
||||
bool gui_button_state_ammo;
|
||||
bool gui_button_state_names;
|
||||
bool gui_button_state_minimap_2x;
|
||||
bool gui_button_state_minimap_tnt;
|
||||
bool gui_button_state_grid;
|
||||
bool gui_button_state_survey;
|
||||
u16 stats_factories_built;
|
||||
u16 stats_mines_built;
|
||||
u16 stats_buildings_built;
|
||||
u16 stats_units_built;
|
||||
u16 casualties[93];
|
||||
u16 stats_gold_spent_on_upgrades;
|
||||
};
|
||||
|
||||
struct UnitValues
|
||||
{
|
||||
u16 object_index;
|
||||
|
||||
if(CheckObjectId(object_index, true) == true)
|
||||
{
|
||||
u16 class_type;
|
||||
u16 turns;
|
||||
u16 hits;
|
||||
u16 armor;
|
||||
u16 attack;
|
||||
u16 speed;
|
||||
u16 range;
|
||||
u16 rounds;
|
||||
bool move_and_fire;
|
||||
u16 scan;
|
||||
u16 storage;
|
||||
u16 ammo;
|
||||
u16 attack_radius;
|
||||
u16 agent_adjust;
|
||||
u16 version;
|
||||
u8 units_built;
|
||||
}
|
||||
};
|
||||
|
||||
struct Complex
|
||||
{
|
||||
u16 object_index;
|
||||
|
||||
if(CheckObjectId(object_index, true) == true)
|
||||
{
|
||||
u16 class_type;
|
||||
s16 material;
|
||||
s16 fuel;
|
||||
s16 gold;
|
||||
s16 power;
|
||||
s16 workers;
|
||||
s16 buildings;
|
||||
s16 id;
|
||||
}
|
||||
};
|
||||
|
||||
struct TeamUnits
|
||||
{
|
||||
s16 gold;
|
||||
UnitValues base_unit_values[93];
|
||||
UnitValues current_unit_values[93];
|
||||
u16 complex_count;
|
||||
Complex complexes[complex_count];
|
||||
};
|
||||
|
||||
enum UnitType : u16
|
||||
{
|
||||
UNIT_TYPE_GOLD_REFINERY = 0,
|
||||
UNIT_TYPE_POWER_STATION = 1,
|
||||
UNIT_TYPE_POWER_GENERATOR = 2,
|
||||
UNIT_TYPE_BARRACKS = 3,
|
||||
UNIT_TYPE_ALIEN_BUILDING_1 = 4,
|
||||
UNIT_TYPE_RADAR = 5,
|
||||
UNIT_TYPE_STORAGE_UNIT = 6,
|
||||
UNIT_TYPE_FUEL_TANK = 7,
|
||||
UNIT_TYPE_GOLD_VAULT = 8,
|
||||
UNIT_TYPE_DEPOT = 9,
|
||||
UNIT_TYPE_HANGAR = 10,
|
||||
UNIT_TYPE_DOCK = 11,
|
||||
UNIT_TYPE_CONNECTOR = 12,
|
||||
UNIT_TYPE_LARGE_RUBBLE_1 = 13,
|
||||
UNIT_TYPE_SMALL_RUBBLE_1 = 14,
|
||||
UNIT_TYPE_LARGE_TAPE = 15,
|
||||
UNIT_TYPE_SMALL_TAPE = 16,
|
||||
UNIT_TYPE_LARGE_SLAB = 17,
|
||||
UNIT_TYPE_SMALL_SLAB = 18,
|
||||
UNIT_TYPE_LARGE_CONES = 19,
|
||||
UNIT_TYPE_SMALL_CONES = 20,
|
||||
UNIT_TYPE_ROAD = 21,
|
||||
UNIT_TYPE_LANDING_PAD = 22,
|
||||
UNIT_TYPE_SHIPYARD = 23,
|
||||
UNIT_TYPE_LIGHT_VEHICLE_PLANT = 24,
|
||||
UNIT_TYPE_HEAVY_VEHICLE_PLANT = 25,
|
||||
UNIT_TYPE_ALIEN_BUILDING_2 = 26,
|
||||
UNIT_TYPE_AIR_UNITS_PLANT = 27,
|
||||
UNIT_TYPE_HABITAT = 28,
|
||||
UNIT_TYPE_RESEARCH_CENTER = 29,
|
||||
UNIT_TYPE_ECOSPHERE = 30,
|
||||
UNIT_TYPE_ALIEN_BUILDING_3 = 31,
|
||||
UNIT_TYPE_TRAINING_HALL = 32,
|
||||
UNIT_TYPE_WATER_PLATFORM = 33,
|
||||
UNIT_TYPE_GUN_TURRET = 34,
|
||||
UNIT_TYPE_ANTI_AIRCRAFT = 35,
|
||||
UNIT_TYPE_ARTILLERY = 36,
|
||||
UNIT_TYPE_MISSILE_LAUNCHER = 37,
|
||||
UNIT_TYPE_CONCRETE_BLOCK = 38,
|
||||
UNIT_TYPE_BRIDGE = 39,
|
||||
UNIT_TYPE_MINING_STATION = 40,
|
||||
UNIT_TYPE_LAND_MINE = 41,
|
||||
UNIT_TYPE_SEA_MINE = 42,
|
||||
UNIT_TYPE_LAND_EXPLOSION = 43,
|
||||
UNIT_TYPE_AIR_EXPLOSION = 44,
|
||||
UNIT_TYPE_SEA_EXPLOSION = 45,
|
||||
UNIT_TYPE_BUILDING_EXPLOSION = 46,
|
||||
UNIT_TYPE_HIT_EXPLOSION = 47,
|
||||
UNIT_TYPE_MASTER_BUILDER = 48,
|
||||
UNIT_TYPE_CONSTRUCTOR = 49,
|
||||
UNIT_TYPE_SCOUT = 50,
|
||||
UNIT_TYPE_TANK = 51,
|
||||
UNIT_TYPE_ASSAULT_GUN = 52,
|
||||
UNIT_TYPE_ROCKET_LAUNCHER = 53,
|
||||
UNIT_TYPE_MISSILE_CRAWLER = 54,
|
||||
UNIT_TYPE_MOBILE_ANTI_AIRCRAFT = 55,
|
||||
UNIT_TYPE_MINE_LAYER = 56,
|
||||
UNIT_TYPE_SURVEYOR = 57,
|
||||
UNIT_TYPE_SCANNER = 58,
|
||||
UNIT_TYPE_SUPPLY_TRUCK = 59,
|
||||
UNIT_TYPE_GOLD_TRUCK = 60,
|
||||
UNIT_TYPE_ENGINEER = 61,
|
||||
UNIT_TYPE_BULLDOZER = 62,
|
||||
UNIT_TYPE_REPAIR_UNIT = 63,
|
||||
UNIT_TYPE_FUEL_TRUCK = 64,
|
||||
UNIT_TYPE_PERSONNEL_CARRIER = 65,
|
||||
UNIT_TYPE_INFILTRATOR = 66,
|
||||
UNIT_TYPE_INFANTRY = 67,
|
||||
UNIT_TYPE_ESCORT = 68,
|
||||
UNIT_TYPE_CORVETTE = 69,
|
||||
UNIT_TYPE_GUNBOAT = 70,
|
||||
UNIT_TYPE_SUBMARINE = 71,
|
||||
UNIT_TYPE_SEA_TRANSPORT = 72,
|
||||
UNIT_TYPE_MISSILE_CRUISER = 73,
|
||||
UNIT_TYPE_SEA_MINE_LAYER = 74,
|
||||
UNIT_TYPE_CARGO_SHIP = 75,
|
||||
UNIT_TYPE_FIGHTER = 76,
|
||||
UNIT_TYPE_GROUND_ATTACK_PLANE = 77,
|
||||
UNIT_TYPE_AIR_TRANSPORT = 78,
|
||||
UNIT_TYPE_AWAC = 79,
|
||||
UNIT_TYPE_ALIEN_GUNBOAT = 80,
|
||||
UNIT_TYPE_ALIEN_TANK = 81,
|
||||
UNIT_TYPE_ALIEN_ASSAULT_GUN = 82,
|
||||
UNIT_TYPE_ALIEN_ATTACK_PLANE = 83,
|
||||
UNIT_TYPE_MISSILE = 84,
|
||||
UNIT_TYPE_TORPEDO = 85,
|
||||
UNIT_TYPE_ALIEN_MISSILE = 86,
|
||||
UNIT_TYPE_TANK_PLASMA_BALL = 87,
|
||||
UNIT_TYPE_ARTILLERY_PLASMA_BALL = 88,
|
||||
UNIT_TYPE_SMOKE_TRAIL = 89,
|
||||
UNIT_TYPE_BUBBLE_TRAIL = 90,
|
||||
UNIT_TYPE_HARVESTER = 91,
|
||||
UNIT_TYPE_DEAD_WALDO = 92
|
||||
};
|
||||
|
||||
enum OrderType : u8
|
||||
{
|
||||
ORDER_TYPE_AWAITING = 0x0,
|
||||
ORDER_TYPE_TRANSFORMING = 0x1,
|
||||
ORDER_TYPE_MOVING = 0x2,
|
||||
ORDER_TYPE_FIRING = 0x3,
|
||||
ORDER_TYPE_ORDER_BUILDING = 0x4,
|
||||
ORDER_TYPE_ACTIVATE_ORDER = 0x5,
|
||||
ORDER_TYPE_NEW_ALLOCATE_ORDER = 0x6,
|
||||
ORDER_TYPE_POWER_ON = 0x7,
|
||||
ORDER_TYPE_POWER_OFF = 0x8,
|
||||
ORDER_TYPE_EXPLODING = 0x9,
|
||||
ORDER_TYPE_UNLOADING = 0xA,
|
||||
ORDER_TYPE_CLEARING = 0xB,
|
||||
ORDER_TYPE_SENTRY = 0xC,
|
||||
ORDER_TYPE_LANDING = 0xD,
|
||||
ORDER_TYPE_TAKING_OFF = 0xE,
|
||||
ORDER_TYPE_LOADING = 0xF,
|
||||
ORDER_TYPE_IDLE = 0x10,
|
||||
ORDER_TYPE_REPAIRING = 0x11,
|
||||
ORDER_TYPE_REFUELING = 0x12,
|
||||
ORDER_TYPE_RELOADING = 0x13,
|
||||
ORDER_TYPE_TRANSFERRING = 0x14,
|
||||
ORDER_TYPE_AWAITING_21 = 0x15,
|
||||
ORDER_TYPE_AWAITING_22 = 0x16,
|
||||
ORDER_TYPE_AWAITING_23 = 0x17,
|
||||
ORDER_TYPE_AWAITING_24 = 0x18,
|
||||
ORDER_TYPE_AWAITING_25 = 0x19,
|
||||
ORDER_TYPE_DISABLED = 0x1A,
|
||||
ORDER_TYPE_MOVING_27 = 0x1B,
|
||||
ORDER_TYPE_REPAIRING_28 = 0x1C,
|
||||
ORDER_TYPE_TRANSFERRING_29 = 0x1D,
|
||||
ORDER_TYPE_ATTACKING = 0x1E,
|
||||
ORDER_TYPE_BUILDING_HALTED = 0x1F
|
||||
};
|
||||
|
||||
struct Rect
|
||||
{
|
||||
s32 ulx;
|
||||
s32 uly;
|
||||
s32 lrx;
|
||||
s32 lry;
|
||||
};
|
||||
|
||||
struct PathStep
|
||||
{
|
||||
s8 x;
|
||||
s8 y;
|
||||
};
|
||||
|
||||
struct Path
|
||||
{
|
||||
u16 object_index;
|
||||
|
||||
if(CheckObjectId(object_index, true) == true)
|
||||
{
|
||||
u16 class_type;
|
||||
|
||||
// Air path
|
||||
if (class_type == 1)
|
||||
{
|
||||
s16 length;
|
||||
u8 angle;
|
||||
Point pixel_start;
|
||||
Point pixel_end;
|
||||
s32 x_step;
|
||||
s32 y_step;
|
||||
s32 delta_x;
|
||||
s32 delta_y;
|
||||
}
|
||||
// Ground path
|
||||
else if (class_type == 4)
|
||||
{
|
||||
Point pixel_end;
|
||||
s16 index;
|
||||
s16 steps_count;
|
||||
PathStep steps[steps_count];
|
||||
}
|
||||
// Builder path
|
||||
else if (class_type == 2)
|
||||
{
|
||||
Point coordinate;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::assert(0, "Unknown path class");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct UnitTypeArray
|
||||
{
|
||||
u16 object_count;
|
||||
|
||||
UnitType array[object_count];
|
||||
};
|
||||
|
||||
struct UnitInfo
|
||||
{
|
||||
u16 object_index;
|
||||
|
||||
if(CheckObjectId(object_index, true) == true)
|
||||
{
|
||||
u16 class_type;
|
||||
UnitType unit_type;
|
||||
|
||||
if (unit_type == UnitType::UNIT_TYPE_DEAD_WALDO)
|
||||
{
|
||||
std::print("Found Waldo!");
|
||||
}
|
||||
|
||||
u16 hash_id;
|
||||
UnitFlags flags;
|
||||
Point pixel_position;
|
||||
Point grid_position;
|
||||
u16 name_length;
|
||||
s8 name[name_length];
|
||||
Point shadow_offset;
|
||||
TeamIndex team;
|
||||
u8 name_index;
|
||||
u8 brightness;
|
||||
u8 angle;
|
||||
u8 visible_to_team[5];
|
||||
u8 spotted_by_team[5];
|
||||
u8 max_velocity;
|
||||
u8 velocity;
|
||||
u8 sound;
|
||||
u8 scaler_adjust;
|
||||
Rect sprite_bounds;
|
||||
Rect shadow_bounds;
|
||||
u8 turret_angle;
|
||||
s8 turret_offset_x;
|
||||
s8 turret_offset_y;
|
||||
u16 total_images;
|
||||
u16 image_base;
|
||||
u16 turret_image_base;
|
||||
u16 firing_image_base;
|
||||
u16 connector_image_base;
|
||||
u16 image_index;
|
||||
u16 turret_image_index;
|
||||
u16 image_index_max;
|
||||
OrderType orders;
|
||||
u8 state;
|
||||
OrderType prior_orders;
|
||||
u8 prior_state;
|
||||
u8 laying_state;
|
||||
Point target_grid;
|
||||
u8 build_time;
|
||||
u8 total_mining;
|
||||
u8 raw_mining;
|
||||
u8 fuel_mining;
|
||||
u8 gold_mining;
|
||||
u8 raw_mining_max;
|
||||
u8 gold_mining_max;
|
||||
u8 fuel_mining_max;
|
||||
u8 hits;
|
||||
u8 speed;
|
||||
u8 shots;
|
||||
u8 move_and_fire;
|
||||
u16 storage;
|
||||
u8 ammo;
|
||||
u8 targeting_mode;
|
||||
u8 enter_mode;
|
||||
u8 cursor;
|
||||
u8 recoil_delay;
|
||||
u8 delayed_reaction;
|
||||
u8 damaged_this_turn;
|
||||
u8 research_topic;
|
||||
u8 moved;
|
||||
u8 bobbed;
|
||||
u8 shake_effect_state;
|
||||
u8 engine;
|
||||
u8 weapon;
|
||||
u8 comm;
|
||||
u8 fuel_distance;
|
||||
u8 move_fraction;
|
||||
u8 energized;
|
||||
u8 repeat_build;
|
||||
u16 build_rate;
|
||||
u8 disabled_reaction_fire;
|
||||
u8 auto_survey;
|
||||
u32 field_221;
|
||||
Path path;
|
||||
u16 connectors;
|
||||
UnitValues base_values;
|
||||
Complex complex;
|
||||
UnitInfo parent_unit;
|
||||
UnitInfo enemy_unit;
|
||||
UnitTypeArray build_list;
|
||||
}
|
||||
};
|
||||
|
||||
struct UnitInfoList
|
||||
{
|
||||
u16 unitinfo_count;
|
||||
UnitInfo units[unitinfo_count];
|
||||
};
|
||||
|
||||
struct HashMapUnitInfo
|
||||
{
|
||||
u16 hash_size;
|
||||
UnitInfoList map[hash_size];
|
||||
};
|
||||
|
||||
struct MapHash
|
||||
{
|
||||
Point coordinates;
|
||||
UnitInfoList units;
|
||||
};
|
||||
|
||||
struct MapHashList
|
||||
{
|
||||
u16 maphash_count;
|
||||
MapHash objects[maphash_count];
|
||||
};
|
||||
|
||||
struct HashMapMapHash
|
||||
{
|
||||
u16 hash_size;
|
||||
s16 x_shift;
|
||||
MapHashList map[hash_size];
|
||||
};
|
||||
|
||||
struct TeamHeatMaps
|
||||
{
|
||||
u8 heatmap_complete[12544];
|
||||
u8 heatmap_stealth_sea[12544];
|
||||
u8 heatmap_stealth_land[12544];
|
||||
};
|
||||
|
||||
struct MessageLog
|
||||
{
|
||||
s16 length;
|
||||
char text[length];
|
||||
UnitInfo unit;
|
||||
Point coordinates;
|
||||
bool is_alert_message;
|
||||
u16 resource_id;
|
||||
};
|
||||
|
||||
struct MessageLogList
|
||||
{
|
||||
u16 message_log_count;
|
||||
MessageLog entires[message_log_count];
|
||||
};
|
||||
|
||||
struct AiMap
|
||||
{
|
||||
UnitInfo unit;
|
||||
TeamIndex16 team;
|
||||
bool visible_to_team;
|
||||
Point point;
|
||||
};
|
||||
|
||||
struct AiMapList
|
||||
{
|
||||
u16 ai_map_count;
|
||||
AiMap objects[ai_map_count];
|
||||
};
|
||||
|
||||
struct AiPlayer
|
||||
{
|
||||
TeamIndex16 team;
|
||||
AiStrategy strategy;
|
||||
s16 field_3;
|
||||
s16 field_5;
|
||||
s16 field_7;
|
||||
TeamIndex16 target_team;
|
||||
AiMapList map_list;
|
||||
u16 has_info_map;
|
||||
|
||||
if (has_info_map)
|
||||
{
|
||||
u8 info_map[12544];
|
||||
}
|
||||
|
||||
u16 has_mine_map;
|
||||
|
||||
if (has_mine_map)
|
||||
{
|
||||
u8 mine_map[12544];
|
||||
}
|
||||
|
||||
Point target_location;
|
||||
};
|
||||
|
||||
u16 last_object_index;
|
||||
bool context;
|
||||
|
||||
fn Init()
|
||||
{
|
||||
context = false;
|
||||
last_object_index = 0;
|
||||
};
|
||||
|
||||
fn CheckObjectId(u16 index, bool caller)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
// ImHex bug workaround
|
||||
if (context) { context = false; return result; }
|
||||
|
||||
// null object?
|
||||
if (index == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// already serialized object?
|
||||
if (last_object_index < index)
|
||||
{
|
||||
last_object_index = index;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
struct SaveFile
|
||||
{
|
||||
Init();
|
||||
|
||||
s16 version;
|
||||
FileType save_file_type;
|
||||
char save_game_name[30];
|
||||
PlanetType planet;
|
||||
s16 mission_index;
|
||||
char team_name_red[30];
|
||||
char team_name_green[30];
|
||||
char team_name_blue[30];
|
||||
char team_name_gray[30];
|
||||
TeamType team_type_red;
|
||||
TeamType team_type_green;
|
||||
TeamType team_type_blue;
|
||||
TeamType team_type_gray;
|
||||
TeamType team_type_alien;
|
||||
TeamClan team_clan_red;
|
||||
TeamClan team_clan_green;
|
||||
TeamClan team_clan_blue;
|
||||
TeamClan team_clan_gray;
|
||||
TeamClan team_clan_alien;
|
||||
u32 rng_seed;
|
||||
OpponentType opponent;
|
||||
s16 turn_timer;
|
||||
s16 endturn;
|
||||
PlayMode play_mode;
|
||||
IniOptions options;
|
||||
SurfaceType surface_map[12544];
|
||||
GridResourceMapEntry GridResourceMap[12544];
|
||||
TeamInfo team_info_red;
|
||||
TeamInfo team_info_green;
|
||||
TeamInfo team_info_blue;
|
||||
TeamInfo team_info_gray;
|
||||
TeamIndex active_turn_team;
|
||||
TeamIndex player_team;
|
||||
s32 turn_counter;
|
||||
s16 game_state;
|
||||
u16 turn_timer_;
|
||||
IniPreferences preferences;
|
||||
TeamUnits team_units_red;
|
||||
TeamUnits team_units_green;
|
||||
TeamUnits team_units_blue;
|
||||
TeamUnits team_units_gray;
|
||||
UnitInfoList unit_info_list_ground_cover_units;
|
||||
UnitInfoList unit_info_list_mobile_land_sea_units;
|
||||
UnitInfoList unit_info_list_stationary_units;
|
||||
UnitInfoList unit_info_list_mobile_air_units;
|
||||
UnitInfoList unit_info_list_particles;
|
||||
HashMapUnitInfo hash_map_unit_info;
|
||||
HashMapMapHash hash_map_map_hash;
|
||||
|
||||
if (team_type_red != TeamType::None)
|
||||
{
|
||||
TeamHeatMaps heat_maps_red;
|
||||
}
|
||||
|
||||
if (team_type_green != TeamType::None)
|
||||
{
|
||||
TeamHeatMaps heat_maps_green;
|
||||
}
|
||||
|
||||
if (team_type_blue != TeamType::None)
|
||||
{
|
||||
TeamHeatMaps heat_maps_blue;
|
||||
}
|
||||
|
||||
if (team_type_gray != TeamType::None)
|
||||
{
|
||||
TeamHeatMaps heat_maps_gray;
|
||||
}
|
||||
|
||||
MessageLogList message_log_red;
|
||||
MessageLogList message_log_green;
|
||||
MessageLogList message_log_blue;
|
||||
MessageLogList message_log_gray;
|
||||
|
||||
if (team_type_red == TeamType::Computer)
|
||||
{
|
||||
AiPlayer ai_player_red;
|
||||
}
|
||||
|
||||
if (team_type_green == TeamType::Computer)
|
||||
{
|
||||
AiPlayer ai_player_green;
|
||||
}
|
||||
|
||||
if (team_type_blue == TeamType::Computer)
|
||||
{
|
||||
AiPlayer ai_player_blue;
|
||||
}
|
||||
|
||||
if (team_type_gray == TeamType::Computer)
|
||||
{
|
||||
AiPlayer ai_player_gray;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SaveFile save @ 0x0;
|
||||
|
||||
std::assert($ == std::mem::size(), "Extra data found after parsed data");
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
#pragma MIME audio/x-wav
|
||||
#pragma MIME audio/wav
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
BIN
tests/patterns/test_data/gb.hexpat.gb
Normal file
BIN
tests/patterns/test_data/gb.hexpat.gb
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/maxsave.dta
Normal file
BIN
tests/patterns/test_data/maxsave.dta
Normal file
Binary file not shown.
Reference in New Issue
Block a user