Add patch for play code changes.

This commit is contained in:
yukirij 2024-10-04 20:32:08 -07:00
parent cf365a9e2a
commit 08686670d8
3 changed files with 34 additions and 7 deletions

View File

@ -144,6 +144,12 @@ impl Game {
} else { false } } else { false }
} }
// Player retired.
0xF => {
self.status = GameStatus::Resign;
true
}
_ => false, _ => false,
} { } {
self.history.push(*play); self.history.push(*play);

View File

@ -87,10 +87,6 @@ impl App {
// Load session history // Load session history
if let Ok(history) = filesystem.session_history_fetch(id as u32) { if let Ok(history) = filesystem.session_history_fetch(id as u32) {
let mut history = history;
for play in &mut history {
if play.source == 3 { play.source = 2; }
}
session.game.apply_history(&history).ok(); session.game.apply_history(&history).ok();
} }

View File

@ -253,7 +253,7 @@ impl FileSystem {
.join(format!("{:08x}", dir_index)); .join(format!("{:08x}", dir_index));
// Open session history file // Open session history file
if let Ok(mut file) = File::options().read(true).open(bucket_path.join(GENERIC_HISTORY)) { if let Ok(mut file) = File::options().write(true).read(true).open(bucket_path.join(GENERIC_HISTORY)) {
// Read history length // Read history length
let mut buffer = [0u8; 2]; let mut buffer = [0u8; 2];
@ -265,11 +265,36 @@ impl FileSystem {
for _ in 0..length { for _ in 0..length {
file.read_exact(&mut buffer).map_err(|_| ())?; file.read_exact(&mut buffer).map_err(|_| ())?;
let data = unpack_u16(&buffer, &mut 0); let data = unpack_u16(&buffer, &mut 0);
result.push(Play {
let mut play = Play {
source:(data & 0xF) as u8, source:(data & 0xF) as u8,
from:((data >> 4) & 0x3F) as u8, from:((data >> 4) & 0x3F) as u8,
to:((data >> 10) & 0x3F) as u8, to:((data >> 10) & 0x3F) as u8,
}); };
match play.source {
2 => {
play.source = 0xF;
file.seek(SeekFrom::Current(-2)).map_err(|_| ())?;
file.write(&mut pack_u16(
play.source as u16
| ((play.from as u16) << 4)
| ((play.to as u16) << 10)
)).map_err(|_| ())?;
}
3 => {
play.source = 2;
file.seek(SeekFrom::Current(-2)).map_err(|_| ())?;
file.write(&mut pack_u16(
play.source as u16
| ((play.from as u16) << 4)
| ((play.to as u16) << 10)
)).map_err(|_| ())?;
}
_ => { }
}
result.push(play);
} }
Ok(result) Ok(result)