Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new server epf files #167

Merged
merged 6 commits into from
Sep 9, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data/pub/*.edf
data/pub/*.enf
data/pub/*.evf
data/pub/*.etf
data/pub/*.epf
data/pub/**/*.json
data/maps/*.emf
data/quests/*.txt*
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:

db:
image: mysql
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
Expand All @@ -13,4 +13,4 @@ services:
ports:
- "3306:3306"
volumes:
- ./db-init/:/docker-entrypoint-initdb.d/
- ./db-init/:/docker-entrypoint-initdb.d/
15 changes: 9 additions & 6 deletions src/utils/load_class_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ fn load_json() -> Result<Ecf, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<Ecf, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/dat001.ecf")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/dat001.ecf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(Ecf::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(Ecf::deserialize(&reader)?);
}

Ok(Ecf::default())
}
62 changes: 56 additions & 6 deletions src/utils/load_drop_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,61 @@ fn load_json() -> Result<DropFile, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<DropFile, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/dtd001.edf")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/serv_drops.epf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(DropFile::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);

if reader.get_fixed_string(3) != "EDF" {
return Err("Invalid file".into());
}

reader.get_short();
reader.get_short();

let mut edf = DropFile::default();

let num_records = reader.get_short();

edf.npcs = Vec::with_capacity(num_records as usize);

reader.get_char();

for _ in 0..num_records {
let mut record = DropNpcRecord::default();
record.npc_id = reader.get_short();
let num_drops = reader.get_short();

record.drops = Vec::with_capacity(num_drops as usize);
for _ in 0..num_drops {
let item_id = reader.get_short();
let min_amount = reader.get_three();
let max_amount = reader.get_three();
let rate = ((reader.get_short() as f32) / 10_000. * 64_000.).floor() as i32;
record.drops.push(DropRecord {
item_id,
min_amount,
max_amount,
rate,
});
}

edf.npcs.push(record);
}

return Ok(edf);
}

if let Ok(mut file) = File::open("data/pub/dtd001.edf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(DropFile::deserialize(&reader)?);
}

Ok(DropFile::default())
}
72 changes: 65 additions & 7 deletions src/utils/load_inn_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, io::Read};
use std::{cmp, fs::File, io::Read};

use bytes::Bytes;
use eolib::{
Expand Down Expand Up @@ -81,11 +81,69 @@ fn load_json() -> Result<InnFile, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<InnFile, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/din001.eid")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/serv_inns.epf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(InnFile::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
if reader.get_fixed_string(3) != "EID" {
return Err("Invalid file".into());
}

reader.get_short();
reader.get_short();

let mut eif = InnFile::default();

let num_records = reader.get_short();

eif.inns = Vec::with_capacity(num_records as usize);

reader.get_char();

for _ in 0..num_records {
let mut record = InnRecord::default();
record.behavior_id = reader.get_short();
let name_length = reader.get_char();
record.name = reader.get_fixed_string(name_length as usize);

// sleep cost
reader.get_three();

record.sleep_map = reader.get_short();
record.sleep_x = reader.get_char();
record.sleep_y = reader.get_char();
record.spawn_map = reader.get_short();
record.spawn_x = reader.get_char();
record.spawn_y = reader.get_char();
record.alternate_spawn_enabled = reader.get_short() != 0;
record.alternate_spawn_map = reader.get_short();
record.alternate_spawn_x = reader.get_char();
record.alternate_spawn_y = reader.get_char();

let num_questions = reader.get_char();
for i in 0..cmp::min(num_questions as usize, 3) {
let question_length = reader.get_char();
let question = reader.get_fixed_string(question_length as usize);
let answer_length = reader.get_char();
let answer = reader.get_fixed_string(answer_length as usize);
record.questions[i] = InnQuestionRecord { question, answer };
}
eif.inns.push(record);
}

return Ok(eif);
}

if let Ok(mut file) = File::open("data/pub/din001.eid") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(InnFile::deserialize(&reader)?);
}

Ok(InnFile::default())
}
15 changes: 9 additions & 6 deletions src/utils/load_item_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ fn load_json() -> Result<Eif, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<Eif, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/dat001.eif")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/dat001.eif") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(Eif::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(Eif::deserialize(&reader)?);
}

Ok(Eif::default())
}
15 changes: 9 additions & 6 deletions src/utils/load_npc_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ fn load_json() -> Result<Enf, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<Enf, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/dtn001.enf")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/dtn001.enf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(Enf::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(Enf::deserialize(&reader)?);
}

Ok(Enf::default())
}
92 changes: 86 additions & 6 deletions src/utils/load_shop_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,91 @@ fn load_json() -> Result<ShopFile, Box<dyn std::error::Error>> {
}

fn load_pub() -> Result<ShopFile, Box<dyn std::error::Error>> {
let mut file = File::open("data/pub/dts001.esf")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
if let Ok(mut file) = File::open("data/pub/serv_shops.epf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
Ok(ShopFile::deserialize(&reader)?)
let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);

if reader.get_fixed_string(3) != "ESF" {
return Err("Invalid file".into());
}

reader.get_short();
reader.get_short();

let mut esf = ShopFile::default();

let num_records = reader.get_short();

esf.shops = Vec::with_capacity(num_records as usize);

reader.get_char();

for _ in 0..num_records {
let mut record = ShopRecord::default();
record.behavior_id = reader.get_short();

let name_length = reader.get_char();
record.name = reader.get_fixed_string(name_length as usize);
record.min_level = reader.get_short();
record.max_level = reader.get_short();
record.class_requirement = reader.get_char();

let num_trades = reader.get_short();
let num_crafts = reader.get_char();

record.trades = Vec::with_capacity(num_trades as usize);
record.crafts = Vec::with_capacity(num_crafts as usize);

for _ in 0..num_trades {
record.trades.push(ShopTradeRecord {
item_id: reader.get_short(),
buy_price: reader.get_three(),
sell_price: reader.get_three(),
max_amount: reader.get_char(),
});
}

for _ in 0..num_crafts {
record.crafts.push(ShopCraftRecord {
item_id: reader.get_short(),
ingredients: [
ShopCraftIngredientRecord {
item_id: reader.get_short(),
amount: reader.get_char(),
},
ShopCraftIngredientRecord {
item_id: reader.get_short(),
amount: reader.get_char(),
},
ShopCraftIngredientRecord {
item_id: reader.get_short(),
amount: reader.get_char(),
},
ShopCraftIngredientRecord {
item_id: reader.get_short(),
amount: reader.get_char(),
},
],
});
}

esf.shops.push(record);
}

return Ok(esf);
}

if let Ok(mut file) = File::open("data/pub/dts001.esf") {
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let bytes = Bytes::from(buf);
let reader = EoReader::new(bytes);
return Ok(ShopFile::deserialize(&reader)?);
}

Ok(ShopFile::default())
}
Loading