sc4
Version:
A command line utility for automating SimCity 4 modding tasks & modifying savegames
79 lines (78 loc) • 3.43 kB
TypeScript
import Header, { type HeaderJSON, type HeaderOptions } from './dbpf-header.js';
import Entry, { type EntryJSON, type EntryFromType } from './dbpf-entry.js';
import DIR from './dir.js';
import { TGIIndex } from 'sc4/utils';
import type { TGIArray, TGILiteral, TGIQuery, uint32 } from 'sc4/types';
import type { FindParameters } from 'src/utils/tgi-index.js';
import type { DBPFFile, DecodedFileTypeId, FileTypeId } from './types.js';
export type DBPFOptions = {
file?: string | File;
buffer?: Uint8Array;
parse?: boolean;
header?: HeaderOptions;
entries?: any;
};
export type DBPFSaveOptions = string | {
file?: string;
};
export type DBPFJSON = {
file: string;
header: HeaderJSON;
entries: EntryJSON;
};
type FileAddOptions = {
compressed?: boolean;
size?: number;
};
export default class DBPF {
file: string | null;
fileObject: File | null;
buffer: Uint8Array | null;
header: Header;
entries: TGIIndex<Entry>;
constructor(opts?: DBPFOptions | string | Uint8Array | File);
get length(): number;
get dir(): DIR | null;
get filename(): string;
find<T extends DecodedFileTypeId>(query: TGIQuery<T>): EntryFromType<T> | undefined;
find<T extends DecodedFileTypeId>(type: T, group: uint32, instance: uint32): EntryFromType<T> | undefined;
find<T extends FileTypeId>(query: TGIQuery<T>): Entry<Uint8Array> | undefined;
find<T extends FileTypeId>(type: T, group: uint32, instance: uint32): Entry<Uint8Array> | undefined;
find(...params: FindParameters<Entry>): Entry | undefined;
findAll<T extends DecodedFileTypeId>(query: TGIQuery<T>): EntryFromType<T>[];
findAll<T extends DecodedFileTypeId>(type: T, group: uint32, instance: uint32): EntryFromType<T>[];
findAll<T extends FileTypeId>(query: TGIQuery<T>): Entry<Uint8Array>[];
findAll<T extends FileTypeId>(type: T, group: uint32, instance: uint32): Entry<Uint8Array>[];
findAll(...params: FindParameters<Entry>): Entry[];
add<T extends DecodedFileTypeId>(tgi: TGILiteral<T> | TGIArray<T>, file: DBPFFile | DBPFFile[], opts?: FileAddOptions): EntryFromType<T>;
add<T extends FileTypeId>(tgi: TGILiteral<T> | TGIArray<T>, buffer: Uint8Array, opts?: FileAddOptions): Entry;
add(tgi: TGILiteral | TGIArray, buffer: Uint8Array, opts?: FileAddOptions): Entry;
remove(query: TGIQuery | TGILiteral): number;
free(): this;
readBytes(offset: number, length: number): Uint8Array<ArrayBufferLike>;
readBytesAsync(offset: number, length: number): Promise<Uint8Array<ArrayBufferLike>>;
parse(): this;
parseAsync(): Promise<this | undefined>;
createIndex(): this;
save(opts?: string | DBPFSaveOptions): void;
toBuffer(): Uint8Array<ArrayBufferLike>;
toJSON(): {
file: string | null;
header: {
version: string;
created: string | number | Date;
modified: string | number | Date;
indexMajor: number;
indexMinor: number;
indexCount: number;
indexOffset: number;
indexSize: number;
};
entries: EntryJSON[];
};
get exemplars(): EntryFromType<1697917002>[];
readExemplars(): import("./exemplar.js").Exemplar[];
memSearch(refs: uint32 | uint32[]): any;
[Symbol.iterator](): Generator<Entry<import("./types.js").DecodedFile | Uint8Array<ArrayBufferLike>>, void, unknown>;
}
export {};