Skip to content

Commit 3d19f62

Browse files
Merge pull request #7 from Vluurie/master
remember DAT files order and duplicates; add wmb preview
2 parents 665df42 + 994d1f1 commit 3d19f62

28 files changed

+1415
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ app.*.map.json
4747
/android/app/release
4848

4949
.vscode
50+
.vs
5051
assets/bins
5152
assets/effect
5253
assets/mcdFonts

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "assets/FontAtlasGenerator"]
55
path = assets/FontAtlasGenerator
66
url = https://github.com/ArthurHeitmann/FontAtlasGenerator.git
7+
[submodule "assets/rusty_platinum_utils"]
8+
path = assets/rusty_platinum_utils
9+
url = https://github.com/ArthurHeitmann/rusty_platinum_utils.git

assets/rusty_platinum_utils

Submodule rusty_platinum_utils added at 0b159cd

lib/ffi/FfiHelper.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
import 'dart:ffi';
3+
import 'package:path/path.dart';
4+
5+
import 'RustyPlatinumUtilsFfi.dart';
6+
7+
class FfiHelper {
8+
static late final FfiHelper i;
9+
final RustyPlatinumUtils rustyPlatinumUtils;
10+
11+
12+
FfiHelper(String assetsDir) :
13+
rustyPlatinumUtils = RustyPlatinumUtils(DynamicLibrary.open(join(assetsDir, "rusty_platinum_utils", "target", "release", "rusty_platinum_utils.dll")));
14+
}

