Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rs-runec"
version = "0.6.1"
version = "0.7.0"
edition = "2024"
rust-version = "1.95.0"
authors = ["Tyler Telis <xlitersps@gmail.com>", "RustCityRS <https://github.com/RustCityRS>"]
Expand Down
51 changes: 40 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# RuneScape Compiler (runec)

`runec` compiles RuneScript (`.rs2`) for the server and ClientScript (`.cs2`)
for the client. GlobalScript (`.gs2`) holds code shared by both. It also provides
an editor language server and a Rust library with ClientScript decompilation.
for the client. GlobalScript (`.gs2`) holds code shared by both. LobbyScript
(`.ls2`) is compiled on its own for a lobby server. It also provides an editor
language server and a Rust library with ClientScript decompilation.

The examples assume `runec` is installed and on your `PATH`. Run commands from
your project's root directory and adjust the source, pack and output paths to
Expand All @@ -31,33 +32,37 @@ content/
├── scripts/
│ ├── engine.rs2
│ ├── engine.cs2
│ ├── engine.ls2
│ ├── interface_bank/
│ │ ├── scripts/bank.rs2
│ │ ├── client/bank.cs2
│ │ └── global/bank.gs2
│ ├── skill_combat/
│ ├── lobby/friends.ls2
│ └── quests/
└── pack/ # script IDs, command opcodes and named assets
```

Discovery searches the whole scripts root recursively. File extensions select
the target: `.rs2` runs on the server, `.cs2` on the client, and `.gs2` is compiled
for both. Folder names have no effect. Each file can contain multiple scripts.
for both. `.ls2` runs on the lobby server, which compiles only `.ls2` and never
`.gs2`. Folder names have no effect. Each file can contain multiple scripts.
Keep existing feature names and nested source/config folders when adding client
or shared scripts to a server project.
Existing `runescript`, `clientscript` and `globalscript` folders still work;
passing one of those paths resolves to its ancestor `scripts` root.

Configs and constants are shared by default. To restrict a file, put
`// @scope(server)` or `// @scope(client)` in its leading comments.
`// @scope(shared)` states the default explicitly. This ownership travels with
`// @scope(server)`, `// @scope(client)` or `// @scope(lobby)` in its leading
comments. `// @scope(shared)` states the default explicitly. This ownership travels with
the file when it moves. Shared scripts can only use shared definitions; each
target can also use its own private definitions. Script ownership always comes
from the extension.
from the extension. LobbyScript uses shared configs and constants but no `.gs2`
procs, and other targets cannot use `.ls2` scripts.

Your project supplies the engine commands, asset names and script IDs.
`engine.rs2` and `engine.cs2` declare command parameters and return types. They
can be anywhere under the root; duplicate engine files are an error.
`engine.rs2`, `engine.cs2` and `engine.ls2` declare command parameters and return
types. They can be anywhere under the root; duplicate engine files are an error.
Client commands follow their declared argument order. A command whose first
`component` parameter is evaluated last uses `@stack(component_last)`:

Expand All @@ -84,6 +89,7 @@ The pack directory maps names to IDs:
| Files | Purpose |
|---|---|
| `command.pack` | Server command opcodes; server script IDs are generated in memory |
| `ls2_command.pack` | Lobby command opcodes, in the `command.pack` format |
| `cs2_command.pack` and `clientscript.pack` | Client opcodes and script IDs |
| Other packs, such as `obj.pack` and `inv.pack` | Named assets and game data |

Expand Down Expand Up @@ -123,6 +129,24 @@ Keep explicit ID entries when renaming scripts. For example, renaming
`clientscript_1465` to `bank_refresh` requires `1465=[proc,bank_refresh]` in
`clientscript.pack` to preserve that client's script ID.

## Compile lobby scripts

```bash
runec compile-lobby --source content/scripts --pack content/pack --output data/lobby
```

