diff --git a/bapi.dll b/bapi.dll index 5f2207477b2..7922a5bfa01 100644 Binary files a/bapi.dll and b/bapi.dll differ diff --git a/html/changelogs/DreamySkrell-mapmanip-script-one-map.yml b/html/changelogs/DreamySkrell-mapmanip-script-one-map.yml new file mode 100644 index 00000000000..87c7e5a9802 --- /dev/null +++ b/html/changelogs/DreamySkrell-mapmanip-script-one-map.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: DreamySkrell + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - rscadd: "Bapi mapmanip script - optional argument to specify a map directory to run manipulations on." diff --git a/rust/bapi/Cargo.lock b/rust/bapi/Cargo.lock index bbfddc1dab7..83636a44af6 100644 --- a/rust/bapi/Cargo.lock +++ b/rust/bapi/Cargo.lock @@ -99,6 +99,7 @@ dependencies = [ "eyre", "fxhash", "itertools", + "libc", "rand", "regex", "scc", @@ -394,7 +395,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -659,9 +660,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.186" +version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libloading" diff --git a/rust/bapi/Cargo.toml b/rust/bapi/Cargo.toml index dc4a8daf360..03508df4090 100644 --- a/rust/bapi/Cargo.toml +++ b/rust/bapi/Cargo.toml @@ -37,3 +37,4 @@ regex = "1.10.5" # time chrono = "0.4.39" uuid = { version = "1.18.1", features = ["v4"] } +libc = "0.2.189" diff --git a/rust/bapi/src/lib.rs b/rust/bapi/src/lib.rs index c5890c401e8..5e2a782aa30 100644 --- a/rust/bapi/src/lib.rs +++ b/rust/bapi/src/lib.rs @@ -100,9 +100,37 @@ fn read_dmm_file(path: ByondValue) -> eyre::Result { /// Not to be called from the game server, so bad error-handling is fine. /// This should run map manipulations on every `.dmm` map that has a `.jsonc` config file, /// and write it to a `.mapmanipout.dmm` file in the same location. +/// Or, if provided, run manipulations on maps in a directory from the `path_raw` argument. #[no_mangle] -pub unsafe extern "C" fn all_mapmanip_configs_execute_ffi() { - let mapmanip_configs = walkdir::WalkDir::new("../../maps") +pub unsafe extern "system" fn all_mapmanip_configs_execute_ffi( + _hwnd: *mut libc::c_void, + _hinst: *mut libc::c_void, + lpsz_cmd_line: *const libc::c_char, + _n_cmd_show: i32, +) { + let maps_path = if lpsz_cmd_line.is_null() { + // just do all maps + "../../maps".to_string() + } else { + // try to safely parse the argument + let c_str = unsafe { std::ffi::CStr::from_ptr(lpsz_cmd_line) }; + + match c_str.to_str() { + Ok(s) if !s.trim().is_empty() => { + let input_path = std::path::Path::new(s.trim()); + if input_path.is_absolute() { + input_path.to_string_lossy().into_owned() + } else { + let mut resolved = std::path::PathBuf::from("../../"); + resolved.push(input_path); + resolved.to_string_lossy().into_owned() + } + } + _ => "../../maps".to_string(), + } + }; + + let mapmanip_configs = walkdir::WalkDir::new(maps_path) .into_iter() .map(|d| d.unwrap().path().to_owned()) .filter(|p| p.extension().is_some()) @@ -117,6 +145,10 @@ pub unsafe extern "C" fn all_mapmanip_configs_execute_ffi() { p }; + if !dmm_path.exists() { + continue; + } + let path_dir: &std::path::Path = dmm_path.parent().unwrap(); let mut dmm = dmmtools::dmm::Map::from_file(&dmm_path).unwrap(); diff --git a/tools/bapi/mapmanip.ps1 b/tools/bapi/mapmanip.ps1 index 10fad66da09..a823f0456cb 100644 --- a/tools/bapi/mapmanip.ps1 +++ b/tools/bapi/mapmanip.ps1 @@ -1,15 +1,28 @@ +param ( + [string]$Path +) + # if you want to run this script but it opens in notepad # you may want to right click it and "run with powershell" # script explanation -echo "*****" -echo "This script will run map manipulations on every `.dmm` map that has a `.jsonc` config file," -echo "and write it to a `.mapmanipout.dmm` file in the same location." -echo "Make sure to not commit these files to the repo." -echo "This script will not show any error messages if map manipulations have failed." -echo "Should launch the actual server to get stacktraces and the like." -echo "*****" +Write-Host "*****" +Write-Host "" +Write-Host "This script will run map manipulations on every `.dmm` map that has a `.jsonc` config file," +Write-Host "and write it to a `.mapmanipout.dmm` file in the same location." +Write-Host "Make sure to not commit these files to the repo." +Write-Host "This script will not show any error messages if map manipulations have failed." +Write-Host "You may have to launch the actual server to get stacktraces and the like." +Write-Host "You may provide a path to a specific map directory as an argument." +Write-Host "" +Write-Host "Example usage:" +Write-Host "./mapmanip.ps1" +Write-Host "./mapmanip.ps1 -Path maps/away/ships/my_map_folder" +Write-Host "./mapmanip.ps1 -Path D:/Git/Aurora.3/maps/away/ships/my_map_folder" +Write-Host "" +Write-Host "*****" +Write-Host "" # find path to bapi.dll if (Test-Path "./../../rust/bapi/target/i686-pc-windows-msvc/release/bapi.dll") { @@ -19,20 +32,27 @@ if (Test-Path "./../../rust/bapi/target/i686-pc-windows-msvc/release/bapi.dll") } elseif (Test-Path "./../../bapi.dll") { $BapiPath = "./../../bapi.dll" } else { - echo "Cannot find bapi." + Write-Host "Cannot find bapi." } # run ffi function from bapi.dll -echo "Executing..." +Write-Host "Executing..." +$HasPath = $PSBoundParameters.ContainsKey('Path') -or ($null -ne $Path) $BapiDllFunction = "all_mapmanip_configs_execute_ffi" $BapiExecutionTime = Measure-Command { # `rundll` runs a function from a dll # the very sad limitation is that it does not give any output from that function - rundll32.exe $BapiPath,$BapiDllFunction + if ($HasPath) { + Write-Host "on path $Path..." + rundll32.exe "$BapiPath,$BapiDllFunction" $Path + } else { + Write-Host "on all maps..." + rundll32.exe "$BapiPath,$BapiDllFunction" + } } # done -echo "Done!" -echo ("Took {0} seconds, or {1} milliseconds in total." -f $BapiExecutionTime.Seconds,$BapiExecutionTime.Milliseconds) -echo "*****" +Write-Host "Done!" +Write-Host ("Took {0} seconds, or {1} milliseconds in total." -f $BapiExecutionTime.Seconds,$BapiExecutionTime.Milliseconds) +Write-Host "*****" Read-Host -Prompt "Press Enter to exit..." diff --git a/tools/ci/libbapi_ci.so b/tools/ci/libbapi_ci.so index dcff7eead41..caaafd09b41 100644 Binary files a/tools/ci/libbapi_ci.so and b/tools/ci/libbapi_ci.so differ