mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-26 17:30:52 +01:00
Update error logging
This commit is contained in:
parent
224d7ac736
commit
adbcec6e80
@ -42,6 +42,4 @@ import { Mapper } from './mapping/mappers/asset/Mapper';
|
|||||||
// const effectConverter = container.resolve(EffectConverter);
|
// const effectConverter = container.resolve(EffectConverter);
|
||||||
// await effectConverter.convertAsync();
|
// await effectConverter.convertAsync();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
console.log('finished!');
|
|
||||||
})();
|
})();
|
||||||
|
@ -1,10 +1,29 @@
|
|||||||
import { wrap } from 'bytebuffer';
|
import { wrap } from 'bytebuffer';
|
||||||
|
import { writeFile } from 'fs/promises';
|
||||||
import { parseStringPromise } from 'xml2js';
|
import { parseStringPromise } from 'xml2js';
|
||||||
|
import { IAssetData } from '../../mapping/json';
|
||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import { DefineBinaryDataTag } from '../../swf/tags/DefineBinaryDataTag';
|
import { DefineBinaryDataTag } from '../../swf/tags/DefineBinaryDataTag';
|
||||||
|
import { NitroBundle } from '../../utils/NitroBundle';
|
||||||
|
import { SpriteBundle } from '../bundle/SpriteBundle';
|
||||||
|
|
||||||
export class SWFConverter
|
export class SWFConverter
|
||||||
{
|
{
|
||||||
|
protected async fromHabboAsset(habboAssetSWF: HabboAssetSWF, outputFolder: string, type: string, assetData: IAssetData, spriteBundle: SpriteBundle): Promise<void>
|
||||||
|
{
|
||||||
|
if(spriteBundle && (spriteBundle.spritesheet !== undefined)) assetData.spritesheet = spriteBundle.spritesheet;
|
||||||
|
|
||||||
|
const name = habboAssetSWF.getDocumentClass();
|
||||||
|
const path = outputFolder + '/' + name + '.nitro';
|
||||||
|
const nitroBundle = new NitroBundle();
|
||||||
|
|
||||||
|
nitroBundle.addFile((name + '.json'), Buffer.from(JSON.stringify(assetData)));
|
||||||
|
|
||||||
|
if(spriteBundle && (spriteBundle.imageData !== undefined)) nitroBundle.addFile(spriteBundle.imageData.name, spriteBundle.imageData.buffer);
|
||||||
|
|
||||||
|
await writeFile(path, await nitroBundle.toBufferAsync());
|
||||||
|
}
|
||||||
|
|
||||||
private static getBinaryData(habboAssetSWF: HabboAssetSWF, type: string, documentNameTwice: boolean): DefineBinaryDataTag
|
private static getBinaryData(habboAssetSWF: HabboAssetSWF, type: string, documentNameTwice: boolean): DefineBinaryDataTag
|
||||||
{
|
{
|
||||||
let binaryName = habboAssetSWF.getFullClassName(type, documentNameTwice);
|
let binaryName = habboAssetSWF.getFullClassName(type, documentNameTwice);
|
||||||
@ -19,51 +38,6 @@ export class SWFConverter
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static getPalette(habboAssetSWF: HabboAssetSWF, paletteName: string): [ number, number, number ][]
|
|
||||||
{
|
|
||||||
const binaryData = SWFConverter.getBinaryData(habboAssetSWF, paletteName, false);
|
|
||||||
|
|
||||||
if(!binaryData || !binaryData.binaryDataBuffer) return null;
|
|
||||||
|
|
||||||
const byteBuffer = wrap(binaryData.binaryDataBuffer);
|
|
||||||
|
|
||||||
const paletteColors: [ number, number, number ][] = [];
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
let R = 0;
|
|
||||||
let G = 0;
|
|
||||||
let B = 0;
|
|
||||||
let counter = 1;
|
|
||||||
|
|
||||||
while((binaryData.binaryDataBuffer.length - byteBuffer.offset) > 0)
|
|
||||||
{
|
|
||||||
if(counter == 1) R = byteBuffer.readUint8();
|
|
||||||
|
|
||||||
else if(counter == 2) G = byteBuffer.readUint8();
|
|
||||||
|
|
||||||
else if(counter == 3)
|
|
||||||
{
|
|
||||||
B = byteBuffer.readUint8();
|
|
||||||
paletteColors.push([ R, G, B ]);
|
|
||||||
|
|
||||||
counter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return paletteColors;
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (err)
|
|
||||||
{
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static async getAssetsXML(habboAssetSWF: HabboAssetSWF): Promise<any>
|
protected static async getAssetsXML(habboAssetSWF: HabboAssetSWF): Promise<any>
|
||||||
{
|
{
|
||||||
const binaryData = SWFConverter.getBinaryData(habboAssetSWF, 'assets', true);
|
const binaryData = SWFConverter.getBinaryData(habboAssetSWF, 'assets', true);
|
||||||
@ -99,4 +73,40 @@ export class SWFConverter
|
|||||||
|
|
||||||
return await parseStringPromise(binaryData.binaryData);
|
return await parseStringPromise(binaryData.binaryData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static getPalette(habboAssetSWF: HabboAssetSWF, paletteName: string): [ number, number, number ][]
|
||||||
|
{
|
||||||
|
const binaryData = SWFConverter.getBinaryData(habboAssetSWF, paletteName, false);
|
||||||
|
|
||||||
|
if(!binaryData || !binaryData.binaryDataBuffer) return null;
|
||||||
|
|
||||||
|
const byteBuffer = wrap(binaryData.binaryDataBuffer);
|
||||||
|
|
||||||
|
const paletteColors: [ number, number, number ][] = [];
|
||||||
|
|
||||||
|
let R = 0;
|
||||||
|
let G = 0;
|
||||||
|
let B = 0;
|
||||||
|
let counter = 1;
|
||||||
|
|
||||||
|
while((binaryData.binaryDataBuffer.length - byteBuffer.offset) > 0)
|
||||||
|
{
|
||||||
|
if(counter == 1) R = byteBuffer.readUint8();
|
||||||
|
|
||||||
|
else if(counter == 2) G = byteBuffer.readUint8();
|
||||||
|
|
||||||
|
else if(counter == 3)
|
||||||
|
{
|
||||||
|
B = byteBuffer.readUint8();
|
||||||
|
|
||||||
|
paletteColors.push([ R, G, B ]);
|
||||||
|
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return paletteColors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { writeFile } from 'fs/promises';
|
|
||||||
import * as ora from 'ora';
|
import * as ora from 'ora';
|
||||||
import { singleton } from 'tsyringe';
|
import { singleton } from 'tsyringe';
|
||||||
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
||||||
import { SpriteBundle } from '../../common/bundle/SpriteBundle';
|
|
||||||
import { Configuration } from '../../common/config/Configuration';
|
import { Configuration } from '../../common/config/Configuration';
|
||||||
import { SWFConverter } from '../../common/converters/SWFConverter';
|
import { SWFConverter } from '../../common/converters/SWFConverter';
|
||||||
import { IAssetData } from '../../mapping/json';
|
import { IAssetData } from '../../mapping/json';
|
||||||
@ -10,7 +8,6 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
|||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import File from '../../utils/File';
|
import File from '../../utils/File';
|
||||||
import Logger from '../../utils/Logger';
|
import Logger from '../../utils/Logger';
|
||||||
import { NitroBundle } from '../../utils/NitroBundle';
|
|
||||||
import { FurnitureDownloader } from './FurnitureDownloader';
|
import { FurnitureDownloader } from './FurnitureDownloader';
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
@ -33,63 +30,29 @@ export class FurnitureConverter extends SWFConverter
|
|||||||
|
|
||||||
const outputFolder = new File(this._configuration.getValue('output.folder.furniture'));
|
const outputFolder = new File(this._configuration.getValue('output.folder.furniture'));
|
||||||
|
|
||||||
if(!outputFolder.isDirectory())
|
if(!outputFolder.isDirectory()) outputFolder.mkdirs();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
spinner.text = `Creating Folder: ${ outputFolder.path }`;
|
|
||||||
|
|
||||||
spinner.render();
|
|
||||||
|
|
||||||
outputFolder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
await this._furniDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
await this._furniDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||||
{
|
{
|
||||||
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
||||||
|
|
||||||
spinner.render();
|
spinner.render();
|
||||||
|
|
||||||
try
|
const assetData = await this.mapXML2JSON(habboAssetSwf, 'furniture');
|
||||||
{
|
|
||||||
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
||||||
|
|
||||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'furniture', spriteBundle);
|
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'furniture', assetData, spriteBundle);
|
||||||
|
});
|
||||||
|
|
||||||
|
spinner.succeed(`Furniture finished in ${ Date.now() - now }ms`);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log();
|
spinner.fail('Furniture failed: ' + error.message);
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
spinner.succeed(`Furniture Finished in ${ Date.now() - now }ms`);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async fromHabboAsset(habboAssetSWF: HabboAssetSWF, outputFolder: string, type: string, spriteBundle: SpriteBundle): Promise<void>
|
|
||||||
{
|
|
||||||
const assetData = await this.mapXML2JSON(habboAssetSWF, 'furniture');
|
|
||||||
|
|
||||||
if(!assetData) return;
|
|
||||||
|
|
||||||
const name = habboAssetSWF.getDocumentClass();
|
|
||||||
const path = outputFolder + '/' + name + '.nitro';
|
|
||||||
const nitroBundle = new NitroBundle();
|
|
||||||
|
|
||||||
nitroBundle.addFile((name + '.json'), Buffer.from(JSON.stringify(assetData)));
|
|
||||||
|
|
||||||
if(spriteBundle && (spriteBundle.spritesheet !== undefined))
|
|
||||||
{
|
|
||||||
if(spriteBundle.spritesheet && spriteBundle.imageData)
|
|
||||||
{
|
|
||||||
assetData.spritesheet = spriteBundle.spritesheet;
|
|
||||||
|
|
||||||
nitroBundle.addFile(spriteBundle.imageData.name, spriteBundle.imageData.buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const buffer = await nitroBundle.toBufferAsync();
|
|
||||||
|
|
||||||
await writeFile(path, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async mapXML2JSON(habboAssetSWF: HabboAssetSWF, assetType: string): Promise<IAssetData>
|
private async mapXML2JSON(habboAssetSWF: HabboAssetSWF, assetType: string): Promise<IAssetData>
|
||||||
@ -100,8 +63,6 @@ export class FurnitureConverter extends SWFConverter
|
|||||||
|
|
||||||
assetData.type = assetType;
|
assetData.type = assetType;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const indexXML = await FurnitureConverter.getIndexXML(habboAssetSWF);
|
const indexXML = await FurnitureConverter.getIndexXML(habboAssetSWF);
|
||||||
|
|
||||||
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
||||||
@ -120,11 +81,4 @@ export class FurnitureConverter extends SWFConverter
|
|||||||
|
|
||||||
return assetData;
|
return assetData;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,29 +2,22 @@ import { singleton } from 'tsyringe';
|
|||||||
import { Configuration } from '../../common/config/Configuration';
|
import { Configuration } from '../../common/config/Configuration';
|
||||||
import { IFurnitureData } from '../../mapping/json';
|
import { IFurnitureData } from '../../mapping/json';
|
||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import File from '../../utils/File';
|
|
||||||
import { FileUtilities } from '../../utils/FileUtilities';
|
import { FileUtilities } from '../../utils/FileUtilities';
|
||||||
import Logger from '../../utils/Logger';
|
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
export class FurnitureDownloader
|
export class FurnitureDownloader
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(private readonly _configuration: Configuration)
|
||||||
private readonly _configuration: Configuration,
|
|
||||||
private readonly _logger: Logger)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public async download(callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
public async download(callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
const furniData = await this.parseFurniData();
|
const furniData = await this.parseFurniData();
|
||||||
|
|
||||||
|
if(!furniData) throw new Error('invalid_furnidata');
|
||||||
|
|
||||||
const classNames: string[] = [];
|
const classNames: string[] = [];
|
||||||
|
|
||||||
const outputFolder = new File(this._configuration.getValue('output.folder.furniture'));
|
|
||||||
|
|
||||||
if(!outputFolder.isDirectory()) outputFolder.mkdirs();
|
|
||||||
|
|
||||||
if(furniData.roomitemtypes !== undefined)
|
if(furniData.roomitemtypes !== undefined)
|
||||||
{
|
{
|
||||||
if(furniData.roomitemtypes.furnitype !== undefined)
|
if(furniData.roomitemtypes.furnitype !== undefined)
|
||||||
@ -46,7 +39,7 @@ export class FurnitureDownloader
|
|||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log();
|
console.log();
|
||||||
console.error(error);
|
console.error(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,28 +66,19 @@ export class FurnitureDownloader
|
|||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log();
|
console.log();
|
||||||
console.error(error);
|
console.error(`Error parsing ${ className }: ` + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async parseFurniData(): Promise<IFurnitureData>
|
public async parseFurniData(): Promise<IFurnitureData>
|
||||||
{
|
{
|
||||||
const url = this._configuration.getValue('furnidata.url');
|
const url = this._configuration.getValue('furnidata.url');
|
||||||
|
|
||||||
if(!url || !url.length) return null;
|
if(!url || !url.length) return null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const content = await FileUtilities.readFileAsString(url);
|
const content = await FileUtilities.readFileAsString(url);
|
||||||
|
|
||||||
if(!content || !content.length) return null;
|
if(!content || !content.length) return null;
|
||||||
@ -102,13 +86,6 @@ export class FurnitureDownloader
|
|||||||
return (JSON.parse(content) as IFurnitureData);
|
return (JSON.parse(content) as IFurnitureData);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async extractFurniture(revision: number, className: string, callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
public async extractFurniture(revision: number, className: string, callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
||||||
{
|
{
|
||||||
let url = this._configuration.getValue('dynamic.download.url.furniture');
|
let url = this._configuration.getValue('dynamic.download.url.furniture');
|
||||||
@ -118,8 +95,6 @@ export class FurnitureDownloader
|
|||||||
url = url.replace('%revision%', revision.toString());
|
url = url.replace('%revision%', revision.toString());
|
||||||
url = url.replace('%className%', className);
|
url = url.replace('%className%', className);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||||
|
|
||||||
if(!buffer) return;
|
if(!buffer) return;
|
||||||
@ -130,11 +105,4 @@ export class FurnitureDownloader
|
|||||||
|
|
||||||
await callback(newHabboAssetSWF, className);
|
await callback(newHabboAssetSWF, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { writeFile } from 'fs/promises';
|
|
||||||
import * as ora from 'ora';
|
import * as ora from 'ora';
|
||||||
import { singleton } from 'tsyringe';
|
import { singleton } from 'tsyringe';
|
||||||
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
||||||
import { SpriteBundle } from '../../common/bundle/SpriteBundle';
|
|
||||||
import { Configuration } from '../../common/config/Configuration';
|
import { Configuration } from '../../common/config/Configuration';
|
||||||
import { SWFConverter } from '../../common/converters/SWFConverter';
|
import { SWFConverter } from '../../common/converters/SWFConverter';
|
||||||
import { IAssetData } from '../../mapping/json';
|
import { IAssetData } from '../../mapping/json';
|
||||||
@ -10,7 +8,6 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
|||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import File from '../../utils/File';
|
import File from '../../utils/File';
|
||||||
import Logger from '../../utils/Logger';
|
import Logger from '../../utils/Logger';
|
||||||
import { NitroBundle } from '../../utils/NitroBundle';
|
|
||||||
import { PetDownloader } from './PetDownloader';
|
import { PetDownloader } from './PetDownloader';
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
@ -18,7 +15,7 @@ export class PetConverter extends SWFConverter
|
|||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _petDownloader: PetDownloader,
|
private readonly _petDownloader: PetDownloader,
|
||||||
private readonly _config: Configuration,
|
private readonly _configuration: Configuration,
|
||||||
private readonly _bundleProvider: BundleProvider,
|
private readonly _bundleProvider: BundleProvider,
|
||||||
private readonly _logger: Logger)
|
private readonly _logger: Logger)
|
||||||
{
|
{
|
||||||
@ -31,69 +28,30 @@ export class PetConverter extends SWFConverter
|
|||||||
|
|
||||||
const spinner = ora('Preparing Pets').start();
|
const spinner = ora('Preparing Pets').start();
|
||||||
|
|
||||||
const outputFolder = new File(this._config.getValue('output.folder.pet'));
|
const outputFolder = new File(this._configuration.getValue('output.folder.pet'));
|
||||||
|
|
||||||
if(!outputFolder.isDirectory())
|
if(!outputFolder.isDirectory()) outputFolder.mkdirs();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
spinner.text = `Creating Folder: ${ outputFolder.path }`;
|
|
||||||
|
|
||||||
spinner.render();
|
|
||||||
|
|
||||||
outputFolder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||||
{
|
{
|
||||||
spinner.text = 'Parsing Pet: ' + habboAssetSwf.getDocumentClass();
|
spinner.text = 'Parsing Pet: ' + habboAssetSwf.getDocumentClass();
|
||||||
|
|
||||||
spinner.render();
|
spinner.render();
|
||||||
|
|
||||||
try
|
const assetData = await this.mapXML2JSON(habboAssetSwf, 'pet');
|
||||||
{
|
|
||||||
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
||||||
|
|
||||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'pet', spriteBundle);
|
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'pet', assetData, spriteBundle);
|
||||||
|
});
|
||||||
|
|
||||||
|
spinner.succeed(`Pets finished in ${ Date.now() - now }ms`);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log();
|
spinner.fail('Pet failed: ' + error.message);
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
spinner.succeed(`Pets Finished in ${ Date.now() - now }ms`);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async fromHabboAsset(habboAssetSWF: HabboAssetSWF, outputFolder: string, type: string, spriteBundle: SpriteBundle): Promise<void>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const assetData = await this.mapXML2JSON(habboAssetSWF, 'pet');
|
|
||||||
|
|
||||||
if(!assetData) return;
|
|
||||||
|
|
||||||
if(spriteBundle && (spriteBundle.spritesheet !== undefined)) assetData.spritesheet = spriteBundle.spritesheet;
|
|
||||||
|
|
||||||
const name = habboAssetSWF.getDocumentClass();
|
|
||||||
const path = outputFolder + '/' + name + '.nitro';
|
|
||||||
const nitroBundle = new NitroBundle();
|
|
||||||
|
|
||||||
nitroBundle.addFile((name + '.json'), Buffer.from(JSON.stringify(assetData)));
|
|
||||||
|
|
||||||
if(spriteBundle.imageData !== undefined)
|
|
||||||
{
|
|
||||||
nitroBundle.addFile(spriteBundle.imageData.name, spriteBundle.imageData.buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
const buffer = await nitroBundle.toBufferAsync();
|
|
||||||
|
|
||||||
await writeFile(path, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (err)
|
|
||||||
{
|
|
||||||
this._logger.logErrorAsync(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +63,6 @@ export class PetConverter extends SWFConverter
|
|||||||
|
|
||||||
assetData.type = assetType;
|
assetData.type = assetType;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const indexXML = await PetConverter.getIndexXML(habboAssetSWF);
|
const indexXML = await PetConverter.getIndexXML(habboAssetSWF);
|
||||||
|
|
||||||
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
||||||
@ -151,11 +107,4 @@ export class PetConverter extends SWFConverter
|
|||||||
|
|
||||||
return assetData;
|
return assetData;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,12 @@ export class PetDownloader
|
|||||||
private readonly _logger: Logger)
|
private readonly _logger: Logger)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public async download(callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
public async download(callback: (habboAssetSwf: HabboAssetSWF) => Promise<void>): Promise<void>
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
const petTypes = await this.parsePetTypes();
|
const petTypes = await this.parsePetTypes();
|
||||||
|
|
||||||
|
if(!petTypes) throw new Error('invalid_pets');
|
||||||
|
|
||||||
const classNames: string[] = [];
|
const classNames: string[] = [];
|
||||||
|
|
||||||
for(const petType of petTypes)
|
for(const petType of petTypes)
|
||||||
@ -38,16 +39,7 @@ export class PetDownloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async parsePetTypes(): Promise<string[]>
|
public async parsePetTypes(): Promise<string[]>
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
await this._config.loadExternalVariables();
|
await this._config.loadExternalVariables();
|
||||||
|
|
||||||
@ -65,14 +57,7 @@ export class PetDownloader
|
|||||||
return petTypes;
|
return petTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
public async extractPet(className: string, callback: (habboAssetSwf: HabboAssetSWF) => Promise<void>): Promise<void>
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async extractPet(className: string, callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
|
||||||
{
|
{
|
||||||
let url = this._config.getValue('dynamic.download.url.pet');
|
let url = this._config.getValue('dynamic.download.url.pet');
|
||||||
|
|
||||||
@ -80,19 +65,14 @@ export class PetDownloader
|
|||||||
|
|
||||||
url = url.replace('%className%', className);
|
url = url.replace('%className%', className);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||||
|
|
||||||
|
if(!buffer) return;
|
||||||
|
|
||||||
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
||||||
|
|
||||||
await newHabboAssetSWF.setupAsync();
|
await newHabboAssetSWF.setupAsync();
|
||||||
await callback(newHabboAssetSWF, className);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
await callback(newHabboAssetSWF);
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@ export class FileUtilities
|
|||||||
|
|
||||||
let content: Buffer = null;
|
let content: Buffer = null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if(url.startsWith('http'))
|
if(url.startsWith('http'))
|
||||||
{
|
{
|
||||||
const data = await fetch.default(url);
|
const data = await fetch.default(url);
|
||||||
@ -29,21 +27,12 @@ export class FileUtilities
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async readFileAsString(url: string): Promise<string>
|
public static async readFileAsString(url: string): Promise<string>
|
||||||
{
|
{
|
||||||
if(!url) return null;
|
if(!url) return null;
|
||||||
|
|
||||||
let content = null;
|
let content = null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if(url.startsWith('http'))
|
if(url.startsWith('http'))
|
||||||
{
|
{
|
||||||
const data = await fetch.default(url);
|
const data = await fetch.default(url);
|
||||||
@ -59,11 +48,4 @@ export class FileUtilities
|
|||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user