This reads only the `.ls2` scripts and writes `script.dat` and `script.idx` in the
server format, with script IDs of their own. Lobby commands come from
`ls2_command.pack`, with signatures in `engine.ls2`; commands listed only in
`command.pack` do not resolve. Lobby scripts
accept only the `proc`, `label`, `login`, `logout`, `if_button`, `if_button1` to
`if_button10`, `if_buttond` and `if_close` triggers, and cannot use the secondary
player (`.command`, `.%var` or commands that need `.active_player`). Each is a
compile error. `compile-lobby` takes the same flags as `compile`; without
`--output`, lobby output goes to `./data/pack/lobby`.
`runec lint-lobby --source content/scripts --pack content/pack` checks lobby
scripts without writing output.

## Check server scripts

```bash
Expand All @@ -144,6 +168,7 @@ Use `--help` for all available options:
runec --help
runec compile --help
runec compile-client --help
runec compile-lobby --help
runec lsp --help
```

Expand Down Expand Up @@ -200,7 +225,8 @@ runec lsp --source content/scripts --pack content/pack
```

It loads separate server and client analysis contexts from the available engine
files. Shared scripts are checked against both. Use `--server` or `--client` to
files, and a lobby context when `engine.ls2` exists. Shared scripts are checked
against the server and client. Use `--server`, `--client` or `--lobby` to
restrict a process to one target when needed.

If the editor has separate fields for the executable and arguments, use `runec`
Expand All @@ -212,13 +238,14 @@ With `--source`, only that revision's scripts tree, packs and supported
cache asset folders belong to the server. Files from other revisions opened by
project-wide search are ignored, so their script names cannot create duplicates.

Map all three script extensions to this server:
Map all four script extensions to this server:

| File pattern | Language ID |
|---|---|
| `*.rs2` | `rs2` |
| `*.cs2` | `cs2` |
| `*.gs2` | `gs2` |
| `*.ls2` | `ls2` |

The language server provides diagnostics, completion, hover, definitions,
references, rename, syntax highlighting, signature help, inlay hints, formatting,
Expand Down Expand Up @@ -344,7 +371,9 @@ Use [Project](src/project.rs) to manage source documents in memory:

The host supplies a [SymbolRegistry](src/symbol.rs) and owns storage and script
ID persistence. [EngineProfile](src/environment.rs) describes engine-specific
triggers and pointer rules.
triggers and pointer rules. `Target::Lobby` compiles `Scope::Lobby` documents to
server bytecode; a lobby server compiles its scripts tree with
`compile_lobby_memory_with_ids`.

For ClientScript tools, use [Format](src/clientscript/format.rs) for opcode
mappings, [Script::decode](src/clientscript/decode.rs) for binary decoding, and
Expand Down
12 changes: 6 additions & 6 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub enum Opcode {
Gosub = opcodes::GOSUB,
Jump = opcodes::JUMP,
Switch = opcodes::SWITCH,
PushVarbit = opcodes::PUSH_VARBIT,
PopVarbit = opcodes::POP_VARBIT,
PushVarpBit = opcodes::PUSH_VARPBIT,
PopVarpBit = opcodes::POP_VARPBIT,
BranchLessThanOrEquals = opcodes::BRANCH_LESS_THAN_OR_EQUALS,
BranchGreaterThanOrEquals = opcodes::BRANCH_GREATER_THAN_OR_EQUALS,
PushIntLocal = opcodes::PUSH_INT_LOCAL,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Opcode {
match category {
"varn" => Self::PushVarn,
"vars" => Self::PushVars,
"varpbit" => Self::PushVarbit,
"varpbit" => Self::PushVarpBit,
"varc" => Self::PushVarcInt,
"varcstr" => Self::PushVarcString,
"varclan" => Self::PushVarClan,
Expand All @@ -153,7 +153,7 @@ impl Opcode {
match category {
"varn" => Self::PopVarn,
"vars" => Self::PopVars,
"varpbit" => Self::PopVarbit,
"varpbit" => Self::PopVarpBit,
"varc" => Self::PopVarcInt,
"varcstr" => Self::PopVarcString,
"varclan" => Self::PopVarClan,
Expand All @@ -180,8 +180,8 @@ impl Opcode {
"PopVarn" => Some(Self::PopVarn),
"PushVars" => Some(Self::PushVars),
"PopVars" => Some(Self::PopVars),
"PushVarbit" => Some(Self::PushVarbit),
"PopVarbit" => Some(Self::PopVarbit),
"PushVarpBit" => Some(Self::PushVarpBit),
"PopVarpBit" => Some(Self::PopVarpBit),
"PushVarcInt" => Some(Self::PushVarcInt),
"PopVarcInt" => Some(Self::PopVarcInt),
"PushVarcString" => Some(Self::PushVarcString),
Expand Down
2 changes: 1 addition & 1 deletion src/clientscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod format;
pub(crate) mod hooks;
pub(crate) mod triggers;
use format::{Format, Width};
pub use hooks::{HookValue, component_hook};
pub use hooks::{HookArg, component_hook};

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CommandKind {
Expand Down
7 changes: 3 additions & 4 deletions src/clientscript/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use std::io::Result;
pub struct Script {
pub name: String,
pub local_int_count: u16,
pub local_string_count: u16,
pub local_obj_count: u16,
pub local_long_count: u16,
pub int_param_count: u16,
pub string_param_count: u16,
pub long_param_count: u16,
/// Physical opcode IDs are retained for disassembly and lossless output.
pub opcodes: Vec<u16>,
pub operations: Vec<Opcode>,
pub int_operands: Vec<i32>,
Expand Down Expand Up @@ -177,7 +176,7 @@ impl Script {
let mut script = Self {
name: code.string()?,
local_int_count: counts[0][0],
local_string_count: counts[0][1],
local_obj_count: counts[0][1],
local_long_count: counts[0][2],
int_param_count: counts[1][0],
string_param_count: counts[1][1],
Expand Down Expand Up @@ -234,7 +233,7 @@ impl Script {
}
let local = match operation {
Opcode::PushIntLocal | Opcode::PopIntLocal => Some(script.local_int_count),
Opcode::PushStringLocal | Opcode::PopStringLocal => Some(script.local_string_count),
Opcode::PushStringLocal | Opcode::PopStringLocal => Some(script.local_obj_count),
Opcode::PushLongLocal | Opcode::PopLongLocal => Some(script.local_long_count),
_ => None,
};
Expand Down
10 changes: 5 additions & 5 deletions src/clientscript/decompile/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::source::script_name;
use crate::arguments::{
command_hints, command_parameters, command_returns, expression_types, proc_hints, stack_hints,
};
use crate::clientscript::hooks::{self, HookValue};
use crate::clientscript::hooks::{self, HookArg};
use crate::parser::{
BinOp, Expr, ScriptDeclaration, ScriptFile, Statement, StringPart, array_name,
};
Expand Down Expand Up @@ -679,7 +679,7 @@ pub fn hook_literal(
/// The scripts' types, and what each variable they use turned out to be.
pub fn infer(
files: &[(u32, ScriptFile)],
component_hooks: &[Vec<HookValue>],
component_hooks: &[Vec<HookArg>],
registry: &SymbolRegistry,
) -> (HashMap<u32, Inferred>, Vec<(String, Type)>) {
let mut inference = Inference {
Expand Down Expand Up @@ -759,16 +759,16 @@ pub fn infer(
})
.collect();
for hook in component_hooks {
if let Some(HookValue::Int(script)) = hook.first()
if let Some(HookArg::Int(script)) = hook.first()
&& let Some(key) = keys.get(script)
{
let callee = inference.scopes[key].clone();
let values: Vec<_> = hook[1..]
.iter()
.map(|value| {
let ty = match value {
HookValue::String(_) => Type::String,
HookValue::Int(value) => event_name(*value, registry)
HookArg::String(_) => Type::String,
HookArg::Int(value) => event_name(*value, registry)
.and_then(event_type)
.unwrap_or(Type::Int),
};
Expand Down
Loading
Loading