Skip to content

Commit fed3129

Browse files
authored
Merge pull request #2 from AstroTechies/dependency_system
Dependency system
2 parents 951da64 + f068e19 commit fed3129

File tree

10 files changed

+121
-14
lines changed

10 files changed

+121
-14
lines changed

astro_modintegrator/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
[package]
22
name = "astro_modintegrator"
33
authors = ["AstroTechies"]
4-
version = "0.1.4"
4+
version = "0.1.5"
55
edition = "2021"
66

77
[dependencies]
8-
unreal_modloader = { verison = "0.1.5", git = "https://github.com/AstroTechies/unrealmodding", features = ["ue4_23"] }
8+
unreal_modloader = { verison = "0.1.6", git = "https://github.com/AstroTechies/unrealmodding", features = ["ue4_23"] }
99
serde_json = "1.0.82"
1010
serde = { version = "1.0.140", features = ["derive"] }
1111
log = "0.4.17"
1212
colored = "2.0.0"
1313
lazy_static = "1.4.0"
1414
regex = "1.6.0"
15-
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
15+
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
16+
17+
[build-dependencies]
18+
walkdir = "2.3.2"
19+
unreal_pak = { version = "0.1.0", git = "https://github.com/AstroTechies/unrealmodding" }
20+
5.03 KB
Binary file not shown.
1.17 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"schema_version": 2,
3+
"name": "CoreMod",
4+
"mod_id": "CoreMod",
5+
"version": "0.1.0",
6+
"author": "AstroTechies",
7+
"integrator": {
8+
"persistent_actors": [
9+
"/Game/Integrator/NotificationActor"
10+
],
11+
"persistent_actor_maps": [
12+
"Astro/Content/Maps/Staging_T2.umap",
13+
"Astro/Content/Maps/Staging_T2_PackedPlanets_Switch.umap",
14+
"Astro/Content/Maps/test/BasicSphereT2.umap"
15+
]
16+
}
17+
}

astro_modintegrator/build.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use std::{
2+
env,
3+
error::Error,
4+
fs::{self, OpenOptions},
5+
path::{Path, PathBuf},
6+
};
7+
8+
use unreal_pak::{pakversion::PakVersion, PakFile, PakRecord};
9+
use walkdir::WalkDir;
10+
11+
fn add_extension(path: &mut PathBuf, extension: &str) {
12+
match path.extension() {
13+
Some(existing_extension) => {
14+
let mut os_str = existing_extension.to_os_string();
15+
os_str.push(".");
16+
os_str.push(extension);
17+
path.set_extension(os_str);
18+
}
19+
None => {
20+
path.set_extension(extension);
21+
}
22+
}
23+
}
24+
25+
fn main() -> Result<(), Box<dyn Error>> {
26+
println!("cargo:rerun-if-changed=baked");
27+
28+
let baked_dir = fs::read_dir("baked")?;
29+
let out_dir = env::var("OUT_DIR")?;
30+
let out_dir = Path::new(&out_dir).join("baked");
31+
32+
fs::create_dir_all(&out_dir)?;
33+
34+
for path in baked_dir
35+
.filter_map(|e| e.ok())
36+
.filter(|e| e.file_type().unwrap().is_dir())
37+
{
38+
let path = path.path();
39+
let mut pak_path = out_dir.join(path.file_name().unwrap());
40+
add_extension(&mut pak_path, "pak");
41+
42+
OpenOptions::new()
43+
.create(true)
44+
.write(true)
45+
.truncate(true)
46+
.open(&pak_path)?;
47+
48+
let file = OpenOptions::new().append(true).open(pak_path)?;
49+
50+
let mut pak = PakFile::writer(PakVersion::PakFileVersionFnameBasedCompressionMethod, &file);
51+
52+
for entry in WalkDir::new(&path).into_iter().map(|e| e.unwrap()) {
53+
if entry.file_type().is_file() {
54+
let rel_path = entry.path().strip_prefix(&path).unwrap();
55+
let record_name = rel_path.to_str().unwrap().replace('\\', "/");
56+
57+
let file_data = fs::read(entry.path()).unwrap();
58+
let record =
59+
PakRecord::new(record_name, file_data, unreal_pak::CompressionMethod::Zlib)?;
60+
61+
pak.add_record(record)?;
62+
}
63+
}
64+
65+
pak.write()?;
66+
}
67+
68+
Ok(())
69+
}

