{"id":20139670,"url":"https://github.com/livesplit/asr","last_synced_at":"2025-04-09T18:23:00.298Z","repository":{"id":45752810,"uuid":"499245355","full_name":"LiveSplit/asr","owner":"LiveSplit","description":"Helper crate to write auto splitters for LiveSplit One's auto splitting runtime.","archived":false,"fork":false,"pushed_at":"2025-03-30T21:33:52.000Z","size":344,"stargazers_count":10,"open_issues_count":5,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T22:26:59.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://livesplit.org/asr/asr","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiveSplit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-02T18:24:01.000Z","updated_at":"2025-03-30T21:33:56.000Z","dependencies_parsed_at":"2023-12-01T15:26:19.724Z","dependency_job_id":"f82a3b9b-6c16-4a66-b499-e1461a3b7b97","html_url":"https://github.com/LiveSplit/asr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiveSplit%2Fasr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiveSplit%2Fasr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiveSplit%2Fasr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiveSplit%2Fasr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiveSplit","download_url":"https://codeload.github.com/LiveSplit/asr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085902,"owners_count":21045235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T21:46:37.371Z","updated_at":"2025-04-09T18:23:00.259Z","avatar_url":"https://github.com/LiveSplit.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"https://raw.githubusercontent.com/LiveSplit/LiveSplit/master/res/Icon.svg\" alt=\"LiveSplit\" height=\"42\" width=\"45\" align=\"top\"/\u003e asr\n\n\nHelper crate to write auto splitters for LiveSplit One's auto splitting\nruntime.\n\n[API Documentation](https://livesplit.org/asr/asr/)\n\nThere are two ways of defining an auto splitter.\n\n## Defining an `update` function\n\nYou can define an `update` function that will be called every frame. This is\nthe simplest way to define an auto splitter. The function must have the\nfollowing signature:\n```rust\n#[no_mangle]\npub extern \"C\" fn update() {}\n```\n\nThe advantage of this approach is that you have full control over what\nhappens on every tick of the runtime. However, it's much harder to keep\nstate around as you need to store all state in global variables as you need\nto return out of the function on every tick.\n\n### Example\n\n```rust\n#[no_mangle]\npub extern \"C\" fn update() {\n    if let Some(process) = Process::attach(\"explorer.exe\") {\n        asr::print_message(\"Hello World!\");\n        if let Ok(address) = process.get_module_address(\"explorer.exe\") {\n            if let Ok(value) = process.read::\u003cu32\u003e(address) {\n                if value \u003e 0 {\n                    asr::timer::start();\n                }\n            }\n        }\n    }\n}\n```\n\n## Defining an asynchronous `main` function\n\nYou can use the `async_main` macro to define an asynchronous `main`\nfunction.\n\nSimilar to using an `update` function, it is important to constantly yield\nback to the runtime to communicate that the auto splitter is still alive.\nAll asynchronous code that you await automatically yields back to the\nruntime. However, if you want to write synchronous code, such as the main\nloop handling of a process on every tick, you can use the\n`next_tick` function to yield back to the runtime and\ncontinue on the next tick.\n\nThe main low level abstraction is the `retry` function, which wraps any code\nthat you want to retry until it succeeds, yielding back to the runtime between\neach try.\n\nSo if you wanted to attach to a Process you could for example write:\n\n```rust\nlet process = retry(|| Process::attach(\"MyGame.exe\")).await;\n```\n\nThis will try to attach to the process every tick until it succeeds. This\nspecific example is exactly how the `Process::wait_attach` method is\nimplemented. So if you wanted to attach to any of multiple processes, you could\nfor example write:\n\n```rust\nlet process = retry(|| {\n   [\"a.exe\", \"b.exe\"].into_iter().find_map(Process::attach)\n}).await;\n```\n\n### Example\n\nHere is a full example of how an auto splitter could look like using the\n`async_main` macro:\n\nUsage on stable Rust:\n```rust\nasync_main!(stable);\n```\n\nUsage on nightly Rust:\n```rust\n#![feature(type_alias_impl_trait, const_async_blocks)]\n\nasync_main!(nightly);\n```\n\nThe asynchronous main function itself:\n```rust\nasync fn main() {\n    // TODO: Set up some general state and settings.\n    loop {\n        let process = Process::wait_attach(\"explorer.exe\").await;\n        process.until_closes(async {\n            // TODO: Load some initial information from the process.\n            loop {\n                // TODO: Do something on every tick.\n               next_tick().await;\n            }\n        }).await;\n    }\n}\n```\n\n## License\n\nLicensed under either of\n  * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n    http://www.apache.org/licenses/LICENSE-2.0)\n  * MIT license ([LICENSE-MIT](LICENSE-MIT) or\n    http://opensource.org/licenses/MIT) at your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you shall be dual licensed as above, without any\nadditional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivesplit%2Fasr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivesplit%2Fasr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivesplit%2Fasr/lists"}