lib/ffi/RustyPlatinumUtilsFfi.dart

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
// AUTO GENERATED FILE, DO NOT EDIT.
2+
//
3+
// Generated by `package:ffigen`.
4+
// ignore_for_file: type=lint
5+
import 'dart:ffi' as ffi;
6+
7+
class RustyPlatinumUtils {
8+
/// Holds the symbol lookup function.
9+
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
10+
_lookup;
11+
12+
/// The symbols are looked up in [dynamicLibrary].
13+
RustyPlatinumUtils(ffi.DynamicLibrary dynamicLibrary)
14+
: _lookup = dynamicLibrary.lookup;
15+
16+
/// The symbols are looked up with [lookup].
17+
RustyPlatinumUtils.fromLookup(
18+
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
19+
lookup)
20+
: _lookup = lookup;
21+
22+
ffi.Pointer<ffi.Void> rpu_load_wmb(
23+
ffi.Pointer<ffi.Char> wmb_path,
24+
) {
25+
return _rpu_load_wmb(
26+
wmb_path,
27+
);
28+
}
29+
30+
late final _rpu_load_wmbPtr = _lookup<
31+
ffi.NativeFunction<
32+
ffi.Pointer<ffi.Void> Function(
33+
ffi.Pointer<ffi.Char>)>>('rpu_load_wmb');
34+
late final _rpu_load_wmb = _rpu_load_wmbPtr
35+
.asFunction<ffi.Pointer<ffi.Void> Function(ffi.Pointer<ffi.Char>)>();
36+
37+
ffi.Pointer<ffi.Void> rpu_new_context() {
38+
return _rpu_new_context();
39+
}
40+
41+
late final _rpu_new_contextPtr =
42+
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Void> Function()>>(
43+
'rpu_new_context');
44+
late final _rpu_new_context =
45+
_rpu_new_contextPtr.asFunction<ffi.Pointer<ffi.Void> Function()>();
46+
47+
ffi.Pointer<ffi.Void> rpu_new_renderer(
48+
ffi.Pointer<ffi.Void> context,
49+
int width,
50+
int height,
51+
ffi.Pointer<ffi.Void> scene_data,
52+
) {
53+
return _rpu_new_renderer(
54+
context,
55+
width,
56+
height,
57+
scene_data,
58+
);
59+
}
60+
61+
late final _rpu_new_rendererPtr = _lookup<
62+
ffi.NativeFunction<
63+
ffi.Pointer<ffi.Void> Function(ffi.Pointer<ffi.Void>, ffi.Uint32,
64+
ffi.Uint32, ffi.Pointer<ffi.Void>)>>('rpu_new_renderer');
65+
late final _rpu_new_renderer = _rpu_new_rendererPtr.asFunction<
66+
ffi.Pointer<ffi.Void> Function(
67+
ffi.Pointer<ffi.Void>, int, int, ffi.Pointer<ffi.Void>)>();
68+
69+
void rpu_drop_renderer(
70+
ffi.Pointer<ffi.Void> state,
71+
) {
72+
return _rpu_drop_renderer(
73+
state,
74+
);
75+
}
76+
77+
late final _rpu_drop_rendererPtr =
78+
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
79+
'rpu_drop_renderer');
80+
late final _rpu_drop_renderer =
81+
_rpu_drop_rendererPtr.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
82+
83+
int rpu_render(
84+
ffi.Pointer<ffi.Void> state,
85+
ffi.Pointer<ffi.Uint8> buffer,
86+
int buffer_size,
87+
int width,
88+
int height,
89+
double bg_r,
90+
double bg_g,
91+
double bg_b,
92+
double bg_a,
93+
) {
94+
return _rpu_render(
95+
state,
96+
buffer,
97+
buffer_size,
98+
width,
99+
height,
100+
bg_r,
101+
bg_g,
102+
bg_b,
103+
bg_a,
104+
);
105+
}
106+
107+
late final _rpu_renderPtr = _lookup<
108+
ffi.NativeFunction<
109+
ffi.Int32 Function(
110+
ffi.Pointer<ffi.Void>,
111+
ffi.Pointer<ffi.Uint8>,
112+
ffi.Size,
113+
ffi.Uint32,
114+
ffi.Uint32,
115+
ffi.Float,
116+
ffi.Float,
117+
ffi.Float,
118+
ffi.Float)>>('rpu_render');
119+
late final _rpu_render = _rpu_renderPtr.asFunction<
120+
int Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Uint8>, int, int, int,
121+
double, double, double, double)>();
122+
123+
void rpu_add_camera_rotation(
124+
ffi.Pointer<ffi.Void> state,
125+
double x,
126+
double y,
127+
) {
128+
return _rpu_add_camera_rotation(
129+
state,
130+
x,
131+
y,
132+
);
133+
}
134+
135+
late final _rpu_add_camera_rotationPtr = _lookup<
136+
ffi.NativeFunction<
137+
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Float,
138+
ffi.Float)>>('rpu_add_camera_rotation');
139+
late final _rpu_add_camera_rotation = _rpu_add_camera_rotationPtr
140+
.asFunction<void Function(ffi.Pointer<ffi.Void>, double, double)>();
141+
142+
void rpu_add_camera_offset(
143+
ffi.Pointer<ffi.Void> state,
144+
double x,
145+
double y,
146+
) {
147+
return _rpu_add_camera_offset(
148+
state,
149+
x,
150+
y,
151+
);
152+
}
153+
154+
late final _rpu_add_camera_offsetPtr = _lookup<
155+
ffi.NativeFunction<
156+
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Float,
157+
ffi.Float)>>('rpu_add_camera_offset');
158+
late final _rpu_add_camera_offset = _rpu_add_camera_offsetPtr
159+
.asFunction<void Function(ffi.Pointer<ffi.Void>, double, double)>();
160+
161+
void rpu_zoom_camera_by(
162+
ffi.Pointer<ffi.Void> state,
163+
double distance,
164+
) {
165+
return _rpu_zoom_camera_by(
166+
state,
167+
distance,
168+
);
169+
}
170+
171+
late final _rpu_zoom_camera_byPtr = _lookup<
172+
ffi
173+
.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Float)>>(
174+
'rpu_zoom_camera_by');
175+
late final _rpu_zoom_camera_by = _rpu_zoom_camera_byPtr
176+
.asFunction<void Function(ffi.Pointer<ffi.Void>, double)>();
177+
178+
void rpu_auto_set_target(
179+
ffi.Pointer<ffi.Void> state,
180+
) {
181+
return _rpu_auto_set_target(
182+
state,
183+
);
184+
}
185+
186+
late final _rpu_auto_set_targetPtr =
187+
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
188+
'rpu_auto_set_target');
189+
late final _rpu_auto_set_target = _rpu_auto_set_targetPtr
190+
.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
191+
192+
void rpu_set_model_visibility(
193+
ffi.Pointer<ffi.Void> state,
194+
int model_id,
195+
bool visibility,
196+
) {
197+
return _rpu_set_model_visibility(
198+
state,
199+
model_id,
200+
visibility,
201+
);
202+
}
203+
204+
late final _rpu_set_model_visibilityPtr = _lookup<
205+
ffi.NativeFunction<
206+
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Uint32,
207+
ffi.Bool)>>('rpu_set_model_visibility');
208+
late final _rpu_set_model_visibility = _rpu_set_model_visibilityPtr
209+
.asFunction<void Function(ffi.Pointer<ffi.Void>, int, bool)>();
210+
211+
ffi.Pointer<ffi.Uint32> rpu_get_model_states(
212+
ffi.Pointer<ffi.Void> state,
213+
) {
214+
return _rpu_get_model_states(
215+
state,
216+
);
217+
}
218+
219+
late final _rpu_get_model_statesPtr = _lookup<
220+
ffi.NativeFunction<
221+
ffi.Pointer<ffi.Uint32> Function(
222+
ffi.Pointer<ffi.Void>)>>('rpu_get_model_states');
223+
late final _rpu_get_model_states = _rpu_get_model_statesPtr
224+
.asFunction<ffi.Pointer<ffi.Uint32> Function(ffi.Pointer<ffi.Void>)>();
225+
}

