mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-22 15:40:52 +01:00
Update converters
This commit is contained in:
parent
73fe879160
commit
6ab7fa37f1
@ -1,4 +1,3 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import ora from 'ora';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { Configuration, File, FileUtilities, IConverter } from '../common';
|
||||
@ -21,10 +20,9 @@ export class EffectConverter implements IConverter
|
||||
|
||||
const now = Date.now();
|
||||
const spinner = ora('Preparing Effects').start();
|
||||
const baseUrl = this._configuration.getValue('dynamic.download.effect.url');
|
||||
const downloadBase = this._configuration.getValue('dynamic.download.effect.url');
|
||||
const saveDirectory = await FileUtilities.getDirectory('./assets/bundled/effect');
|
||||
const effectMap = this._effectMapConverter.effectMap;
|
||||
const directory = await FileUtilities.getDirectory('./assets/bundled/effect');
|
||||
|
||||
const classNames: string[] = [];
|
||||
|
||||
if(effectMap.effects !== undefined)
|
||||
@ -51,14 +49,15 @@ export class EffectConverter implements IConverter
|
||||
|
||||
try
|
||||
{
|
||||
const path = new File(directory.path + '/' + className + '.nitro');
|
||||
const saveFile = new File(saveDirectory.path + '/' + className + '.nitro');
|
||||
|
||||
if(path.exists()) continue;
|
||||
if(saveFile.exists()) continue;
|
||||
|
||||
spinner.text = `Converting: ${ className } (${ (i + 1) } / ${ totalClassNames })`;
|
||||
spinner.render();
|
||||
|
||||
const habboAssetSWF = await SWFDownloader.download(baseUrl, className, -1);
|
||||
const downloadUrl = SWFDownloader.getDownloadUrl(downloadBase, className, -1);
|
||||
const habboAssetSWF = await SWFDownloader.downloadFromUrl(downloadUrl);
|
||||
|
||||
if(!habboAssetSWF)
|
||||
{
|
||||
@ -70,9 +69,9 @@ export class EffectConverter implements IConverter
|
||||
|
||||
const nitroBundle = await GenerateEffectBundle(habboAssetSWF, className, this.effectTypes.get(className));
|
||||
|
||||
await writeFile(path.path, await nitroBundle.toBufferAsync());
|
||||
await saveFile.writeData(await nitroBundle.toBufferAsync());
|
||||
|
||||
spinner.text = 'Converted: ' + className;
|
||||
spinner.text = `Converted: ${ className }`;
|
||||
spinner.render();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import ora from 'ora';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { Configuration, File, FileUtilities, IConverter } from '../common';
|
||||
@ -21,9 +20,9 @@ export class FigureConverter implements IConverter
|
||||
|
||||
const now = Date.now();
|
||||
const spinner = ora('Preparing Figure').start();
|
||||
const baseUrl = this._configuration.getValue('dynamic.download.figure.url');
|
||||
const downloadBase = this._configuration.getValue('dynamic.download.figure.url');
|
||||
const saveDirectory = await FileUtilities.getDirectory('./assets/bundled/figure');
|
||||
const figureMap = this._figureMapConverter.figureMap;
|
||||
const directory = await FileUtilities.getDirectory('./assets/bundled/figure');
|
||||
const classNames: string[] = [];
|
||||
|
||||
if(figureMap.libraries !== undefined)
|
||||
@ -52,14 +51,15 @@ export class FigureConverter implements IConverter
|
||||
|
||||
try
|
||||
{
|
||||
const path = new File(directory.path + '/' + className + '.nitro');
|
||||
const saveFile = new File(`${ saveDirectory.path }/${ className }.nitro`);
|
||||
|
||||
if(path.exists()) continue;
|
||||
if(saveFile.exists()) continue;
|
||||
|
||||
spinner.text = `Converting: ${ className } (${ (i + 1) } / ${ totalClassNames })`;
|
||||
spinner.render();
|
||||
|
||||
const habboAssetSWF = await SWFDownloader.download(baseUrl, className, -1);
|
||||
const downloadUrl = SWFDownloader.getDownloadUrl(downloadBase, className, -1);
|
||||
const habboAssetSWF = await SWFDownloader.downloadFromUrl(downloadUrl);
|
||||
|
||||
if(!habboAssetSWF)
|
||||
{
|
||||
@ -71,9 +71,9 @@ export class FigureConverter implements IConverter
|
||||
|
||||
const nitroBundle = await GenerateFigureBundle(habboAssetSWF, className, this.figureTypes.get(className));
|
||||
|
||||
await writeFile(path.path, await nitroBundle.toBufferAsync());
|
||||
await saveFile.writeData(await nitroBundle.toBufferAsync());
|
||||
|
||||
spinner.text = 'Converted: ' + className;
|
||||
spinner.text = `Converted: ${ className }`;
|
||||
spinner.render();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import ora from 'ora';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { Configuration, ConverterResult, File, FileUtilities, IConverter, NitroBundle } from '../common';
|
||||
import { Configuration, File, FileUtilities, IConverter } from '../common';
|
||||
import { GenerateFurnitureBundle, SWFDownloader } from '../swf';
|
||||
import { FurnitureDataConverter } from './FurnitureDataConverter';
|
||||
|
||||
@ -12,11 +12,8 @@ export class FurnitureConverter implements IConverter
|
||||
private readonly _configuration: Configuration)
|
||||
{}
|
||||
|
||||
public async convertAsync(bundle: boolean = false, extract: boolean = false): Promise<void>
|
||||
public async convertAsync(): Promise<void>
|
||||
{
|
||||
if(bundle) await this.convertInputToNitro();
|
||||
if(extract) await this.extractNitroToFolder();
|
||||
|
||||
if(!this._configuration.getBoolean('convert.furniture')) return;
|
||||
|
||||
const now = Date.now();
|
||||
@ -36,31 +33,36 @@ export class FurnitureConverter implements IConverter
|
||||
|
||||
try
|
||||
{
|
||||
const saveFile = new File(`${ saveDirectory.path }/${ className }.nitro`);
|
||||
|
||||
if(saveFile.exists()) continue;
|
||||
|
||||
spinner.text = `Converting: ${ className } (${ (i + 1) } / ${ totalClassNames })`;
|
||||
spinner.render();
|
||||
|
||||
const downloadUrl = SWFDownloader.getDownloadUrl(downloadBase, className, revision);
|
||||
const result = await this.convertSwfToNitro(className, downloadUrl, saveDirectory, false);
|
||||
const habboAssetSWF = await SWFDownloader.downloadFromUrl(downloadUrl);
|
||||
|
||||
switch(result)
|
||||
if(!habboAssetSWF)
|
||||
{
|
||||
case ConverterResult.OK:
|
||||
spinner.text = 'Converted: ' + className;
|
||||
spinner.render();
|
||||
break;
|
||||
case ConverterResult.INVALID_SWF:
|
||||
console.log();
|
||||
console.error(`Invalid SWF: ${ downloadUrl }`);
|
||||
break;
|
||||
console.log();
|
||||
console.error(`Invalid SWF: ${ downloadUrl }`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const nitroBundle = await GenerateFurnitureBundle(habboAssetSWF);
|
||||
|
||||
await saveFile.writeData(await nitroBundle.toBufferAsync());
|
||||
|
||||
spinner.text = `Converted: ${ className }`;
|
||||
spinner.render();
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(`Error Converting: ${ className } - ${ error.message }`);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,153 +70,6 @@ export class FurnitureConverter implements IConverter
|
||||
spinner.succeed(`Furniture: Finished in ${ Date.now() - now }ms`);
|
||||
}
|
||||
|
||||
public async convertInputToNitro(): Promise<void>
|
||||
{
|
||||
const now = Date.now();
|
||||
const spinner = ora('Preparing Furniture Inputs').start();
|
||||
const saveDirectory = await FileUtilities.getDirectory('./assets/bundled/furniture');
|
||||
const inputDirectory = await FileUtilities.getDirectory('./assets/bundle/furniture');
|
||||
const files = await inputDirectory.getFileList();
|
||||
|
||||
for await (const name of files)
|
||||
{
|
||||
try
|
||||
{
|
||||
const [ className, extension, ...rest ] = name.split('.');
|
||||
const file = new File(`${ inputDirectory.path}/${ name }`);
|
||||
|
||||
if(await file.isDirectory())
|
||||
{
|
||||
spinner.text = `Bundling: ${ className }`;
|
||||
spinner.render();
|
||||
|
||||
const nitroBundle = new NitroBundle();
|
||||
const childFiles = await file.getFileList();
|
||||
|
||||
if(childFiles && childFiles.length)
|
||||
{
|
||||
for await (const childName of childFiles)
|
||||
{
|
||||
const childFile = new File(`${ file.path }/${ childName }`);
|
||||
|
||||
nitroBundle.addFile(childName, await childFile.getContentsAsBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
if(nitroBundle.totalFiles)
|
||||
{
|
||||
const path = new File(`${ saveDirectory.path }/${ className }.nitro`);
|
||||
|
||||
await path.writeData(await nitroBundle.toBufferAsync());
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log();
|
||||
console.error(`Error Bundling: ${ name } - The bundle was empty`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
spinner.text = 'Bundled: ' + name;
|
||||
spinner.render();
|
||||
}
|
||||
|
||||
else if(extension === 'swf')
|
||||
{
|
||||
spinner.text = `Converting: ${ className }`;
|
||||
spinner.render();
|
||||
|
||||
const downloadUrl = `${ inputDirectory.path }/${ name }`;
|
||||
const result = await this.convertSwfToNitro(className, file.path, saveDirectory, true);
|
||||
|
||||
switch(result)
|
||||
{
|
||||
case ConverterResult.OK:
|
||||
spinner.text = 'Converted: ' + className;
|
||||
spinner.render();
|
||||
break;
|
||||
case ConverterResult.INVALID_SWF:
|
||||
console.log();
|
||||
console.error(`Invalid SWF: ${ downloadUrl }`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(`Error Converting: ${ name } - ${ error.message }`);
|
||||
}
|
||||
}
|
||||
|
||||
spinner.succeed(`Furniture Inputs: Finished in ${ Date.now() - now }ms`);
|
||||
}
|
||||
|
||||
public async extractNitroToFolder(): Promise<void>
|
||||
{
|
||||
const now = Date.now();
|
||||
const spinner = ora('Preparing Furniture Extraction').start();
|
||||
const saveBaseDirectory = await FileUtilities.getDirectory('./assets/extracted/furniture');
|
||||
const inputDirectory = await FileUtilities.getDirectory('./assets/extract/furniture');
|
||||
const files = await inputDirectory.getFileList();
|
||||
|
||||
for await (const name of files)
|
||||
{
|
||||
try
|
||||
{
|
||||
const [ className, extension, ...rest ] = name.split('.');
|
||||
const saveDirectory = await FileUtilities.getDirectory(`${ saveBaseDirectory.path }/${ className }`);
|
||||
const file = new File(`${ inputDirectory.path }/${ name }`);
|
||||
|
||||
spinner.text = `Extracting: ${ className }`;
|
||||
spinner.render();
|
||||
|
||||
if(extension === 'nitro')
|
||||
{
|
||||
const nitroBundle = NitroBundle.from((await file.getContentsAsBuffer()).buffer);
|
||||
|
||||
for await (const [ bundleName, bundleBuffer ] of nitroBundle.files.entries())
|
||||
{
|
||||
const saveFile = new File(`${ saveDirectory.path }/${ bundleName }`);
|
||||
|
||||
await saveFile.writeData(bundleBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(`Error Extracting: ${ name } - ${ error.message }`);
|
||||
}
|
||||
}
|
||||
|
||||
spinner.succeed(`Furniture Extraction: Finished in ${ Date.now() - now }ms`);
|
||||
}
|
||||
|
||||
private async convertSwfToNitro(className: string, url: string, parentFile: File, overwrite: boolean = false): Promise<number>
|
||||
{
|
||||
if(!className || !url || !parentFile) return ConverterResult.BAD_ARGS;
|
||||
|
||||
const file = new File(`${ parentFile.path }/${ className }.nitro`);
|
||||
|
||||
if(!overwrite)
|
||||
{
|
||||
if(file.exists()) return ConverterResult.FILE_EXISTS;
|
||||
}
|
||||
|
||||
const habboAssetSWF = await SWFDownloader.downloadFromUrl(url);
|
||||
|
||||
if(!habboAssetSWF) return ConverterResult.INVALID_SWF;
|
||||
|
||||
const nitroBundle = await GenerateFurnitureBundle(habboAssetSWF);
|
||||
|
||||
await file.writeData(await nitroBundle.toBufferAsync());
|
||||
|
||||
return ConverterResult.OK;
|
||||
}
|
||||
|
||||
public get floorOnly(): boolean
|
||||
{
|
||||
return (this._configuration.getBoolean('convert.furniture.floor.only') || false);
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import ora from 'ora';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { Configuration, File, FileUtilities, IConverter } from '../common';
|
||||
@ -17,9 +16,9 @@ export class PetConverter implements IConverter
|
||||
|
||||
const now = Date.now();
|
||||
const spinner = ora('Preparing Pets').start();
|
||||
const baseUrl = this._configuration.getValue('dynamic.download.pet.url');
|
||||
const downloadBase = this._configuration.getValue('dynamic.download.pet.url');
|
||||
const saveDirectory = await FileUtilities.getDirectory('./assets/bundled/pet');
|
||||
const classNames = this.getPetTypes();
|
||||
const directory = await FileUtilities.getDirectory('./assets/bundled/pet');
|
||||
|
||||
if(classNames)
|
||||
{
|
||||
@ -31,14 +30,15 @@ export class PetConverter implements IConverter
|
||||
|
||||
try
|
||||
{
|
||||
const path = new File(directory.path + '/' + className + '.nitro');
|
||||
const saveFile = new File(`${ saveDirectory.path }/${ className }.nitro`);
|
||||
|
||||
if(path.exists()) continue;
|
||||
if(saveFile.exists()) continue;
|
||||
|
||||
spinner.text = `Converting: ${ className } (${ (i + 1) } / ${ totalClassNames })`;
|
||||
spinner.render();
|
||||
|
||||
const habboAssetSWF = await SWFDownloader.download(baseUrl, className, -1);
|
||||
const downloadUrl = SWFDownloader.getDownloadUrl(downloadBase, className, -1);
|
||||
const habboAssetSWF = await SWFDownloader.downloadFromUrl(downloadUrl);
|
||||
|
||||
if(!habboAssetSWF)
|
||||
{
|
||||
@ -50,9 +50,9 @@ export class PetConverter implements IConverter
|
||||
|
||||
const nitroBundle = await GeneratePetBundle(habboAssetSWF);
|
||||
|
||||
await writeFile(path.path, await nitroBundle.toBufferAsync());
|
||||
await saveFile.writeData(await nitroBundle.toBufferAsync());
|
||||
|
||||
spinner.text = 'Converted: ' + className;
|
||||
spinner.text = `Converted: ${ className }`;
|
||||
spinner.render();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user