From 15d3fbf0a4dfbae6a8c4df430f0ab278a6aad240 Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Mon, 4 Mar 2024 21:27:03 +0100 Subject: [PATCH] Initial public release --- .github/workflows/release.yml | 32 + .gitignore | 2 + Cargo.toml | 13 + build.rs | 45 + src/lib.rs | 1 + src/xtlid.xml | 1650 +++++++++++++++++++++++++++++++++ 6 files changed, 1743 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 src/lib.rs create mode 100644 src/xtlid.xml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8fdac25 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get version from Cargo.toml + id: get_version + run: echo VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="xtlid") | .version') >> $GITHUB_ENV + + - name: Log in to crates.io + run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + + - name: Publish crate + run: cargo publish + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.VERSION }} + files: src/xtlid.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ccdf63 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/src/xtlid.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..02bd0ec --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "xtlid" +version = "0.1.1" +authors = ["Stefan Schmidt"] +edition = "2021" +license = "MIT" +description = "Provides a mapping of IDs to function names for .XTLID-sections found in Xbox executables" + +[dependencies] +phf = {version= " 0.11.2", features = ["macros"]} + +[build-dependencies] +xmltree = "0.10" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ff9a874 --- /dev/null +++ b/build.rs @@ -0,0 +1,45 @@ +use std::fs; +use std::{env, path::Path}; +use xmltree::Element; + +fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("xtlid.rs"); + + let input = fs::read_to_string("src/xtlid.xml").unwrap(); + let xtlid_element = Element::parse(input.as_bytes()).unwrap(); + + let mut output = String::new(); + + output.push_str("use phf::phf_map;\n\n"); + output.push_str("pub static XTLIDS: phf::Map = phf_map! {\n"); + + for lib_node in xtlid_element.children.iter() { + match lib_node { + xmltree::XMLNode::Element(child_element) => { + if child_element.name == "lib" { + for func_node in child_element.children.iter() { + match func_node { + xmltree::XMLNode::Element(func_node) => { + if func_node.name == "func" { + let id = func_node.attributes.get("id").unwrap(); + let name = func_node.attributes.get("name").unwrap(); + output.push_str(&format!(" {}u32 => \"{}\",\n", id, name)); + } + } + _ => {} + } + } + } + } + _ => {} + } + } + + output.push_str("};\n"); + + fs::write(dest_path, output).unwrap(); + + println!("cargo:rerun-if-changed=src/xtlid.xml"); + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..dbedd98 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/xtlid.rs")); diff --git a/src/xtlid.xml b/src/xtlid.xml new file mode 100644 index 0000000..c29876f --- /dev/null +++ b/src/xtlid.xml @@ -0,0 +1,1650 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +