init static method
Opens the packs. Call once at start-up, before any packed asset is
loaded. packs are Flutter asset paths listed in the game's pubspec.
Implementation
static Future<void> init({
required List<int> key,
List<String> packs = const ['assets/packs/game.owp'],
String? devDir = 'protected',
}) async {
AssetPack.devDir = devDir;
_keys = PackKeys.fromMaster(key);
_packs.clear();
_index.clear();
_indexLower.clear();
for (final name in packs) {
Uint8List bytes;
try {
final data = await rootBundle.load(name);
bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
} catch (e) {
// Fine while developing from devDir; a real problem in release.
if (kDebugMode && devDir != null) {
debugPrint('AssetPack: $name not found, using $devDir/ only');
continue;
}
throw AssetPackException('Could not load pack $name: $e');
}
final index = readPackIndex(bytes, _keys!);
final packNo = _packs.length;
_packs.add(_OpenPack(bytes, index.dataStart));
for (final e in index.entries) {
final loc = _Located(packNo, e);
_index[e.path] = loc;
_indexLower[e.path.toLowerCase()] = loc;
}
}
}