Skip to content

Commit

Permalink
Merge pull request #9 from arceusVen1/feat-header-2-parsing
Browse files Browse the repository at this point in the history
fix minor reading details and naming + early header 2 parsing
  • Loading branch information
arceusVen1 committed Feb 24, 2024
2 parents 1931e89 + c8d23a7 commit 703e811
Show file tree
Hide file tree
Showing 24 changed files with 1,248 additions and 169 deletions.
Binary file added docs/gsf/gsf_full.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,034 changes: 1,034 additions & 0 deletions docs/gsf/kaitai/gsf.ksy

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions lib/classes/gsf/gsf.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/header.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/header.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header2/header2.dart';

class GSF {
const GSF({
GSF({
required this.header,
required this.header2,
});

final Header header;
late final Header2 header2;

GSF.fromBytes(Uint8List bytes) : header = Header.fromBytes(bytes);
GSF.fromBytes(Uint8List bytes) : header = Header.fromBytes(bytes) {
header2 = Header2.fromBytes(bytes, header.getEndOffset());
}

@override
String toString() {
Expand Down
32 changes: 32 additions & 0 deletions lib/classes/gsf/header/anim_flags_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class AnimFlagTable extends GsfPart {
late final Standard4BytesData<int> nameLength;

AnimFlagTable.fromBytes(Uint8List bytes, int offset) : super(offset: offset) {
nameLength = Standard4BytesData(
position: 0,
bytes: bytes,
offset: offset,
);

name = GsfData.fromPosition(
relativePos: nameLength.relativeEnd,
length: nameLength.value,
bytes: bytes,
offset: offset,
);
}

@override
int getEndOffset() {
return name.offsettedLength;
}

@override
String toString() {
return 'AnimFlagsTable: $name';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DustTrailInfo extends GsfPart {
bytes,
entries.isNotEmpty
? entries.last.getEndOffset()
: entryCount.offsettedLength(offset),
: entryCount.offsettedLength,
));
}
}
Expand All @@ -51,7 +51,7 @@ class DustTrailInfo extends GsfPart {
int getEndOffset() {
return entries.isNotEmpty
? entries.last.getEndOffset()
: entryCount.offsettedLength(offset);
: entryCount.offsettedLength;
}

@override
Expand Down Expand Up @@ -87,6 +87,6 @@ class DustTrailEntry extends GsfPart {

@override
int getEndOffset() {
return valueChars.offsettedLength(offset);
return valueChars.offsettedLength;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/dust_trail_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/dust_trail_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class DustTrailTable extends GsfPart {
Expand All @@ -23,7 +23,7 @@ class DustTrailTable extends GsfPart {
bytes,
dustTrailInfos.isNotEmpty
? dustTrailInfos.last.getEndOffset()
: dustTrailCount.offsettedLength(offset),
: dustTrailCount.offsettedLength,
),
);
}
Expand All @@ -33,7 +33,7 @@ class DustTrailTable extends GsfPart {
int getEndOffset() {
return dustTrailInfos.isNotEmpty
? dustTrailInfos.last.getEndOffset()
: dustTrailCount.offsettedLength(offset);
: dustTrailCount.offsettedLength;
}

@override
Expand Down
71 changes: 50 additions & 21 deletions lib/classes/gsf/header.dart → lib/classes/gsf/header/header.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/dust_trail_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/model_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/sound_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/walk_transition_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/anim_flags_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/dust_trail_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/model_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/sound_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/walk_transition_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class Header extends GsfPart {
Header({
required this.name,
required this.modelCount,
required this.soundTable,
required this.modelInfos,
required this.dustTrailTable,
required this.walkTransitionTable1,
required this.walkTransitionTable2,
}) : super(offset: 0);

late final GsfData<int> _magic;
late final Standard4BytesData<int> _version;

late final Standard4BytesData<int> contentTableOffset;
late final Standard4BytesData<int> nameLength;
late final GsfData<String> name;
late final Standard4BytesData<int> modelCount;
late final List<ModelInfo> modelInfos;
late final SoundTable soundTable;
late final DustTrailTable dustTrailTable;
late final WalkTransitionTable walkTransitionTable1;
late final WalkTransitionTable
walkTransitionTable2; // there seems to be 2 transitions tables
late final Standard4BytesData<int> animFlagsCount;
late final List<AnimFlagTable> animFlagsTables = [];
late final Standard4BytesData<int> walkTransitionsCount;
late final List<WalkTransitionTable> walkTransitionTables = [];

Header.fromBytes(Uint8List bytes) : super(offset: 0) {
_magic = GsfData.fromPosition(
Expand All @@ -51,7 +49,10 @@ class Header extends GsfPart {
);

modelCount = Standard4BytesData<int>(
position: name.relativeEnd, bytes: bytes, offset: offset);
position: name.relativeEnd,
bytes: bytes,
offset: offset,
);
print("modelCount: $modelCount");
modelInfos = [];
for (var i = 0; i < modelCount.value; i++) {
Expand All @@ -60,31 +61,57 @@ class Header extends GsfPart {
bytes,
modelInfos.isNotEmpty
? modelInfos.last.getEndOffset()
: modelCount.offsettedLength(offset),
: modelCount.offsettedLength,
),
);
}
soundTable = SoundTable.fromBytes(
bytes,
modelInfos.isNotEmpty
? modelInfos.last.getEndOffset()
: modelCount.offsettedLength(offset),
: modelCount.offsettedLength,
);

dustTrailTable = DustTrailTable.fromBytes(
bytes,
soundTable.getEndOffset(),
);

walkTransitionTable1 = WalkTransitionTable.fromBytes(
bytes,
dustTrailTable.getEndOffset(),
animFlagsCount = Standard4BytesData(
position: dustTrailTable.getEndOffset() - offset,
bytes: bytes,
offset: offset,
);

walkTransitionTable2 = WalkTransitionTable.fromBytes(
bytes,
walkTransitionTable1.getEndOffset(),
for (var i = 0; i < animFlagsCount.value; i++) {
animFlagsTables.add(
AnimFlagTable.fromBytes(
bytes,
animFlagsTables.isNotEmpty
? animFlagsTables.last.getEndOffset()
: animFlagsCount.offsettedLength,
),
);
}

walkTransitionsCount = Standard4BytesData(
position: animFlagsTables.isNotEmpty
? animFlagsTables.last.getEndOffset() - offset
: animFlagsCount.offsettedLength,
bytes: bytes,
offset: offset,
);

for (var i = 0; i < walkTransitionsCount.value; i++) {
walkTransitionTables.add(
WalkTransitionTable.fromBytes(
bytes,
walkTransitionTables.isNotEmpty
? walkTransitionTables.last.getEndOffset()
: walkTransitionsCount.offsettedLength,
),
);
}
}

@override
Expand All @@ -101,6 +128,8 @@ class Header extends GsfPart {

@override
int getEndOffset() {
return walkTransitionTable2.getEndOffset();
return walkTransitionTables.isNotEmpty
? walkTransitionTables.last.getEndOffset()
: walkTransitionsCount.offsettedLength;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/sound_indices.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/sound_indices.dart';
import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class ModelAnim extends GsfPart {
ModelAnim({required super.offset});

late final Standard4BytesData<int> nameLength;
late final GsfData<String> name;
late final Standard4BytesData<int> index;
late final SoundIndices soundIndices;
late final Standard4BytesData<UnknowData> unknownData;
Expand All @@ -25,7 +24,7 @@ class ModelAnim extends GsfPart {
index = Standard4BytesData(
position: name.relativeEnd, bytes: bytes, offset: offset);

soundIndices = SoundIndices.fromBytes(bytes, index.offsettedLength(offset));
soundIndices = SoundIndices.fromBytes(bytes, index.offsettedLength);
unknownData = Standard4BytesData(
position: index.relativeEnd + soundIndices.length,
bytes: bytes,
Expand All @@ -35,7 +34,7 @@ class ModelAnim extends GsfPart {

@override
int getEndOffset() {
return unknownData.offsettedLength(offset);
return unknownData.offsettedLength;
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/model_anim.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/walk_set_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/model_anim.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/walk_set_table.dart';
import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class ModelInfo extends GsfPart {
ModelInfo({
required offset,
required this.name,
required this.index,
required this.animCount,
required this.modelAnims,
required this.walkSetTable,
}) : super(offset: offset);

late final Standard4BytesData<int> nameLength;
late final GsfData<String> name;
late final Standard4BytesData<int> index;
late final Standard4BytesData<int> animCount;
late final List<ModelAnim>
Expand Down Expand Up @@ -46,7 +44,7 @@ class ModelInfo extends GsfPart {
bytes,
modelAnims.isNotEmpty
? modelAnims.last.getEndOffset()
: animCount.offsettedLength(offset),
: animCount.offsettedLength,
));
}
}
Expand All @@ -55,7 +53,7 @@ class ModelInfo extends GsfPart {
bytes,
modelAnims.isNotEmpty
? modelAnims.last.getEndOffset()
: animCount.offsettedLength(offset),
: animCount.offsettedLength,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class SoundIndices extends GsfPart {

@override
int getEndOffset() {
return count.offsettedLength(offset) + indices.length * 4;
return indices.isNotEmpty ? indices.last.offsettedLength : count.offsettedLength ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class SoundInfo extends GsfPart {
late final Standard4BytesData<int> nameLength;
late final GsfData<String> name;
late final Standard4BytesData<int> startFrame;
late final Standard4BytesData<int> volume;
late final Standard4BytesData<int> speed;
late final Standard4BytesData<double> speed;
late final GsfData<UnknowData> unknownData; // 16 unknown bytes
late final Standard4BytesData<int> soundGroupNameLength;
late final GsfData<String> soundGroupName;
Expand Down Expand Up @@ -48,7 +47,7 @@ class SoundInfo extends GsfPart {

@override
int getEndOffset() {
return soundGroupName.offsettedLength(offset);
return soundGroupName.offsettedLength;
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:typed_data';

import 'package:paraworld_gsf_viewer/classes/gsf/sound_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf/header/sound_info.dart';
import 'package:paraworld_gsf_viewer/classes/gsf_data.dart';

class SoundTable extends GsfPart {
Expand All @@ -21,7 +21,7 @@ class SoundTable extends GsfPart {
bytes,
soundInfos.isNotEmpty
? soundInfos.last.getEndOffset()
: soundCount.offsettedLength(offset),
: soundCount.offsettedLength,
),
);
}
Expand All @@ -31,7 +31,7 @@ class SoundTable extends GsfPart {
int getEndOffset() {
return soundInfos.isNotEmpty
? soundInfos.last.getEndOffset()
: soundCount.offsettedLength(offset);
: soundCount.offsettedLength;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,6 @@ class WalkSet extends GsfPart {

@override
int getEndOffset() {
return name.offsettedLength(offset);
return name.offsettedLength;
}
}
Loading

0 comments on commit 703e811

Please sign in to comment.