Skip to content

Commit

Permalink
edited MCD files can now generate new texture files (based on the in-…
Browse files Browse the repository at this point in the history
…game fonts)
  • Loading branch information
ArthurHeitmann committed Oct 30, 2022
1 parent fa51a61 commit 9f63dc2
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 99 deletions.
12 changes: 12 additions & 0 deletions lib/background/searchService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:isolate';
import 'package:path/path.dart' as path;
import 'package:xml/xml.dart';

import '../fileTypeUtils/mcd/mcdIO.dart';
import '../fileTypeUtils/tmd/tmdReader.dart';
import '../fileTypeUtils/yax/hashToStringMap.dart';
import '../stateManagement/Property.dart';
Expand Down Expand Up @@ -260,6 +261,10 @@ class _SearchServiceWorker {
var entries = await readTmdFile(file.path);
return entries.map((e) => e.toString()).join("\n");
}
else if (file.path.endsWith(".mcd")) {
var mcd = await McdFile.fromFile(file.path);
return mcd.toString();
}
try {
return await file.readAsString();
}
Expand All @@ -283,6 +288,13 @@ class _SearchServiceWorker {
.expand((e) => e)
.toList();
}
else if (file.path.endsWith(".mcd")) {
var mcd = await McdFile.fromFile(file.path);
return mcd.events
.map((e) => e.toString().split("\n"))
.expand((e) => e)
.toList();
}
try {
return await file.readAsLines();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,14 @@ class McdFileSymbol {
late final String char;
final int glyphId;

late final McdFileFont _font;
late final McdFileGlyph _glyph;

McdFileSymbol(this.fontId, this.charCode, this.glyphId, this._font, this._glyph) :
McdFileSymbol(this.fontId, this.charCode, this.glyphId) :
char = String.fromCharCode(charCode);

McdFileSymbol.read(ByteDataWrapper bytes, List<McdFileFont> fonts, List<McdFileGlyph> glyphs) :
fontId = bytes.readUint16(),
charCode = bytes.readUint16(),
glyphId = bytes.readUint32() {
char = String.fromCharCode(charCode);
_font = fonts.firstWhere((f) => f.id == fontId);
_glyph = glyphs[glyphId];
// if (_glyph.height != _font.height) {
// print("Warning: Glyph height (${_glyph.height}) does not match font height (${_font.height})");
// }
Expand Down Expand Up @@ -460,4 +455,9 @@ class McdFile {

await File(path).writeAsBytes(bytes.buffer.asUint8List());
}

@override
String toString() {
return events.join("\n\n");
}
}
46 changes: 46 additions & 0 deletions lib/fileTypeUtils/wta/wtaReader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct {
} header;
*/
import 'dart:io';
import 'dart:typed_data';

import '../utils/ByteDataWrapper.dart';

Expand All @@ -34,6 +35,17 @@ class WtaFileHeader {
offsetTextureFlags = bytes.readUint32(),
offsetTextureIdx = bytes.readUint32(),
offsetTextureInfo = bytes.readUint32();

void write(ByteDataWrapper bytes) {
bytes.writeString(id);
bytes.writeInt32(unknown);
bytes.writeInt32(numTex);
bytes.writeUint32(offsetTextureOffsets);
bytes.writeUint32(offsetTextureSizes);
bytes.writeUint32(offsetTextureFlags);
bytes.writeUint32(offsetTextureIdx);
bytes.writeUint32(offsetTextureInfo);
}
}

class WtaFileTextureInfo {
Expand All @@ -43,6 +55,12 @@ class WtaFileTextureInfo {
WtaFileTextureInfo.read(ByteDataWrapper bytes) :
format = bytes.readUint32(),
data = bytes.readUint32List(4);

void write(ByteDataWrapper bytes) {
bytes.writeUint32(format);
for (var d in data)
bytes.writeUint32(d);
}
}

class WtaFile {
Expand Down Expand Up @@ -74,4 +92,32 @@ class WtaFile {
var bytes = ByteDataWrapper((await File(path).readAsBytes()).buffer);
return WtaFile.read(bytes);
}

Future<void> writeToFile(String path) async {
var fileSize = header.offsetTextureInfo + textureInfo.length * 0x14;
var bytes = ByteDataWrapper(ByteData(fileSize).buffer);
header.write(bytes);

bytes.position = header.offsetTextureOffsets;
for (var i = 0; i < textureOffsets.length; i++)
bytes.writeUint32(textureOffsets[i]);

bytes.position = header.offsetTextureSizes;
for (var i = 0; i < textureSizes.length; i++)
bytes.writeUint32(textureSizes[i]);

bytes.position = header.offsetTextureFlags;
for (var i = 0; i < textureFlags.length; i++)
bytes.writeUint32(textureFlags[i]);

bytes.position = header.offsetTextureIdx;
for (var i = 0; i < textureIdx.length; i++)
bytes.writeUint32(textureIdx[i]);

bytes.position = header.offsetTextureInfo;
for (var i = 0; i < textureInfo.length; i++)
textureInfo[i].write(bytes);

await File(path).writeAsBytes(bytes.buffer.asUint8List());
}
}
2 changes: 1 addition & 1 deletion lib/randomScripts/mcdFontExtractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:io';
import 'package:image/image.dart';
import 'package:path/path.dart';

import '../fileTypeUtils/mcd/mcdReader.dart';
import '../fileTypeUtils/mcd/mcdIO.dart';
import '../fileTypeUtils/utils/ByteDataWrapper.dart';

const rootDir = r"D:\delete\mods\na\blender\extracted";
Expand Down
Loading

0 comments on commit 9f63dc2

Please sign in to comment.