Skip to content

Commit c4ca812

Browse files
committed
Various fixes and updates
1 parent 5861f3f commit c4ca812

File tree

15 files changed

+464
-461
lines changed

15 files changed

+464
-461
lines changed

Cargo.lock

Lines changed: 386 additions & 437 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rs3cache_backend/src/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Archive {
153153

154154
let files_length = buffer.get_u16();
155155

156-
let mut headers = buffer.split_to((files_length * 10).try_into().unwrap());
156+
let mut headers = buffer.split_to((files_length * 10).into());
157157
let mut archive = Archive {
158158
index_id: metadata.index_id(),
159159
archive_id: metadata.archive_id(),

rs3cache_backend/src/buf.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ pub enum ReadError {
2323
location: &'static Location<'static>,
2424
terminator: u8,
2525
},
26-
#[error = "reached the end of the buffer unexpectedly"]
26+
#[error = "the buffer was not exhausted: {remainder:?} left."]
2727
NotExhausted {
2828
#[location]
2929
location: &'static Location<'static>,
30-
remainder: usize,
30+
remainder: Bytes,
3131
},
3232
#[error = "opcode {opcode} is not implemented"]
3333
OpcodeNotImplemented {
@@ -307,12 +307,26 @@ impl<R: Buf> Serialize for JString<R> {
307307
}
308308
}
309309

310-
#[derive(Clone, Debug)]
310+
#[derive(Clone)]
311311
pub enum JStringKind<R: Buf> {
312312
Refcounted { buf: R, len: usize },
313313
Allocated(String),
314314
}
315315

316+
impl<R: ::core::fmt::Debug + Buf> ::core::fmt::Debug for JStringKind<R> {
317+
#[inline]
318+
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
319+
match self {
320+
JStringKind::Refcounted { buf, len } => f
321+
.debug_struct("Refcounted")
322+
.field("buf", &&buf.chunk()[..*len])
323+
.field("len", len)
324+
.finish(),
325+
JStringKind::Allocated(s) => f.debug_tuple("Allocated").field(s).finish(),
326+
}
327+
}
328+
}
329+
316330
impl<R: Buf> JString<R> {
317331
/// # Safety
318332
///

rs3cache_backend/src/index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::{
2323
#[cfg_attr(feature = "dat", path = "index/dat.rs")]
2424
mod index_impl;
2525

26+
#[allow(unused_imports)]
2627
pub use index_impl::*;
2728

2829
mod states {

rs3cache_backend/src/index/dat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use crate::{
1212
buf::{BufExtra, FileSeek},
1313
decoder,
1414
error::{self, CacheResult, CannotOpen},
15-
index::*,
15+
index::{ArchiveMissingNamed, CacheIndex, IndexState, Initial},
1616
meta::{IndexMetadata, Metadata},
17+
path::CachePath,
1718
};
1819
impl<S> CacheIndex<S>
1920
where

rs3cache_backend/src/index/dat2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
buf::{BufExtra, FileSeek},
1414
decoder,
1515
error::{self, CacheResult, CannotOpen},
16-
index::*,
16+
index::{ArchiveMissing, ArchiveMissingNamed, CacheIndex, CachePath, IndexState, Initial},
1717
meta::{IndexMetadata, Metadata},
1818
xtea::Xtea,
1919
};

rs3cache_backend/src/xtea.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{collections::HashMap, fs::File, io::BufReader, path::Path};
44

55
use ::error::Context;
66
use serde::{Deserialize, Serialize};
7-
use serde_json;
87

98
use crate::error::{self, CacheResult};
109

src/definitions/dbrows.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct DbRow {
1919
/// Its id.
2020
pub id: u32,
2121
pub unknown_1: Option<bool>,
22-
pub content_type: Option<u8>,
22+
pub content_type: Option<u16>,
2323
pub data: Option<Vec<Vec<Value>>>,
2424
}
2525

@@ -43,7 +43,18 @@ impl DbRow {
4343
let mut opcodes = Vec::new();
4444

4545
loop {
46-
let opcode = buffer.try_get_u8()?;
46+
let opcode = match buffer.try_get_u8() {
47+
Ok(o) => o,
48+
Err(e) => {
49+
return Err(Box::new(e)).context(WithInfo {
50+
#[cfg(debug_assertions)]
51+
opcodes,
52+
buffer,
53+
#[cfg(debug_assertions)]
54+
thing: obj.to_string(),
55+
})
56+
}
57+
};
4758

4859
#[cfg(debug_assertions)]
4960
opcodes.push(opcode);
@@ -52,7 +63,7 @@ impl DbRow {
5263
match opcode {
5364
0 => {
5465
if buffer.has_remaining() {
55-
return Err(NotExhausted::new(buffer.remaining()));
66+
return Err(NotExhausted::new(buffer));
5667
} else {
5768
break Ok(obj);
5869
}
@@ -71,7 +82,7 @@ impl DbRow {
7182

7283
let _subobjects = vec![Value::Null; count * amount];
7384
for _c in 0..count {
74-
for (_pos, ty) in types.iter().enumerate() {
85+
for ty in &types {
7586
match ty {
7687
35 => {
7788
buffer.try_get_array::<8>()?;
@@ -89,7 +100,7 @@ impl DbRow {
89100
}
90101
}
91102
}
92-
4 => obj.content_type = Some(buffer.try_get_u8()?),
103+
4 => obj.content_type = Some(buffer.try_get_unsigned_smart()?),
93104
opcode => Err(ReadError::OpcodeNotImplemented {
94105
location: Location::caller(),
95106
opcode,
@@ -102,7 +113,7 @@ impl DbRow {
102113
opcodes.push(opcode);
103114
}
104115
Err(e) => {
105-
return Err(e).map_err(Box::new).context(WithInfo {
116+
return Err(Box::new(e)).context(WithInfo {
106117
#[cfg(debug_assertions)]
107118
opcodes,
108119
buffer,

src/definitions/location_configs.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl LocationConfig {
235235
match opcode {
236236
0 => {
237237
if buffer.has_remaining() {
238-
return Err(NotExhausted::new(buffer.remaining()));
238+
return Err(NotExhausted::new(buffer));
239239
} else {
240240
break Ok(loc);
241241
}
@@ -391,7 +391,10 @@ impl LocationConfig {
391391
loc.unknown_204 = Some(out)
392392
}
393393
249 => loc.params = Some(ParamTable::deserialize(&mut buffer)),
394-
opcode => do yeet OpcodeNotImplemented::new(opcode),
394+
opcode => {
395+
println!("{loc}");
396+
do yeet OpcodeNotImplemented::new(opcode)
397+
}
395398
}
396399
};
397400
match read {
@@ -400,7 +403,7 @@ impl LocationConfig {
400403
opcodes.push(opcode);
401404
}
402405
Err(e) => {
403-
return Err(e).map_err(Box::new).context(WithInfo {
406+
return Err(Box::new(e)).context(WithInfo {
404407
#[cfg(debug_assertions)]
405408
opcodes,
406409
buffer,
@@ -701,6 +704,10 @@ pub mod location_config_fields {
701704
let unknown_1 = buffer.try_get_u16()?;
702705
let unknown_2 = buffer.try_get_u16()?;
703706
let unknown_3 = buffer.try_get_u8()?;
707+
if cfg!(features = "osrs") {
708+
//FIXME: Post rev 220
709+
let _sound_retain = buffer.try_get_u8()?;
710+
}
704711

705712
let count = buffer.try_get_u8()? as usize;
706713

@@ -772,6 +779,10 @@ pub mod location_config_fields {
772779
pub fn deserialize(buffer: &mut Bytes) -> Result<Self, ReadError> {
773780
let unknown_1 = buffer.try_get_u16()?;
774781
let unknown_2 = buffer.try_get_u8()?;
782+
if cfg!(feature = "osrs") {
783+
// FIXME: Post rev 220
784+
let _sound_retain = buffer.try_get_u8()?;
785+
}
775786

776787
Ok(Self { unknown_1, unknown_2 })
777788
}

src/definitions/npc_configs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ pub struct NpcConfig {
130130
pub unknown_180: Option<u8>,
131131
pub unknown_182: Option<bool>,
132132
pub unknown_184: Option<u16>,
133+
#[cfg(feature = "rs3")]
134+
pub unknown_185: Option<u8>,
135+
#[cfg(feature = "rs3")]
136+
pub unknown_253: Option<u8>,
133137
#[serde(flatten)]
134138
pub params: Option<ParamTable>,
135139
}
@@ -285,7 +289,11 @@ impl NpcConfig {
285289
181 => unimplemented!(),
286290
182 => npc.unknown_182 = Some(true),
287291
184 => npc.unknown_184 = Some(buffer.get_unsigned_smart()),
292+
#[cfg(feature = "rs3")]
293+
185 => npc.unknown_185 = Some(buffer.get_u8()),
288294
249 => npc.params = Some(ParamTable::deserialize(&mut buffer)),
295+
#[cfg(feature = "rs3")]
296+
253 => npc.unknown_253 = Some(buffer.get_u8()),
289297
missing => {
290298
unimplemented!("NpcConfig::deserialize cannot deserialize opcode {} in npc: \n {}\n", missing, npc)
291299
}

src/definitions/tiles.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(unused_imports)]
12
use bytes::{Buf, Bytes};
23
use ndarray::{Array, ArrayBase, Dim, OwnedRepr};
34
#[cfg(feature = "pyo3")]
@@ -28,13 +29,19 @@ pub struct Tile {
2829
pub underlay_id: Option<u16>,
2930

3031
/// The height of the tile.
31-
pub height: Option<u8>,
32+
// Before 936 this used to be a u8
33+
pub height: Option<u16>,
3234
}
3335

3436
impl Tile {
3537
/// Constructor for a sequence of [`Tile`]s.
3638
#[cfg(any(feature = "rs3", feature = "2013_shim"))]
3739
pub fn dump(buffer: &mut Bytes) -> TileArray {
40+
let is_936 = &buffer[0..5] == b"jagx\x01";
41+
if is_936 {
42+
buffer.advance(5)
43+
}
44+
3845
Array::from_shape_simple_fn((4, 64, 64), || {
3946
let mut tile = Tile::default();
4047

@@ -54,7 +61,8 @@ impl Tile {
5461
}
5562

5663
if flag_4 {
57-
tile.height = Some(buffer.get_u8());
64+
// Before 936 this used to be a u8
65+
tile.height = Some(if is_936 { buffer.get_u16() } else { buffer.get_u8() as _ });
5866
}
5967

6068
tile
@@ -97,7 +105,7 @@ impl Tile {
97105
match opcode {
98106
0 => break tile,
99107
1 => {
100-
tile.height = Some(buffer.try_get_u8()?);
108+
tile.height = Some(buffer.try_get_u8()? as u16);
101109
break tile;
102110
}
103111
opcode @ 2..=49 => {
@@ -120,7 +128,7 @@ impl Tile {
120128
if buffer.is_empty() {
121129
ret
122130
} else {
123-
Err(rs3cache_backend::buf::NotExhausted::new(buffer.remaining()))
131+
Err(rs3cache_backend::buf::NotExhausted::new(buffer))
124132
}
125133
}
126134
}

src/definitions/worldmaps.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//!
2-
31
use std::{
42
collections::{BTreeMap, HashMap},
53
fs::{self, File},

src/renderers/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
},
3636
renderers::{scale, zoom},
3737
};
38-
///
38+
3939
pub struct RenderConfig {
4040
/// -1 is the "real" world map.
4141
pub map_id: i32,

src/renderers/map/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub fn put(
9999
51 => (118, 80, 37),
100100
91 => (171, 176, 181),
101101
119 => (50, 48, 44),
102+
120 => (6, 4, 4),
103+
121 | 122 => (87, 70, 62),
104+
125 | 126 => (50, 44, 36),
102105
unknown => unimplemented!("unimplemented texture id {}", unknown),
103106
};
104107
let fill = Rgba([red, green, blue, 255]);

0 commit comments

Comments
 (0)