Compare commits

..

9 Commits

4 changed files with 761 additions and 229 deletions

2
.cargo/config.toml Normal file
View File

@ -0,0 +1,2 @@
[registries.strafesnet]
index = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"

934
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package] [package]
name = "map-tool" name = "map-tool"
version = "1.5.3" version = "1.5.7"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -9,22 +9,22 @@ edition = "2021"
anyhow = "1.0.75" anyhow = "1.0.75"
clap = { version = "4.4.2", features = ["derive"] } clap = { version = "4.4.2", features = ["derive"] }
flate2 = "1.0.27" flate2 = "1.0.27"
image = "0.24.7" image = "0.25.2"
image_dds = "0.1.1" image_dds = "0.6.0"
lazy-regex = "3.1.0" lazy-regex = "3.1.0"
rbx_binary = { version = "0.7.4", registry = "strafesnet" } rbx_binary = { version = "0.7.4", registry = "strafesnet" }
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" } rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
rbx_reflection_database = { version = "0.2.10", registry = "strafesnet" } rbx_reflection_database = { version = "0.2.10", registry = "strafesnet" }
rbx_xml = { version = "0.13.3", registry = "strafesnet" } rbx_xml = { version = "0.13.3", registry = "strafesnet" }
strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet" } strafesnet_bsp_loader = { version = "0.2.1", registry = "strafesnet" }
strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet" } strafesnet_deferred_loader = { version = "0.4.0", features = ["legacy"], registry = "strafesnet" }
strafesnet_rbx_loader = { version = "0.3.6", registry = "strafesnet" } strafesnet_rbx_loader = { version = "0.5.1", registry = "strafesnet" }
strafesnet_snf = { version = "0.1.0", registry = "strafesnet" } strafesnet_snf = { version = "0.2.0", registry = "strafesnet" }
vbsp = "0.5.0" vbsp = "0.6.0"
vmdl = "0.1.1" vmdl = "0.2.0"
vmt-parser = "0.1.1" vmt-parser = "0.2.0"
vpk = "0.2.0" vpk = "0.2.0"
vtf = "0.2.1" vtf = "0.3.0"
#[profile.release] #[profile.release]
#lto = true #lto = true

View File

@ -2,6 +2,7 @@ use std::{collections::HashSet,io::{Read,Seek},path::PathBuf};
use clap::{Args,Parser,Subcommand}; use clap::{Args,Parser,Subcommand};
use anyhow::Result as AResult; use anyhow::Result as AResult;
use rbx_dom_weak::Instance; use rbx_dom_weak::Instance;
use strafesnet_deferred_loader::rbxassetid::RobloxAssetId;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -152,22 +153,6 @@ fn get_dom<R:Read+Seek>(input:&mut R)->AResult<rbx_dom_weak::WeakDom>{
} }
} }
struct RobloxAssetId(u64);
struct RobloxAssetIdParseErr;
impl std::str::FromStr for RobloxAssetId {
type Err=RobloxAssetIdParseErr;
fn from_str(s: &str) -> Result<Self, Self::Err>{
let regman=lazy_regex::regex!(r"(\d+)$");
if let Some(captures) = regman.captures(s) {
if captures.len()==2{//captures[0] is all captures concatenated, and then each individual capture
if let Ok(id) = captures[0].parse::<u64>() {
return Ok(Self(id));
}
}
}
Err(RobloxAssetIdParseErr)
}
}
/* The ones I'm interested in: /* The ones I'm interested in:
Beam.Texture Beam.Texture
Decal.Texture Decal.Texture
@ -322,9 +307,9 @@ fn convert(file_thing:std::fs::DirEntry) -> AResult<()>{
}?.to_rgba8();//this sets a=255, arcane is actually supposed to look like that }?.to_rgba8();//this sets a=255, arcane is actually supposed to look like that
let format=if image.width()%4!=0||image.height()%4!=0{ let format=if image.width()%4!=0||image.height()%4!=0{
image_dds::ImageFormat::R8G8B8A8Srgb image_dds::ImageFormat::Rgba8UnormSrgb
}else{ }else{
image_dds::ImageFormat::BC7Srgb image_dds::ImageFormat::BC7RgbaUnormSrgb
}; };
//this fails if the image dimensions are not a multiple of 4 //this fails if the image dimensions are not a multiple of 4
let dds = image_dds::dds_from_image( let dds = image_dds::dds_from_image(
@ -561,9 +546,9 @@ fn extract_textures(paths:Vec<PathBuf>,vpk_paths:Vec<PathBuf>)->AResult<()>{
let image=vtf::from_bytes(&mut stuff)?.highres_image.decode(0)?.to_rgba8(); let image=vtf::from_bytes(&mut stuff)?.highres_image.decode(0)?.to_rgba8();
let format=if image.width()%4!=0||image.height()%4!=0{ let format=if image.width()%4!=0||image.height()%4!=0{
image_dds::ImageFormat::R8G8B8A8Srgb image_dds::ImageFormat::Rgba8UnormSrgb
}else{ }else{
image_dds::ImageFormat::BC7Srgb image_dds::ImageFormat::BC7RgbaUnormSrgb
}; };
//this fails if the image dimensions are not a multiple of 4 //this fails if the image dimensions are not a multiple of 4
let dds = image_dds::dds_from_image( let dds = image_dds::dds_from_image(
@ -691,19 +676,20 @@ fn roblox_to_snf(pathlist:Vec<std::path::PathBuf>,output_folder:PathBuf)->AResul
} }
let output_folder=output_folder.clone(); let output_folder=output_folder.clone();
threads.push_back(std::thread::spawn(move ||{ threads.push_back(std::thread::spawn(move ||{
let mut dom=strafesnet_rbx_loader::read( let model=strafesnet_rbx_loader::read(
std::fs::File::open(path.as_path()) std::fs::File::open(path.as_path())
.map_err(ConvertError::IO)? .map_err(ConvertError::IO)?
).map_err(ConvertError::RbxLoader)?; ).map_err(ConvertError::RbxLoader)?;
dom.run_scripts(); let mut place=model.into_place();
place.run_scripts();
let mut loader=strafesnet_deferred_loader::roblox_legacy(); let mut loader=strafesnet_deferred_loader::roblox_legacy();
let (texture_loader,mesh_loader)=loader.get_inner_mut(); let (texture_loader,mesh_loader)=loader.get_inner_mut();
let map_step1=strafesnet_rbx_loader::convert( let map_step1=strafesnet_rbx_loader::convert(
&dom, &place,
|name|texture_loader.acquire_render_config_id(name), |name|texture_loader.acquire_render_config_id(name),
|name|mesh_loader.acquire_mesh_id(name), |name|mesh_loader.acquire_mesh_id(name),
); );