Skip to content

Commit

Permalink
feat: Start decoding sb region using kaitai
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed Jun 11, 2024
1 parent 0e4bff1 commit 7c6aae3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion acd/export_l5x.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __post_init__(self):

log.info("Getting records from ACD Comments file and storing in sqllite database")
comments_db = DbExtract(os.path.join(self._temp_dir, "Comments.Dat")).read()
for record in comments_db.records:
for record in comments_db.records.record:
CommentsRecord(self._cur, record)
self._db.commit()

Expand Down
Empty file.
18 changes: 17 additions & 1 deletion acd/sbregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sqlite3 import Cursor

from acd.dbextract import DatRecord
from acd.generated.sbregion.fafa_sbregions import FafaSbregions


@dataclass
Expand All @@ -12,7 +13,22 @@ class SbRegionRecord:
dat_record: DatRecord

def __post_init__(self):
if self.dat_record.identifier == b'\xfa\xfa':

if self.dat_record.identifier == 64250:
r = FafaSbregions.from_bytes(self.dat_record.record.record_buffer)
else:
return

if self.language_type == "Rung NT":

query: str = "INSERT INTO comps VALUES (?, ?, ?, ?, ?, ?)"
entry: tuple = (
r.header.object_id, r.header.parent_id, r.header.record_name, r.header.seq_number, r.header.record_type,
r.record_buffer)
self._cur.execute(query, entry)

def __post_init__(self):
if self.dat_record.identifier == 64250:
record_length_offset = 0
self.record_length = struct.unpack(
"I", self.dat_record.record[0: record_length_offset + 4]
Expand Down
22 changes: 4 additions & 18 deletions resources/templates/SbRegion/FAFA_SbRegion.ksy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta:
id: fafa_comps
id: fafa_sbregions
endian: le
tags:
- version: 33
Expand All @@ -12,21 +12,7 @@ seq:
size: record_length - 144 - 4
types:
header:
instances:
oridinal:
pos: 0x04
seq:
- id: sb_regions
type: u2
record_type:
pos: 0x06
type: u2
object_id:
pos: 0x10
type: u4
parent_id:
pos: 0x14
type: u4
record_name:
pos: 0x18
type: str
size: 124
encoding: UTF-16

4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def run(self):
subprocess.run(
["ksc", "-t", "python", "--outdir", "acd/generated/comps/", "--python-package", "acd.generated.comps",
"resources/templates/Comps/FAFA_Comps.ksy"])
_install.run(self)
subprocess.run(
["ksc", "-t", "python", "--outdir", "acd/generated/sbregion/", "--python-package", "acd.generated.sbregion",
"resources/templates/SbRegion/FAFA_SbRegion.ksy"])
subprocess.run(
["ksc", "-t", "python", "--outdir", "acd/generated/comps/", "--python-package", "acd.generated.comps",
"resources/templates/Comps/FDFD_Comps.ksy"])
Expand Down

0 comments on commit 7c6aae3

Please sign in to comment.