astro_modintegrator/src/baked.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
macro_rules! baked_path {
2+
() => {
3+
concat!(env!("OUT_DIR"), "/baked/")
4+
};
5+
}
6+
7+
pub(crate) const CORE_MOD: &[u8] =
8+
include_bytes!(concat!(baked_path!(), "800-CoreMod-0.1.0_P.pak"));

astro_modintegrator/src/handlers/biome_placement_modifiers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub(crate) fn handle_biome_placement_modifiers(
133133
}
134134

135135
let export_index = export_index.unwrap();
136-
let export = (&mut asset.exports[*export_index])
136+
let export = (asset.exports[*export_index])
137137
.get_normal_export_mut()
138138
.unwrap();
139139

astro_modintegrator/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::{collections::HashMap, io};
22

3-
use crate::unreal_modintegrator::bake_instructions;
4-
use handlers::MAP_PATHS;
3+
use crate::unreal_modintegrator::IntegratorMod;
54
use unreal_modloader::unreal_asset::ue4version::VER_UE4_23;
65
use unreal_modloader::unreal_modintegrator::helpers::game_to_absolute;
76
use unreal_modloader::unreal_modintegrator::BakedInstructions;
7+
use unreal_modloader::unreal_modintegrator::BakedMod;
88
use unreal_modloader::unreal_modintegrator::IntegratorConfig;
99

1010
use lazy_static::lazy_static;
1111

1212
pub mod assets;
13+
pub(crate) mod baked;
1314
pub(crate) mod handlers;
1415

1516
use crate::handlers::{
@@ -96,12 +97,18 @@ impl<'data> IntegratorConfig<'data, (), io::Error> for AstroIntegratorConfig {
9697
}
9798

9899
fn get_instructions(&self) -> Option<BakedInstructions> {
99-
let instructions = bake_instructions!(
100-
"persistent_actors": ["/Game/Integrator/NotificationActor"],
101-
"persistent_actor_maps": MAP_PATHS
102-
);
100+
None
101+
}
103102

104-
Some(BakedInstructions::new(FILE_REFS.clone(), instructions))
103+
fn get_baked_mods(&self) -> Vec<IntegratorMod<io::Error>> {
104+
Vec::from([BakedMod {
105+
data: baked::CORE_MOD,
106+
mod_id: "CoreMod".to_string(),
107+
filename: "800-CoreMod-0.1.0_P.pak",
108+
is_core: true,
109+
priority: 800,
110+
}
111+
.into()])
105112
}
106113

107114
const GAME_NAME: &'static str = "Astro";

astro_modloader/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "astro_modloader"
33
authors = ["AstroTechies"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55
edition = "2021"
66

77
[dependencies]
8-
astro_modintegrator = { version = "0.1.4", path = "../astro_modintegrator" }
8+
astro_modintegrator = { version = "0.1.5", path = "../astro_modintegrator" }
99
image = "0.24.3"
1010
autoupdater = "0.1.7"
1111
serde_json = "1.0.82"

astro_modloader/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ impl AstroGameConfig {
114114
}
115115
}
116116

117-
impl<T, E: std::error::Error> GameConfig<'static, AstroIntegratorConfig, T, E> for AstroGameConfig
117+
impl<T, E: std::error::Error + 'static> GameConfig<'static, AstroIntegratorConfig, T, E>
118+
for AstroGameConfig
118119
where
119120
AstroIntegratorConfig: IntegratorConfig<'static, T, E>,
120121
{

0 commit comments

Comments
 (0)