unity_scene_repacker 2.3.0__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/Cargo.lock +3 -3
  2. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/Cargo.toml +1 -1
  3. unity_scene_repacker-2.4.0/PKG-INFO +7 -0
  4. unity_scene_repacker-2.4.0/README.md +173 -0
  5. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/lib.rs +70 -45
  6. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/justfile +9 -0
  7. unity_scene_repacker-2.4.0/objects/ns-by-type.json +3 -0
  8. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/env.rs +20 -0
  9. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/game_files.rs +29 -0
  10. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/lib.rs +306 -191
  11. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/merge_serialized.rs +72 -51
  12. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/prune.rs +22 -12
  13. unity_scene_repacker-2.4.0/src/reachable.rs +55 -0
  14. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/scene_lookup.rs +2 -48
  15. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/trace_pptr.rs +1 -1
  16. unity_scene_repacker-2.3.0/PKG-INFO +0 -10
  17. unity_scene_repacker-2.3.0/README.md +0 -103
  18. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/.clang-format +0 -0
  19. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/.github/workflows/release.yml +0 -0
  20. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/.gitignore +0 -0
  21. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/LICENSE.md +0 -0
  22. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/Cargo.toml +0 -0
  23. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/completion.rs +0 -0
  24. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/locate.rs +0 -0
  25. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/logger.rs +0 -0
  26. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/main.rs +0 -0
  27. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/py.rs +0 -0
  28. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/cli/src/utils.rs +0 -0
  29. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/data/purelib/unity_scene_repacker.libs/.gitkeep +0 -0
  30. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/docs/demo-cast.svg +0 -0
  31. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/docs/demo.cast +0 -0
  32. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/docs/release.md +0 -0
  33. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/examples/export_monobehaviour_typetrees.rs +0 -0
  34. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/objects/hk-enemies.jsonc +0 -0
  35. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/objects/hk-representative.jsonc +0 -0
  36. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/objects/ns-monsters.json +0 -0
  37. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/pyproject.toml +0 -0
  38. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/rustfmt.toml +0 -0
  39. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/monobehaviour_typetree_export.rs +0 -0
  40. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/typetree_generator_cache.rs +0 -0
  41. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/unity/mod.rs +0 -0
  42. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/unity/types/utils.rs +0 -0
  43. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/src/unity/types.rs +0 -0
  44. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/typetree-generator-api/Cargo.toml +0 -0
  45. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/typetree-generator-api/bindings.h +0 -0
  46. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/typetree-generator-api/src/generated.rs +0 -0
  47. {unity_scene_repacker-2.3.0 → unity_scene_repacker-2.4.0}/typetree-generator-api/src/lib.rs +0 -0
@@ -66,7 +66,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
66
66
 
67
67
  [[package]]
68
68
  name = "bindings"
