@gaialabs/core 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +10 -20
- package/dist/index.d.ts +10 -20
- package/dist/index.js +66 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -114
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -763,29 +763,19 @@ declare class AssemblerState {
|
|
|
763
763
|
}
|
|
764
764
|
|
|
765
765
|
declare class RomGenerator {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
private
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
generateProject(
|
|
775
|
-
private initializeDatabase;
|
|
776
|
-
private initializeChunks;
|
|
777
|
-
private writeScriptTexts;
|
|
778
|
-
private applyBaseRom;
|
|
766
|
+
readonly projectName?: string;
|
|
767
|
+
crc: number;
|
|
768
|
+
branchId: string;
|
|
769
|
+
dbRoot: DbRoot;
|
|
770
|
+
private sourceData;
|
|
771
|
+
constructor(projectName?: string);
|
|
772
|
+
initialize(): Promise<void>;
|
|
773
|
+
validateAndDownload(sourceData: Uint8Array): Promise<boolean>;
|
|
774
|
+
generateProject(modules: string[], manualFiles?: ChunkFile[]): Promise<Uint8Array>;
|
|
779
775
|
private applyProjectInit;
|
|
780
|
-
private applySelectedModules;
|
|
781
776
|
private assembleCodeFromText;
|
|
782
|
-
private applyCodePatches;
|
|
783
|
-
private calculateSizes;
|
|
784
|
-
private performLayout;
|
|
785
|
-
private rebaseAssemblies;
|
|
786
777
|
private generateAsmIncludeLookups;
|
|
787
|
-
applyPatchFile(chunkFile: ChunkFile): void;
|
|
788
|
-
private generateBlockLookup;
|
|
778
|
+
applyPatchFile(chunkFile: ChunkFile, chunkFiles: ChunkFile[], asmFiles: ChunkFile[], patchFiles: ChunkFile[]): void;
|
|
789
779
|
private writeRom;
|
|
790
780
|
}
|
|
791
781
|
|
package/dist/index.d.ts
CHANGED
|
@@ -763,29 +763,19 @@ declare class AssemblerState {
|
|
|
763
763
|
}
|
|
764
764
|
|
|
765
765
|
declare class RomGenerator {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
private
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
generateProject(
|
|
775
|
-
private initializeDatabase;
|
|
776
|
-
private initializeChunks;
|
|
777
|
-
private writeScriptTexts;
|
|
778
|
-
private applyBaseRom;
|
|
766
|
+
readonly projectName?: string;
|
|
767
|
+
crc: number;
|
|
768
|
+
branchId: string;
|
|
769
|
+
dbRoot: DbRoot;
|
|
770
|
+
private sourceData;
|
|
771
|
+
constructor(projectName?: string);
|
|
772
|
+
initialize(): Promise<void>;
|
|
773
|
+
validateAndDownload(sourceData: Uint8Array): Promise<boolean>;
|
|
774
|
+
generateProject(modules: string[], manualFiles?: ChunkFile[]): Promise<Uint8Array>;
|
|
779
775
|
private applyProjectInit;
|
|
780
|
-
private applySelectedModules;
|
|
781
776
|
private assembleCodeFromText;
|
|
782
|
-
private applyCodePatches;
|
|
783
|
-
private calculateSizes;
|
|
784
|
-
private performLayout;
|
|
785
|
-
private rebaseAssemblies;
|
|
786
777
|
private generateAsmIncludeLookups;
|
|
787
|
-
applyPatchFile(chunkFile: ChunkFile): void;
|
|
788
|
-
private generateBlockLookup;
|
|
778
|
+
applyPatchFile(chunkFile: ChunkFile, chunkFiles: ChunkFile[], asmFiles: ChunkFile[], patchFiles: ChunkFile[]): void;
|
|
789
779
|
private writeRom;
|
|
790
780
|
}
|
|
791
781
|
|
package/dist/index.js
CHANGED
|
@@ -3660,88 +3660,72 @@ var Assembler = class {
|
|
|
3660
3660
|
}
|
|
3661
3661
|
};
|
|
3662
3662
|
var RomGenerator = class {
|
|
3663
|
-
constructor(
|
|
3664
|
-
this.
|
|
3665
|
-
this.
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
this.asmFiles = [];
|
|
3663
|
+
constructor(projectName) {
|
|
3664
|
+
this.crc = 0;
|
|
3665
|
+
this.branchId = "";
|
|
3666
|
+
//private chunkFiles: ChunkFile[] = [];
|
|
3667
|
+
//private asmFiles: ChunkFile[] = [];
|
|
3669
3668
|
this.dbRoot = {};
|
|
3670
|
-
this.sourceData =
|
|
3671
|
-
this.
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
const
|
|
3680
|
-
this.
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
this.calculateSizes();
|
|
3687
|
-
this.performLayout();
|
|
3688
|
-
this.rebaseAssemblies();
|
|
3689
|
-
this.generateAsmIncludeLookups();
|
|
3690
|
-
const blockLookup = this.generateBlockLookup();
|
|
3691
|
-
const outRom = await this.writeRom(blockLookup);
|
|
3692
|
-
return outRom;
|
|
3693
|
-
}
|
|
3694
|
-
//Grab structures from supabase
|
|
3695
|
-
async initializeDatabase(projectName) {
|
|
3696
|
-
this.dbRoot = await shared.DbRootUtils.fromSupabaseProject({ projectName });
|
|
3669
|
+
this.sourceData = new Uint8Array();
|
|
3670
|
+
this.projectName = projectName;
|
|
3671
|
+
}
|
|
3672
|
+
async initialize() {
|
|
3673
|
+
var projectData = await shared.summaryFromSupabaseByProject(this.projectName);
|
|
3674
|
+
this.crc = projectData.project.baseRom.gameRom.crc;
|
|
3675
|
+
this.branchId = projectData.id;
|
|
3676
|
+
}
|
|
3677
|
+
async validateAndDownload(sourceData) {
|
|
3678
|
+
const calc = shared.crc32_buffer(sourceData);
|
|
3679
|
+
if (calc === this.crc) {
|
|
3680
|
+
this.dbRoot = await shared.DbRootUtils.fromSupabaseProject(this.projectName, this.branchId);
|
|
3681
|
+
this.sourceData = sourceData;
|
|
3682
|
+
return true;
|
|
3683
|
+
}
|
|
3684
|
+
return false;
|
|
3697
3685
|
}
|
|
3698
|
-
|
|
3699
|
-
|
|
3686
|
+
async generateProject(modules, manualFiles) {
|
|
3687
|
+
if (!this.dbRoot) throw new Error("Database not initialized");
|
|
3688
|
+
if (!this.sourceData) throw new Error("Source data not initialized");
|
|
3700
3689
|
const reader = new BlockReader(this.sourceData, this.dbRoot);
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
}
|
|
3705
|
-
//Convert blocks to text
|
|
3706
|
-
writeScriptTexts(reader) {
|
|
3690
|
+
const chunkFiles = reader.analyzeAndResolve();
|
|
3691
|
+
const asmFiles = chunkFiles.filter((b) => b.type === shared.BinType.Assembly);
|
|
3692
|
+
const patchFiles = [];
|
|
3707
3693
|
const writer = new BlockWriter(reader);
|
|
3708
|
-
for (const block of
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
for (const
|
|
3715
|
-
|
|
3716
|
-
|
|
3694
|
+
for (const block of asmFiles) block.textData = writer.generateAsm(block);
|
|
3695
|
+
for (const chunkFile of this.dbRoot.baseRomFiles) this.applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles);
|
|
3696
|
+
const moduleLookup = this.applyProjectInit(chunkFiles, asmFiles, patchFiles);
|
|
3697
|
+
for (const module of modules) {
|
|
3698
|
+
for (const file of moduleLookup.get(module)) this.applyPatchFile(file, chunkFiles, asmFiles, patchFiles);
|
|
3699
|
+
}
|
|
3700
|
+
for (const file of manualFiles ?? []) this.applyPatchFile(file, chunkFiles, asmFiles, patchFiles);
|
|
3701
|
+
this.assembleCodeFromText(asmFiles);
|
|
3702
|
+
RomProcessor.applyPatches(asmFiles, patchFiles);
|
|
3703
|
+
for (const asm of chunkFiles) shared.ChunkFileUtils.calculateSize(asm);
|
|
3704
|
+
const layout = new RomLayout(chunkFiles);
|
|
3705
|
+
layout.organize();
|
|
3706
|
+
for (const file of asmFiles) shared.ChunkFileUtils.rebase(file);
|
|
3707
|
+
this.generateAsmIncludeLookups(asmFiles);
|
|
3708
|
+
const blockLookup = /* @__PURE__ */ new Map();
|
|
3709
|
+
for (const f of chunkFiles) blockLookup.set(f.name.toUpperCase(), f.location);
|
|
3710
|
+
const outRom = await this.writeRom(blockLookup, this.dbRoot.entryPoints, chunkFiles, asmFiles);
|
|
3711
|
+
return outRom;
|
|
3717
3712
|
}
|
|
3718
|
-
applyProjectInit() {
|
|
3713
|
+
applyProjectInit(chunkFiles, asmFiles, patchFiles) {
|
|
3714
|
+
const moduleLookup = /* @__PURE__ */ new Map();
|
|
3719
3715
|
for (const chunkFile of this.dbRoot.projectFiles) {
|
|
3720
3716
|
console.log(`Processing patch: ${chunkFile.name}`);
|
|
3721
3717
|
if (chunkFile.group) {
|
|
3722
3718
|
let modArray;
|
|
3723
|
-
if (!
|
|
3724
|
-
|
|
3725
|
-
} else {
|
|
3726
|
-
modArray = this.moduleLookup.get(chunkFile.group);
|
|
3727
|
-
}
|
|
3719
|
+
if (!moduleLookup.has(chunkFile.group)) moduleLookup.set(chunkFile.group, modArray = []);
|
|
3720
|
+
else modArray = moduleLookup.get(chunkFile.group);
|
|
3728
3721
|
modArray.push(chunkFile);
|
|
3729
|
-
} else
|
|
3730
|
-
this.applyPatchFile(chunkFile);
|
|
3731
|
-
}
|
|
3732
|
-
}
|
|
3733
|
-
}
|
|
3734
|
-
//Apply selected project modules
|
|
3735
|
-
applySelectedModules() {
|
|
3736
|
-
for (const module of this.moduleList) {
|
|
3737
|
-
for (const file of this.moduleLookup.get(module)) {
|
|
3738
|
-
this.applyPatchFile(file);
|
|
3739
|
-
}
|
|
3722
|
+
} else this.applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles);
|
|
3740
3723
|
}
|
|
3724
|
+
return moduleLookup;
|
|
3741
3725
|
}
|
|
3742
3726
|
//Assemble code from script text
|
|
3743
|
-
assembleCodeFromText() {
|
|
3744
|
-
for (const block of
|
|
3727
|
+
assembleCodeFromText(asmFiles) {
|
|
3728
|
+
for (const block of asmFiles) {
|
|
3745
3729
|
const assembler = new Assembler(this.dbRoot, block.textData);
|
|
3746
3730
|
const { blocks, includes, reqBank } = assembler.parseAssembly();
|
|
3747
3731
|
block.parts = blocks;
|
|
@@ -3749,31 +3733,10 @@ var RomGenerator = class {
|
|
|
3749
3733
|
block.bank = reqBank ?? void 0;
|
|
3750
3734
|
}
|
|
3751
3735
|
}
|
|
3752
|
-
//Apply patches
|
|
3753
|
-
applyCodePatches() {
|
|
3754
|
-
RomProcessor.applyPatches(this.asmFiles, this.patchFiles);
|
|
3755
|
-
}
|
|
3756
|
-
//Calculate sizes
|
|
3757
|
-
calculateSizes() {
|
|
3758
|
-
for (const asm of this.chunkFiles) {
|
|
3759
|
-
shared.ChunkFileUtils.calculateSize(asm);
|
|
3760
|
-
}
|
|
3761
|
-
}
|
|
3762
|
-
// Assign locations
|
|
3763
|
-
performLayout() {
|
|
3764
|
-
const layout = new RomLayout(this.chunkFiles);
|
|
3765
|
-
layout.organize();
|
|
3766
|
-
}
|
|
3767
|
-
// Rebase assemblies
|
|
3768
|
-
rebaseAssemblies() {
|
|
3769
|
-
for (const file of this.asmFiles) {
|
|
3770
|
-
shared.ChunkFileUtils.rebase(file);
|
|
3771
|
-
}
|
|
3772
|
-
}
|
|
3773
3736
|
// Build include lookup map per asm file
|
|
3774
|
-
generateAsmIncludeLookups() {
|
|
3775
|
-
for (const f of
|
|
3776
|
-
const includeBlocks =
|
|
3737
|
+
generateAsmIncludeLookups(asmFiles) {
|
|
3738
|
+
for (const f of asmFiles) {
|
|
3739
|
+
const includeBlocks = asmFiles.filter((x) => f.includes?.has(x.name.toUpperCase())).flatMap((x) => x.parts).filter((b) => !!b.label);
|
|
3777
3740
|
f.includeLookup = /* @__PURE__ */ new Map();
|
|
3778
3741
|
for (const b of includeBlocks) {
|
|
3779
3742
|
if (b.label) f.includeLookup.set(b.label.toUpperCase(), b);
|
|
@@ -3783,43 +3746,33 @@ var RomGenerator = class {
|
|
|
3783
3746
|
}
|
|
3784
3747
|
}
|
|
3785
3748
|
}
|
|
3786
|
-
applyPatchFile(chunkFile) {
|
|
3749
|
+
applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles) {
|
|
3787
3750
|
console.log(`Processing patch: ${chunkFile.name}`);
|
|
3788
|
-
const existing =
|
|
3751
|
+
const existing = chunkFiles.find((x) => x.name === chunkFile.name);
|
|
3789
3752
|
if (chunkFile.type === shared.BinType.Patch || chunkFile.type === shared.BinType.Assembly) {
|
|
3790
3753
|
if (existing) {
|
|
3791
3754
|
existing.textData = chunkFile.textData;
|
|
3792
3755
|
} else {
|
|
3793
3756
|
if (chunkFile.type === shared.BinType.Patch) {
|
|
3794
|
-
|
|
3757
|
+
patchFiles.push(chunkFile);
|
|
3795
3758
|
}
|
|
3796
|
-
|
|
3797
|
-
|
|
3759
|
+
asmFiles.push(chunkFile);
|
|
3760
|
+
chunkFiles.push(chunkFile);
|
|
3798
3761
|
}
|
|
3799
3762
|
} else {
|
|
3800
3763
|
if (existing) {
|
|
3801
3764
|
existing.rawData = chunkFile.rawData;
|
|
3802
3765
|
existing.size = chunkFile.size;
|
|
3803
3766
|
} else {
|
|
3804
|
-
|
|
3767
|
+
chunkFiles.push(chunkFile);
|
|
3805
3768
|
}
|
|
3806
3769
|
}
|
|
3807
3770
|
}
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
const
|
|
3811
|
-
for (const f of this.chunkFiles) {
|
|
3812
|
-
blockLookup.set(f.name.toUpperCase(), f.location);
|
|
3813
|
-
}
|
|
3814
|
-
return blockLookup;
|
|
3815
|
-
}
|
|
3816
|
-
async writeRom(blockLookup) {
|
|
3817
|
-
const romWriter = new RomWriter(this.dbRoot.entryPoints, "GAIALABS", "01JG ");
|
|
3818
|
-
for (const file of this.chunkFiles) {
|
|
3819
|
-
await romWriter.writeFile(file, blockLookup);
|
|
3820
|
-
}
|
|
3771
|
+
async writeRom(blockLookup, entryPoints, chunkFiles, asmFiles) {
|
|
3772
|
+
const romWriter = new RomWriter(entryPoints, "GAIALABS", "01JG ");
|
|
3773
|
+
for (const file of chunkFiles) await romWriter.writeFile(file, blockLookup);
|
|
3821
3774
|
romWriter.writeHeader();
|
|
3822
|
-
romWriter.writeEntryPoints(
|
|
3775
|
+
romWriter.writeEntryPoints(asmFiles);
|
|
3823
3776
|
romWriter.writeChecksum();
|
|
3824
3777
|
return romWriter.outBuffer;
|
|
3825
3778
|
}
|