lib/fileTypeUtils/dat/datExtractor.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import 'dart:io';
55
import 'package:path/path.dart' as path;
66

77
import '../../stateManagement/events/statusInfo.dart';
8+
import '../../utils/utils.dart';
89
import '../pak/pakExtractor.dart';
910
import '../utils/ByteDataWrapper.dart';
1011

12+
const currentDatVersion = 3;
13+
1114
/*
1215
struct {
1316
char id[4];
@@ -67,17 +70,10 @@ Future<List<String>> extractDatFiles(String datPath, { bool shouldExtractPakFile
6770
await extractedFile.writeAsBytes(bytes.readUint8List(fileSizes[i]));
6871
}
6972

70-
fileNames.sort(((a, b) {
71-
var aBaseExt = a.split(".").map((e) => e.toLowerCase()).toList();
72-
var bBaseExt = b.split(".").map((e) => e.toLowerCase()).toList();
73-
if (aBaseExt[0] == bBaseExt[0])
74-
return aBaseExt[1].compareTo(bBaseExt[1]);
75-
else
76-
return aBaseExt[0].compareTo(bBaseExt[0]);
77-
}));
7873
dynamic jsonMetadata = {
79-
"version": 1,
80-
"files": fileNames,
74+
"version": currentDatVersion,
75+
"files": deduplicate(fileNames),
76+
"original_order": fileNames,
8177
"basename": path.basename(datPath).split(".")[0],
8278
"ext": path.basename(datPath).split(".")[1],
8379
};
@@ -141,3 +137,22 @@ Future<List<String>> peekDatFileNames(String datPath) async {
141137
.generate(header.fileNumber, (index) =>
142138
bytes.readString(nameLength).split("\u0000")[0]);
143139
}
140+
141+
142+
Future<void> updateDatInfoFileOriginalOrder(String datPath, String extractDir) async {
143+
var datInfoPath = path.join(extractDir, "dat_info.json");
144+
if (!await File(datInfoPath).exists())
145+
return;
146+
147+
var bytes = await ByteDataWrapper.fromFile(datPath);
148+
var header = _DatHeader(bytes);
149+
bytes.position = header.fileNamesOffset;
150+
var nameLength = bytes.readUint32();
151+
var fileNames = List.generate(header.fileNumber, (index) => bytes.readString(nameLength).split("\u0000")[0]);
152+
153+
var datInfo = jsonDecode(await File(datInfoPath).readAsString()) as Map;
154+
datInfo["original_order"] = fileNames;
155+
datInfo["version"] = currentDatVersion;
156+
var datInfoJson = const JsonEncoder.withIndent("\t").convert(datInfo);
157+
await File(datInfoPath).writeAsString(datInfoJson);
158+
}

0 commit comments

Comments
 (0)