69
- version = "2.3.0"
69
+ version = "2.4.0"
70
70
  dependencies = [
71
71
  "anyhow",
72
72
  "indexmap",
@@ -862,7 +862,7 @@ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
862
862
 
863
863
  [[package]]
864
864
  name = "unity-scene-repacker"
865
- version = "2.3.0"
865
+ version = "2.4.0"
866
866
  dependencies = [
867
867
  "anyhow",
868
868
  "byteorder",
@@ -882,7 +882,7 @@ dependencies = [
882
882
 
883
883
  [[package]]
884
884
  name = "unity-scene-repacker-bin"
885
- version = "2.3.0"
885
+ version = "2.4.0"
886
886
  dependencies = [
887
887
  "anyhow",
888
888
  "clap",
@@ -26,7 +26,7 @@ typetree-generator-api.workspace = true
26
26
  members = ["cli", "typetree-generator-api"]
27
27
  default-members = [".", "bindings", "cli", "typetree-generator-api"]
28
28
 
29
- package.version = "2.3.0"
29
+ package.version = "2.4.0"
30
30
  package.edition = "2024"
31
31
  package.license = "MIT"
32
32
  package.repository = "https://github.com/jakobhellermann/unity-scene-repacker"
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: unity-scene-repacker
3
+ Version: 2.4.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Topic :: Games/Entertainment
6
+ License-File: LICENSE.md
7
+ Requires-Python: >=3.8
@@ -0,0 +1,173 @@
1
+ # unity-scene-repacker
2
+
3
+ ![demo asciicast](./docs/demo-cast.svg)
4
+
5
+ When modding a unity game, you often want to `Instantiate` objects from a scene that isn't loaded.
6
+ One solution for this is to load all the scenes you're interested in at startup, copy the gameobjects somewhere and unload the scene.
7
+ This works, but is slow and memory intensive.
8
+
9
+ This project lets you read scenes from the distributed game, take only what you need, and package those objects into an [AssetBundle](https://docs.unity3d.com/Manual/AssetBundlesIntro.html) that you can load at runtime.
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ uv tool install unity-scene-repacker
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ `unity-scene-repacker` can repack objects into two kinds of [`AssetBundle`](https://docs.unity3d.com/ScriptReference/AssetBundle.html)s.
20
+ - Scene bundles contain the original scenes, filtered down to only the requested objects.
21
+ - Asset bundles allow you to selectively load objects without having to load all of them, but are a bit more experimental.
22
+
23
+ **Scene bundle**:
24
+
25
+ ```jsonc
26
+ objects.json
27
+ {
28
+ "Fungus1_12": [
29
+ "simple_grass",
30
+ "green_grass_2",
31
+ "green_grass_3",
32
+ "green_grass_1 (1)"
33
+ ],
34
+ "White_Palace_01": [
35
+ "WhiteBench",
36
+ "White_ Spikes"
37
+ ]
38
+ }
39
+ ```
40
+
41
+ ```sh
42
+ unity-scene-repacker \
43
+ --steam-game 'Hollow Knight' \
44
+ --scene-objects objects.json \
45
+ --mode scene \
46
+ --output mybundle.unity3d
47
+ ```
48
+
49
+
50
+ ```cs
51
+ const string bundleName = "mybundle";
52
+ var bundle = AssetBundle.LoadFromFile(path);
53
+
54
+ // load single scene
55
+ SceneManager.LoadScene($"unity-scene-repacker/{bundleName}/Fungus1_12.unity")
56
+
57
+ // load add scenes
58
+ foreach (string scenePath in bundle.GetAllScenePaths()) {
59
+ string sceneName = Path.GetFileNameWithoutExtension(scenePath);
60
+ SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
61
+ var scene = USceneManager.GetSceneByPath(scenePath);
62
+ var roots = scene.GetRootGameObjects();
63
+ }
64
+ bundle.Unload();
65
+ ```
66
+
67
+ **Asset bundle**:
68
+
69
+ Asset bundles allow you to selectively load objects, without having to load the others into memory.
70
+ However, the implementation is a bit more experimental, so if something doesn't work, try the scene output instead.
71
+
72
+ ```sh
73
+ unity-scene-repacker \
74
+ --steam-game 'Hollow Knight' \
75
+ --scene-objects objects.json \
76
+ --mode asset \
77
+ --output mybundle.unity3d
78
+ ```
79
+
80
+
81
+ ```cs
82
+ var bundle = AssetBundle.LoadFromFile(path);
83
+ var prefab = bundle.LoadAsset<GameObject>("Fungus1_12/simple_grass");
84
+ var object = Instantiate(prefab);
85
+ bundle.Unload();
86
+ ```
87
+
88
+ The `asset` output mode also allows you to additionally specify arbitrary other objects (e.g. `ScriptableObject`s) by name:
89
+
90
+ ```json
91
+ {
92
+ "FXDealerMaterialTag": ["[FXDealer] 0_YeeAttack _PostureDecrease"]
93
+ }
94
+ ```
95
+
96
+ ```sh
97
+ unity-scene-repacker ... --extra-objects objects-by-type.json --mode asset
98
+ ```
99
+
100
+ ```cs
101
+ var object = bundle.LoadAsset<FXDealerMaterialTag>("ExtraObjects/FXDealerMaterialTag/[FXDealer] 0_YeeAttack _PostureDecrease.prefab");
102
+ ```
103
+
104
+ ### CLI Reference
105
+
106
+ ```
107
+ Usage: unity-scene-repacker [OPTIONS] <--game-dir <GAME_DIR>|--steam-game <STEAM_GAME>>
108
+
109
+ Options:
110
+ -h, --help
111
+ Print help (see a summary with '-h')
112
+
113
+ -V, --version
114
+ Print version
115
+
116
+ Game options:
117
+ --game-dir <GAME_DIR>
118
+ Directory where the levels files are, e.g. steam/Hollow_Knight/hollow_knight_Data
119
+
120
+ --steam-game <STEAM_GAME>
121
+ App ID or search term for the steam game to detect
122
+
123
+ Repack options:
124
+ --scene-objects <SCENE_OBJECTS>
125
+ Path to JSON file, containing a map of scene name to a list of gameobject paths to include
126
+
127
+ {
128
+ "Fungus1_12": [
129
+ "simple_grass",
130
+ "green_grass_2",
131
+ ],
132
+ "White_Palace_01": [
133
+ "WhiteBench",
134
+ ]
135
+ }
136
+
137
+
138
+ --extra-objects <EXTRA_OBJECTS>
139
+ Path to JSON file, containing a map of C# type to monobehaviour names. Useful for scriptable objects etc., which do not exist in the transform hierarchy.
140
+
141
+ {
142
+ "FXDealerMaterialTag": ["[FXDealer] 0_YeeAttack _PostureDecrease"]
143
+ }
144
+
145
+
146
+ Output options:
147
+ --mode <MODE>
148
+ [default: scene]
149
+
150
+ Possible values:
151
+ - scene: A scene asset bundle, containing the original scenes filtered. Load using LoadScene
152
+ - asset: An asset bundle containing individual assets you can load using LoadAsset. The objects are copied from the original level files
153
+ - asset-shallow: An asset bundle containing individual assets you can load using LoadAsset. The bundle is completely empty, and only references the original game level files
154
+
155
+ --disable
156
+ When true, all gameobjects in the scene will start out disabled
157
+
158
+ --compression <COMPRESSION>
159
+ Compression level to apply
160
+
161
+ [default: lzma]
162
+
163
+ Possible values:
164
+ - none
165
+ - lzma
166
+ - lz4hc: Best compression at the cost of speed
167
+
168
+ -o, --output <OUTPUT>
169
+ [default: out.unity3d]
170
+
171
+ --bundle-name <BUNDLE_NAME>
172
+ Name to give the assetbundle. Should be unique for your game
173
+ ```
@@ -9,16 +9,16 @@ mod py;
9
9
  use anyhow::{Context, Result, bail, ensure};
10
10
  use clap::{Args, CommandFactory as _, Parser};
11
11
  use clap_complete::ArgValueCompleter;
12
- use indexmap::IndexMap;
12
+ use indexmap::{IndexMap, IndexSet};
13
13
  use paris::{error, info, success, warn};
14
- use rabex::files::bundlefile::{self, CompressionType};
14
+ use rabex::files::bundlefile::CompressionType;
15
15
  use rabex::objects::ClassId;
16
16
  use rabex::tpk::TpkTypeTreeBlob;
17
17
  use rabex::typetree::TypeTreeProvider as _;
18
18
  use rabex::typetree::typetree_cache::sync::TypeTreeCache;
19
19
  use std::ffi::{OsStr, OsString};
20
20
  use std::fs::{DirBuilder, File};
21
- use std::io::{BufWriter, Cursor};
21
+ use std::io::BufWriter;
22
22
  use std::path::{Path, PathBuf};
23
23
  use std::time::Instant;
24
24
  use unity_scene_repacker::env::Environment;
@@ -69,6 +69,16 @@ struct RepackArgs {
69
69
  #[arg(long)]
70
70
  #[arg(alias = "objects")]
71
71
  scene_objects: Option<PathBuf>,
72
+
73
+ /// Path to JSON file, containing a map of C# type to monobehaviour names.
74
+ /// Useful for scriptable objects etc., which do not exist in the transform hierarchy.
75
+ /// ```json
76
+ /// {
77
+ /// "FXDealerMaterialTag": ["[FXDealer] 0_YeeAttack _PostureDecrease"]
78
+ /// }
79
+ /// ```
80
+ #[arg(long)]
81
+ extra_objects: Option<PathBuf>,
72
82
  }
73
83
 
74
84
  #[derive(Args, Debug)]
@@ -172,9 +182,25 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
172
182
  .scene_objects
173
183
  .as_ref()
174
184
  .map(|path| -> Result<IndexMap<String, Vec<String>>> {
175
- let preloads = std::fs::read_to_string(path)
176
- .with_context(|| format!("couldn't find object json '{}'", path.display()))?;
177
- Ok(json5::from_str(&preloads).context("error parsing the objects json")?)
185
+ let preloads = std::fs::read_to_string(path).with_context(|| {
186
+ format!("couldn't find scene objects json '{}'", path.display())
187
+ })?;
188
+ json5::from_str(&preloads).context("error parsing the scene objects json")
189
+ })
190
+ .transpose()?
191
+ .unwrap_or_default();
192
+ let extra_objects = args
193
+ .repack
194
+ .extra_objects
195
+ .as_ref()
196
+ .map(|path| -> Result<IndexMap<String, IndexSet<String>>> {
197
+ let preloads = std::fs::read_to_string(path).with_context(|| {
198
+ format!(
199
+ "couldn't find extra monobehaviour json '{}'",
200
+ path.display()
201
+ )
202
+ })?;
203
+ json5::from_str(&preloads).context("error parsing the extra monobehaviours json")
178
204
  })
179
205
  .transpose()?
180
206
  .unwrap_or_default();
@@ -189,7 +215,20 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
189
215
  scene_objects.len()
190
216
  );
191
217
  }
192
- let repack_settings = RepackSettings { scene_objects };
218
+ if !extra_objects.is_empty() {
219
+ let obj_count = extra_objects
220
+ .iter()
221
+ .map(|(_, objects)| objects.len())
222
+ .sum::<usize>();
223
+ info!(
224
+ "Repacking {obj_count} extra monobehaviour{}",
225
+ if obj_count == 1 { "" } else { "s" }
226
+ );
227
+ }
228
+ let repack_settings = RepackSettings {
229
+ scene_objects,
230
+ extra_objects,
231
+ };
193
232
 
194
233
  if repack_settings.is_empty() {
195
234
  bail!("Nothing to repack specified. See `--help` for possible repack options.")
@@ -275,7 +314,7 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
275
314
  return Ok(());
276
315
  }
277
316
 
278
- let mut repack_scenes = unity_scene_repacker::repack_scenes(
317
+ let (mut repack_scenes, extra_objects) = unity_scene_repacker::repack_scenes(
279
318
  &env,
280
319
  repack_settings,
281
320
  matches!(args.output.mode, Mode::Asset),
@@ -291,38 +330,22 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
291
330
 
292
331
  let new_size = match args.output.mode {
293
332
  Mode::Scene => {
294
- let (stats, header, files) = unity_scene_repacker::pack_to_scene_bundle(
333
+ let mut out = BufWriter::new(
334
+ File::create(&args.output.output).context("Could not write to output file")?,
335
+ );
336
+
337
+ let stats = unity_scene_repacker::pack_to_scene_bundle(
338
+ &mut out,
295
339
  name,
296
340
  &tpk_blob,
297
341
  &env.tpk,
298
342
  unity_version,
299
343
  repack_scenes.as_mut_slice(),
344
+ compression,
300
345
  )
301
346
  .context("trying to repack bundle")?;
302
347
 
303
- info!(
304
- "Pruned {} -> <b>{}</b> objects",
305
- stats.objects_before, stats.objects_after
306
- );
307
- info!(
308
- "{} -> <b>{}</b> raw size",
309
- friendly_size(stats.size_before),
310
- friendly_size(stats.size_after)
311
- );
312
- println!();
313
-
314
- let mut out = BufWriter::new(
315
- File::create(&args.output.output).context("Could not write to output file")?,
316
- );
317
- bundlefile::write_bundle_iter(
318
- &header,
319
- &mut out,
320
- CompressionType::Lz4hc,
321
- compression,
322
- files
323
- .into_iter()
324
- .map(|(name, file)| Ok((name, Cursor::new(file)))),
325
- )?;
348
+ print_stats(&stats, args.repack.scene_objects.is_some());
326
349
 
327
350
  out.get_ref().metadata()?.len() as usize
328
351
  }
@@ -335,11 +358,11 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
335
358
  &mut out,
336
359
  name,
337
360
  &tpk_blob,
338
- unity_version,
339
361
  repack_scenes,
362
+ extra_objects,
340
363
  compression,
341
364
  )?;
342
- print_stats(&stats);
365
+ print_stats(&stats, args.repack.scene_objects.is_some());
343
366
 
344
367
  out.get_ref().metadata()?.len() as usize
345
368
  }
@@ -362,15 +385,17 @@ fn run(args: Vec<OsString>, libs_dir: Option<&Path>) -> Result<()> {
362
385
  Ok(())
363
386
  }
364
387
 
365
- fn print_stats(stats: &Stats) {
366
- info!(
367
- "Pruned {} -> <b>{}</b> objects",
368
- stats.objects_before, stats.objects_after
369
- );
370
- info!(
371
- "{} -> <b>{}</b> raw size",
372
- friendly_size(stats.size_before),
373
- friendly_size(stats.size_after)
374
- );
375
- println!();
388
+ fn print_stats(stats: &Stats, has_scene_objects: bool) {
389
+ if has_scene_objects {
390
+ info!(
391
+ "Pruned {} -> <b>{}</b> objects",
392
+ stats.objects_before, stats.objects_after
393
+ );
394
+ info!(
395
+ "{} -> <b>{}</b> raw size",
396
+ friendly_size(stats.size_before),
397
+ friendly_size(stats.size_after)
398
+ );
399
+ println!();
400
+ }
376
401
  }
@@ -22,6 +22,15 @@ ninesols *args:
22
22
  --mode asset \
23
23
  --objects objects/ns-monsters.json \
24
24
  --output /tmp/testing/new.bundle \
25
+ --bundle-name test \
26
+ --compression none {{ args }}
27
+
28
+ ninesols-fx *args:
29
+ cargo run --release -- \
30
+ --game-dir "{{ ninesols }}" \
31
+ --mode asset \
32
+ --extra-objects objects/ns-by-type.json \
33
+ --output /tmp/testing/new.bundle \
25
34
  --bundle-name bundle \
26
35
  --compression none {{ args }}
27
36
 
@@ -0,0 +1,3 @@
1
+ {
2
+ "FXDealerMaterialTag": ["[FXDealer] 0_YeeAttack _PostureDecrease"]
3
+ }
@@ -20,6 +20,26 @@ pub trait EnvResolver {
20
20
  fn read_path(&self, path: &Path) -> Result<Vec<u8>, std::io::Error>;
21
21
  fn all_files(&self) -> Result<Vec<PathBuf>, std::io::Error>;
22
22
 
23
+ fn serialized_files(&self) -> Result<Vec<PathBuf>, std::io::Error> {
24
+ Ok(self
25
+ .all_files()?
26
+ .into_iter()
27
+ .filter_map(|path| {
28
+ let name = path.file_name()?.to_str()?;
29
+ let is_level = name
30
+ .strip_prefix("level")
31
+ .and_then(|x| x.parse::<usize>().ok())
32
+ .is_some();
33
+
34
+ let is_serialized = is_level
35
+ || path.extension().is_some_and(|e| e == "assets")
36
+ || name == "globalgamemanagers";
37
+
38
+ is_serialized.then_some(path)
39
+ })
40
+ .collect())
41
+ }
42
+
23
43
  fn level_files(&self) -> Result<Vec<usize>, std::io::Error> {
24
44
  Ok(self
25
45
  .all_files()?
@@ -41,6 +41,35 @@ impl GameFiles {
41
41
  level_files,
42
42
  })
43
43
  }
44
+
45
+ pub fn read(&self, filename: &str) -> Result<Data, std::io::Error> {
46
+ match &self.level_files {
47
+ LevelFiles::Unpacked => {
48
+ let path = self.game_dir.join(filename);
49
+ let file = File::open(path)?;
50
+ let mmap = unsafe { Mmap::map(&file)? };
51
+ Ok(Data::Mmap(mmap))
52
+ }
53
+ LevelFiles::Packed(bundle) => {
54
+ let data = bundle.read_at(filename)?.ok_or_else(|| {
55
+ std::io::Error::new(std::io::ErrorKind::NotFound, "File not found in bundle")
56
+ })?;
57
+ Ok(Data::InMemory(data))
58
+ }
59
+ }
60
+ }
61
+ }
62
+ pub enum Data {
63
+ InMemory(Vec<u8>),
64
+ Mmap(Mmap),
65
+ }
66
+ impl AsRef<[u8]> for Data {
67
+ fn as_ref(&self) -> &[u8] {
68
+ match self {
69
+ Data::InMemory(data) => data.as_slice(),
70
+ Data::Mmap(mmap) => mmap.as_ref(),
71
+ }
72
+ }
44
73
  }
45
74
 
46
75
  impl EnvResolver for GameFiles {