-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial serverlist editor, without saving
- Loading branch information
Showing
13 changed files
with
427 additions
and
111 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use std::mem::size_of; | ||
|
||
use crate::structs::ServerList; | ||
|
||
pub const SERVERLIST_KEY_LEN: usize = 63; | ||
|
||
pub const SERVERLIST_KEY: [u8; SERVERLIST_KEY_LEN] = [ | ||
0xc1, 0xb6, 0xc0, 0xcc, 0xc0, 0xd3, 0xc6, 0xd1, 0xc6, 0xae, 0xbe, 0xcf, 0xc8, 0xa3, 0xc8, 0xad, | ||
0xc0, 0xdb, 0xbe, 0xf7, 0xc0, 0xbb, 0xc0, 0xa7, 0xc7, 0xd1, 0xbd, 0xba, 0xc5, 0xa9, 0xb8, 0xb3, | ||
0xc6, 0xae, 0xc0, 0xd4, 0xb4, 0xcf, 0xb4, 0xd9, 0xb8, 0xb8, 0xc7, 0xd1, 0xb1, 0xdb, 0xb7, 0xce, | ||
0xbe, 0xcf, 0xc8, 0xad, 0xc8, 0xad, 0xc7, 0xd2, 0xc1, 0xd9, 0xa4, 0xbb, 0xa4, 0xbb, 0x00, | ||
]; | ||
|
||
pub const SERVER_LIST_SIZE: usize = size_of::<ServerList>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::consts::{SERVERLIST_KEY, SERVERLIST_KEY_LEN}; | ||
|
||
pub fn server_list(buf: &mut [u8]) -> bool { | ||
for i in 0..10 { | ||
for j in 0..11 { | ||
for k in (64 - SERVERLIST_KEY_LEN)..64 { | ||
let buf_index = 704 * i + 64 * j + k; | ||
let key_index = 63 - k; | ||
|
||
match buf.get_mut(buf_index) { | ||
Some(buf_value) => match SERVERLIST_KEY.get(key_index) { | ||
Some(key_value) => { | ||
*buf_value = ((*buf_value as i16) - (*key_value as i16)) as u8; | ||
} | ||
|
||
None => { | ||
println!("Server list invalid key index: {}", key_index); | ||
return false; | ||
} | ||
}, | ||
|
||
None => { | ||
println!("Server list invalid buf index: {}", buf_index); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
use egui::{Button, ScrollArea, Ui}; | ||
use egui_extras::{Size, StripBuilder}; | ||
use rfd::FileDialog; | ||
use std::{fs::File, io::Read, path::PathBuf, sync::Mutex}; | ||
|
||
use self::server_list::ServerListEditor; | ||
|
||
pub mod server_list; | ||
|
||
#[derive(Default, Clone)] | ||
enum EditorSelected { | ||
#[default] | ||
None, | ||
ServerList(ServerListEditor), | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Editors { | ||
folder_selected: Mutex<Option<PathBuf>>, | ||
editor_selected: Mutex<EditorSelected>, | ||
} | ||
|
||
impl Editors { | ||
pub fn render(&self, ui: &mut Ui) { | ||
let folder_selected = self.folder_selected.lock().unwrap().clone(); | ||
|
||
match folder_selected.clone() { | ||
Some(folder) => { | ||
self.render_selected_folder(ui, folder.clone()); | ||
self.render_body(ui, folder.clone()); | ||
} | ||
|
||
None => { | ||
if ui.button("Selecionar pasta do cliente").clicked() { | ||
match FileDialog::new().pick_folder() { | ||
Some(new_folder) => { | ||
*self.folder_selected.lock().unwrap() = Some(new_folder); | ||
} | ||
None => {} | ||
}; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
fn render_selected_folder(&self, ui: &mut Ui, folder: PathBuf) { | ||
ui.horizontal(|ui| { | ||
ui.label("Pasta:"); | ||
|
||
if ui.link(folder.display().to_string()).clicked() {} | ||
}); | ||
} | ||
|
||
fn render_body(&self, ui: &mut Ui, folder: PathBuf) { | ||
StripBuilder::new(ui) | ||
.size(Size::exact(200.0)) | ||
.size(Size::remainder()) | ||
.horizontal(|mut strip| { | ||
strip.cell(|ui| { | ||
ui.group(|ui| { | ||
ui.set_min_size(ui.available_size()); | ||
|
||
self.render_editors_list(ui, folder.clone()); | ||
}); | ||
}); | ||
|
||
strip.cell(|ui| { | ||
ui.group(|ui| { | ||
ui.set_min_size(ui.available_size()); | ||
|
||
ScrollArea::vertical() | ||
.id_source("editor_scroll") | ||
.show(ui, |ui| { | ||
match self.editor_selected.lock().unwrap().clone() { | ||
EditorSelected::None => { | ||
ui.label("Selecione um editor ao lado"); | ||
} | ||
|
||
EditorSelected::ServerList(server_list) => { | ||
server_list.render(ui); | ||
} | ||
}; | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
fn render_editors_list(&self, ui: &mut Ui, folder: PathBuf) { | ||
ui.vertical_centered_justified(|ui| { | ||
self.render_server_list_editor_button(ui, folder); | ||
}); | ||
} | ||
|
||
fn render_server_list_editor_button(&self, ui: &mut Ui, folder: PathBuf) { | ||
let path = folder.join("serverlist.bin"); | ||
|
||
ui.add_enabled_ui(path.exists(), |ui| { | ||
let mut editor_selected = self.editor_selected.lock().unwrap(); | ||
|
||
let selected = match *editor_selected { | ||
EditorSelected::ServerList(_) => true, | ||
_ => false, | ||
}; | ||
|
||
if ui | ||
.add(Button::new("Server List").selected(selected)) | ||
.clicked() | ||
{ | ||
let buf = &mut Vec::new(); | ||
|
||
match File::open(path).unwrap().read_to_end(buf) { | ||
Ok(_size) => match ServerListEditor::new(buf) { | ||
Some(server_list) => { | ||
*editor_selected = EditorSelected::ServerList(server_list); | ||
} | ||
|
||
None => {} | ||
}, | ||
|
||
Err(_error) => {} | ||
}; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use egui::{Button, Ui}; | ||
use fixedstr::zstr; | ||
use std::{ | ||
str::FromStr, | ||
sync::{Arc, Mutex}, | ||
}; | ||
|
||
use crate::structs::ServerList; | ||
|
||
#[derive(Clone)] | ||
pub struct ServerListEditor { | ||
server_list: Arc<Mutex<ServerList>>, | ||
selected_world_index: Arc<Mutex<usize>>, | ||
} | ||
|
||
impl ServerListEditor { | ||
pub fn new(buf: &[u8]) -> Option<Self> { | ||
match ServerList::new(buf) { | ||
Some(server_list) => Some(Self { | ||
server_list: Arc::new(Mutex::new(server_list)), | ||
selected_world_index: Arc::new(Mutex::new(0)), | ||
}), | ||
None => None, | ||
} | ||
} | ||
|
||
pub fn render(&self, ui: &mut Ui) { | ||
let mut server_list = self.server_list.lock().unwrap(); | ||
|
||
ui.vertical(|ui| { | ||
ui.label("Key:"); | ||
|
||
let key = &mut server_list.key.to_string(); | ||
ui.text_edit_singleline(key); | ||
server_list.key = match FromStr::from_str(key) { | ||
Ok(v) => v, | ||
Err(_error) => server_list.key.clone(), | ||
}; | ||
}); | ||
|
||
ui.add_space(4.0); | ||
|
||
let mut selected_world_index = self.selected_world_index.lock().unwrap(); | ||
|
||
ui.vertical(|ui| { | ||
ui.label("Mundo:"); | ||
|
||
ui.horizontal_wrapped(|ui| { | ||
for i in 0..10 { | ||
let selected = *selected_world_index == i; | ||
|
||
if ui | ||
.add(Button::new((i + 1).to_string()).selected(selected)) | ||
.clicked() | ||
{ | ||
*selected_world_index = i; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
ui.add_space(4.0); | ||
|
||
let (world_url, world_channels) = | ||
server_list.worlds.get_mut(*selected_world_index).unwrap(); | ||
|
||
ui.vertical(|ui| { | ||
let url = &mut world_url.to_string(); | ||
|
||
ui.label("Url:"); | ||
|
||
if ui.text_edit_singleline(url).changed() { | ||
*world_url = zstr::from(url); | ||
} | ||
}); | ||
|
||
ui.add_space(4.0); | ||
|
||
ui.label("Canais:"); | ||
|
||
for channel in world_channels { | ||
let addr = &mut channel.to_string(); | ||
if ui.text_edit_singleline(addr).changed() { | ||
*channel = zstr::from(addr); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use fixedstr::zstr; | ||
use std::{mem::transmute, panic::catch_unwind}; | ||
|
||
use crate::{consts::SERVER_LIST_SIZE, decoders}; | ||
|
||
#[repr(C, packed(4))] | ||
pub struct ServerList { | ||
pub key: u32, | ||
pub worlds: [(zstr<64>, [zstr<64>; 10]); 10], | ||
} | ||
|
||
impl ServerList { | ||
pub fn new(buf: &[u8]) -> Option<Self> { | ||
match catch_unwind(|| { | ||
let mut buf = TryInto::<[u8; SERVER_LIST_SIZE]>::try_into(buf).unwrap(); | ||
let buf_encoded = buf.get_mut(4..).unwrap(); | ||
decoders::server_list(buf_encoded); | ||
unsafe { transmute(buf) } | ||
}) { | ||
Ok(result) => Some(result), | ||
Err(_error) => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters