diff --git a/Cargo.lock b/Cargo.lock index c83c93f..566e7d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,7 +228,7 @@ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6" [[package]] name = "rs-runec" -version = "0.7.5" +version = "0.7.6" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index b9a60a2..49459a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rs-runec" -version = "0.7.5" +version = "0.7.6" edition = "2024" rust-version = "1.95.0" authors = ["Tyler Telis ", "RustCityRS "] diff --git a/src/opcodes.rs b/src/opcodes.rs index 99bd646..9d6c4a0 100644 --- a/src/opcodes.rs +++ b/src/opcodes.rs @@ -315,6 +315,27 @@ opcodes! { GETSOFTTIMER = 2190 => "getsofttimer"; CAM_FORCEANGLE = 2191 => "cam_forceangle"; SOUND_VORBIS = 2192 => "sound_vorbis"; + // 647 (2011): the Grand Exchange. The reads take the client's own names + // (its clientscript commands 3903-3913); buy, sell, abort, the guide + // price and the history are this compiler's, as no source names them. + STOCKMARKET_BUY = 2193 => "stockmarket_buy"; + STOCKMARKET_SELL = 2194 => "stockmarket_sell"; + STOCKMARKET_ABORT = 2195 => "stockmarket_abort"; + STOCKMARKET_GETOFFERTYPE = 2196 => "stockmarket_getoffertype"; + STOCKMARKET_GETOFFERITEM = 2197 => "stockmarket_getofferitem"; + STOCKMARKET_GETOFFERPRICE = 2198 => "stockmarket_getofferprice"; + STOCKMARKET_GETOFFERCOUNT = 2199 => "stockmarket_getoffercount"; + STOCKMARKET_GETOFFERCOMPLETEDCOUNT = 2200 => "stockmarket_getoffercompletedcount"; + STOCKMARKET_GETOFFERCOMPLETEDGOLD = 2201 => "stockmarket_getoffercompletedgold"; + STOCKMARKET_ISOFFEREMPTY = 2202 => "stockmarket_isofferempty"; + STOCKMARKET_ISOFFERSTABLE = 2203 => "stockmarket_isofferstable"; + STOCKMARKET_ISOFFERADDING = 2204 => "stockmarket_isofferadding"; + STOCKMARKET_ISOFFERFINISHED = 2205 => "stockmarket_isofferfinished"; + STOCKMARKET_GUIDEPRICE = 2206 => "stockmarket_guideprice"; + STOCKMARKET_GETHISTORYTYPE = 2207 => "stockmarket_gethistorytype"; + STOCKMARKET_GETHISTORYITEM = 2208 => "stockmarket_gethistoryitem"; + STOCKMARKET_GETHISTORYCOUNT = 2209 => "stockmarket_gethistorycount"; + STOCKMARKET_GETHISTORYGOLD = 2210 => "stockmarket_gethistorygold"; // Npc NPC_ADD = 2500 => "npc_add"; diff --git a/src/pointer.rs b/src/pointer.rs index 79dfcc4..72a51a3 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -1961,6 +1961,23 @@ fn build_command_pointers() -> HashMap { "sound_speech_volume", "sound_speech_stop", "stat_total", + "stockmarket_buy", + "stockmarket_sell", + "stockmarket_abort", + "stockmarket_getoffertype", + "stockmarket_getofferitem", + "stockmarket_getofferprice", + "stockmarket_getoffercount", + "stockmarket_getoffercompletedcount", + "stockmarket_getoffercompletedgold", + "stockmarket_isofferempty", + "stockmarket_isofferstable", + "stockmarket_isofferadding", + "stockmarket_isofferfinished", + "stockmarket_gethistorytype", + "stockmarket_gethistoryitem", + "stockmarket_gethistorycount", + "stockmarket_gethistorygold", "wealth_event", ] { add(name, &[ActivePlayer], &[], &[], &[], &[], &[], false); diff --git a/tests/server_pointer_test.rs b/tests/server_pointer_test.rs index bd9412f..6f252f7 100644 --- a/tests/server_pointer_test.rs +++ b/tests/server_pointer_test.rs @@ -45,6 +45,11 @@ fn project(check_pointers: bool) -> Project { ("p_objdialog", vec![], vec![]), ("p_hsldialog", vec![], vec![]), ("last_coord", vec![], vec![Coord]), + ("stockmarket_buy", vec![Int, Obj, Int, Int], vec![]), + ("stockmarket_abort", vec![Int], vec![]), + ("stockmarket_isofferstable", vec![Int], vec![Boolean]), + ("stockmarket_gethistorygold", vec![Int], vec![Int]), + ("stockmarket_guideprice", vec![Obj], vec![Int]), ]; for (opcode, (name, params, returns)) in commands.into_iter().enumerate() { registry.register_command(name.into(), 1000 + opcode as i32, params, returns); @@ -140,6 +145,32 @@ fn entity_commands_require_the_selected_player() { } } +/// The Grand Exchange's commands act on a player's own offers and history; its +/// guide price is the world's. +#[test] +fn stockmarket_commands_require_the_selected_player_but_not_the_guide_price() { + for command in [ + "stockmarket_buy(0, weapon, 1, 100)", + "stockmarket_abort(0)", + "def_boolean $b = stockmarket_isofferstable(0)", + "def_int $i = stockmarket_gethistorygold(0)", + ] { + for dot in ["", "."] { + let command = command.replacen("stockmarket", &format!("{dot}stockmarket"), 1); + let text = format!("[ai_timer,_]\n{command};\n"); + let warnings = pointer_warnings(&text); + assert!( + warnings + .iter() + .any(|warning| warning.contains(&format!("{dot}active_player"))), + "{text}: {warnings:?}" + ); + } + } + let warnings = pointer_warnings("[ai_timer,_]\ndef_int $i = stockmarket_guideprice(weapon);\n"); + assert!(warnings.is_empty(), "{warnings:?}"); +} + #[test] fn load_delay_requires_protected_player_access() { let warnings = pointer_warnings("[ai_timer,_]\np_loaddelay;\n");