mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-29 18:50:51 +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);
|
||||
// await effectConverter.convertAsync();
|
||||
// }
|
||||
|
||||
console.log('finished!');
|
||||
})();
|
||||
|
@ -1,10 +1,29 @@
|
||||
import { wrap } from 'bytebuffer';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { parseStringPromise } from 'xml2js';
|
||||
import { IAssetData } from '../../mapping/json';
|
||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||
import { DefineBinaryDataTag } from '../../swf/tags/DefineBinaryDataTag';
|
||||
import { NitroBundle } from '../../utils/NitroBundle';
|
||||
import { SpriteBundle } from '../bundle/SpriteBundle';
|
||||
|
||||
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
|
||||
{
|
||||
let binaryName = habboAssetSWF.getFullClassName(type, documentNameTwice);
|
||||
@ -19,51 +38,6 @@ export class SWFConverter
|
||||
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>
|
||||
{
|
||||
const binaryData = SWFConverter.getBinaryData(habboAssetSWF, 'assets', true);
|
||||
@ -99,4 +73,40 @@ export class SWFConverter
|
||||
|
||||
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 { singleton } from 'tsyringe';
|
||||
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
||||
import { SpriteBundle } from '../../common/bundle/SpriteBundle';
|
||||
import { Configuration } from '../../common/config/Configuration';
|
||||
import { SWFConverter } from '../../common/converters/SWFConverter';
|
||||
import { IAssetData } from '../../mapping/json';
|
||||
@ -10,7 +8,6 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||
import File from '../../utils/File';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { NitroBundle } from '../../utils/NitroBundle';
|
||||
import { FurnitureDownloader } from './FurnitureDownloader';
|
||||
|
||||
@singleton()
|
||||
@ -33,63 +30,29 @@ export class FurnitureConverter extends SWFConverter
|
||||
|
||||
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) =>
|
||||
{
|
||||
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
||||
|
||||
spinner.render();
|
||||
|
||||
try
|
||||
await this._furniDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||
{
|
||||
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
||||
|
||||
spinner.render();
|
||||
|
||||
const assetData = await this.mapXML2JSON(habboAssetSwf, 'furniture');
|
||||
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
||||
|
||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'furniture', spriteBundle);
|
||||
}
|
||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'furniture', assetData, spriteBundle);
|
||||
});
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
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);
|
||||
}
|
||||
spinner.succeed(`Furniture finished in ${ Date.now() - now }ms`);
|
||||
}
|
||||
|
||||
const buffer = await nitroBundle.toBufferAsync();
|
||||
|
||||
await writeFile(path, buffer);
|
||||
catch (error)
|
||||
{
|
||||
spinner.fail('Furniture failed: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
private async mapXML2JSON(habboAssetSWF: HabboAssetSWF, assetType: string): Promise<IAssetData>
|
||||
@ -100,31 +63,22 @@ export class FurnitureConverter extends SWFConverter
|
||||
|
||||
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);
|
||||
|
||||
const assetXML = await FurnitureConverter.getAssetsXML(habboAssetSWF);
|
||||
const assetXML = await FurnitureConverter.getAssetsXML(habboAssetSWF);
|
||||
|
||||
if(assetXML) AssetMapper.mapXML(assetXML, assetData);
|
||||
if(assetXML) AssetMapper.mapXML(assetXML, assetData);
|
||||
|
||||
const logicXML = await FurnitureConverter.getLogicXML(habboAssetSWF);
|
||||
const logicXML = await FurnitureConverter.getLogicXML(habboAssetSWF);
|
||||
|
||||
if(logicXML) LogicMapper.mapXML(logicXML, assetData);
|
||||
if(logicXML) LogicMapper.mapXML(logicXML, assetData);
|
||||
|
||||
const visualizationXML = await FurnitureConverter.getVisualizationXML(habboAssetSWF);
|
||||
const visualizationXML = await FurnitureConverter.getVisualizationXML(habboAssetSWF);
|
||||
|
||||
if(visualizationXML) VisualizationMapper.mapXML(visualizationXML, assetData);
|
||||
if(visualizationXML) VisualizationMapper.mapXML(visualizationXML, assetData);
|
||||
|
||||
return assetData;
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
return assetData;
|
||||
}
|
||||
}
|
||||
|
@ -2,88 +2,74 @@ import { singleton } from 'tsyringe';
|
||||
import { Configuration } from '../../common/config/Configuration';
|
||||
import { IFurnitureData } from '../../mapping/json';
|
||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||
import File from '../../utils/File';
|
||||
import { FileUtilities } from '../../utils/FileUtilities';
|
||||
import Logger from '../../utils/Logger';
|
||||
|
||||
@singleton()
|
||||
export class FurnitureDownloader
|
||||
{
|
||||
constructor(
|
||||
private readonly _configuration: Configuration,
|
||||
private readonly _logger: Logger)
|
||||
constructor(private readonly _configuration: Configuration)
|
||||
{}
|
||||
|
||||
public async download(callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
||||
{
|
||||
try
|
||||
const furniData = await this.parseFurniData();
|
||||
|
||||
if(!furniData) throw new Error('invalid_furnidata');
|
||||
|
||||
const classNames: string[] = [];
|
||||
|
||||
if(furniData.roomitemtypes !== undefined)
|
||||
{
|
||||
const furniData = await this.parseFurniData();
|
||||
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.furnitype !== undefined)
|
||||
{
|
||||
if(furniData.roomitemtypes.furnitype !== undefined)
|
||||
for(const furniType of furniData.roomitemtypes.furnitype)
|
||||
{
|
||||
for(const furniType of furniData.roomitemtypes.furnitype)
|
||||
const className = furniType.classname.split('*')[0];
|
||||
const revision = furniType.revision;
|
||||
|
||||
if(classNames.indexOf(className) >= 0) continue;
|
||||
|
||||
classNames.push(className);
|
||||
|
||||
try
|
||||
{
|
||||
const className = furniType.classname.split('*')[0];
|
||||
const revision = furniType.revision;
|
||||
|
||||
if(classNames.indexOf(className) >= 0) continue;
|
||||
|
||||
classNames.push(className);
|
||||
|
||||
try
|
||||
{
|
||||
await this.extractFurniture(revision, className, callback);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
await this.extractFurniture(revision, className, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(furniData.wallitemtypes !== undefined)
|
||||
{
|
||||
if(furniData.wallitemtypes.furnitype !== undefined)
|
||||
{
|
||||
for(const furniType of furniData.wallitemtypes.furnitype)
|
||||
catch (error)
|
||||
{
|
||||
const className = furniType.classname.split('*')[0];
|
||||
const revision = furniType.revision;
|
||||
|
||||
if(classNames.indexOf(className) >= 0) continue;
|
||||
|
||||
classNames.push(className);
|
||||
|
||||
try
|
||||
{
|
||||
await this.extractFurniture(revision, className, callback);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
console.log();
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (error)
|
||||
if(furniData.wallitemtypes !== undefined)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
if(furniData.wallitemtypes.furnitype !== undefined)
|
||||
{
|
||||
for(const furniType of furniData.wallitemtypes.furnitype)
|
||||
{
|
||||
const className = furniType.classname.split('*')[0];
|
||||
const revision = furniType.revision;
|
||||
|
||||
if(classNames.indexOf(className) >= 0) continue;
|
||||
|
||||
classNames.push(className);
|
||||
|
||||
try
|
||||
{
|
||||
await this.extractFurniture(revision, className, callback);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(`Error parsing ${ className }: ` + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,20 +79,11 @@ export class FurnitureDownloader
|
||||
|
||||
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;
|
||||
|
||||
return (JSON.parse(content) as IFurnitureData);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
return (JSON.parse(content) as IFurnitureData);
|
||||
}
|
||||
|
||||
public async extractFurniture(revision: number, className: string, callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
||||
@ -118,23 +95,14 @@ export class FurnitureDownloader
|
||||
url = url.replace('%revision%', revision.toString());
|
||||
url = url.replace('%className%', className);
|
||||
|
||||
try
|
||||
{
|
||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||
|
||||
if(!buffer) return;
|
||||
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)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
await callback(newHabboAssetSWF, className);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import * as ora from 'ora';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { BundleProvider } from '../../common/bundle/BundleProvider';
|
||||
import { SpriteBundle } from '../../common/bundle/SpriteBundle';
|
||||
import { Configuration } from '../../common/config/Configuration';
|
||||
import { SWFConverter } from '../../common/converters/SWFConverter';
|
||||
import { IAssetData } from '../../mapping/json';
|
||||
@ -10,7 +8,6 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||
import File from '../../utils/File';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { NitroBundle } from '../../utils/NitroBundle';
|
||||
import { PetDownloader } from './PetDownloader';
|
||||
|
||||
@singleton()
|
||||
@ -18,7 +15,7 @@ export class PetConverter extends SWFConverter
|
||||
{
|
||||
constructor(
|
||||
private readonly _petDownloader: PetDownloader,
|
||||
private readonly _config: Configuration,
|
||||
private readonly _configuration: Configuration,
|
||||
private readonly _bundleProvider: BundleProvider,
|
||||
private readonly _logger: Logger)
|
||||
{
|
||||
@ -31,69 +28,30 @@ export class PetConverter extends SWFConverter
|
||||
|
||||
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())
|
||||
{
|
||||
spinner.text = `Creating Folder: ${ outputFolder.path }`;
|
||||
if(!outputFolder.isDirectory()) outputFolder.mkdirs();
|
||||
|
||||
spinner.render();
|
||||
|
||||
outputFolder.mkdirs();
|
||||
}
|
||||
|
||||
await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||
{
|
||||
spinner.text = 'Parsing Pet: ' + habboAssetSwf.getDocumentClass();
|
||||
|
||||
spinner.render();
|
||||
|
||||
try
|
||||
{
|
||||
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
||||
|
||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'pet', spriteBundle);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
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)
|
||||
await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||
{
|
||||
nitroBundle.addFile(spriteBundle.imageData.name, spriteBundle.imageData.buffer);
|
||||
}
|
||||
spinner.text = 'Parsing Pet: ' + habboAssetSwf.getDocumentClass();
|
||||
|
||||
const buffer = await nitroBundle.toBufferAsync();
|
||||
spinner.render();
|
||||
|
||||
await writeFile(path, buffer);
|
||||
const assetData = await this.mapXML2JSON(habboAssetSwf, 'pet');
|
||||
const spriteBundle = await this._bundleProvider.generateSpriteSheet(habboAssetSwf);
|
||||
|
||||
await this.fromHabboAsset(habboAssetSwf, outputFolder.path, 'pet', assetData, spriteBundle);
|
||||
});
|
||||
|
||||
spinner.succeed(`Pets finished in ${ Date.now() - now }ms`);
|
||||
}
|
||||
|
||||
catch (err)
|
||||
catch (error)
|
||||
{
|
||||
this._logger.logErrorAsync(err);
|
||||
spinner.fail('Pet failed: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,57 +63,48 @@ export class PetConverter extends SWFConverter
|
||||
|
||||
assetData.type = assetType;
|
||||
|
||||
try
|
||||
const indexXML = await PetConverter.getIndexXML(habboAssetSWF);
|
||||
|
||||
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
||||
|
||||
const assetXML = await PetConverter.getAssetsXML(habboAssetSWF);
|
||||
|
||||
if(assetXML)
|
||||
{
|
||||
const indexXML = await PetConverter.getIndexXML(habboAssetSWF);
|
||||
AssetMapper.mapXML(assetXML, assetData);
|
||||
|
||||
if(indexXML) IndexMapper.mapXML(indexXML, assetData);
|
||||
|
||||
const assetXML = await PetConverter.getAssetsXML(habboAssetSWF);
|
||||
|
||||
if(assetXML)
|
||||
if(assetData.palettes !== undefined)
|
||||
{
|
||||
AssetMapper.mapXML(assetXML, assetData);
|
||||
|
||||
if(assetData.palettes !== undefined)
|
||||
for(const paletteId in assetData.palettes)
|
||||
{
|
||||
for(const paletteId in assetData.palettes)
|
||||
const palette = assetData.palettes[paletteId];
|
||||
|
||||
const paletteColors = PetConverter.getPalette(habboAssetSWF, palette.source);
|
||||
|
||||
if(!paletteColors)
|
||||
{
|
||||
const palette = assetData.palettes[paletteId];
|
||||
delete assetData.palettes[paletteId];
|
||||
|
||||
const paletteColors = PetConverter.getPalette(habboAssetSWF, palette.source);
|
||||
|
||||
if(!paletteColors)
|
||||
{
|
||||
delete assetData.palettes[paletteId];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const rgbs: [ number, number, number ][] = [];
|
||||
|
||||
for(const rgb of paletteColors) rgbs.push([ rgb[0], rgb[1], rgb[2] ]);
|
||||
|
||||
palette.rgb = rgbs;
|
||||
continue;
|
||||
}
|
||||
|
||||
const rgbs: [ number, number, number ][] = [];
|
||||
|
||||
for(const rgb of paletteColors) rgbs.push([ rgb[0], rgb[1], rgb[2] ]);
|
||||
|
||||
palette.rgb = rgbs;
|
||||
}
|
||||
}
|
||||
|
||||
const logicXML = await PetConverter.getLogicXML(habboAssetSWF);
|
||||
|
||||
if(logicXML) LogicMapper.mapXML(logicXML, assetData);
|
||||
|
||||
const visualizationXML = await PetConverter.getVisualizationXML(habboAssetSWF);
|
||||
|
||||
if(visualizationXML) VisualizationMapper.mapXML(visualizationXML, assetData);
|
||||
|
||||
return assetData;
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
const logicXML = await PetConverter.getLogicXML(habboAssetSWF);
|
||||
|
||||
if(logicXML) LogicMapper.mapXML(logicXML, assetData);
|
||||
|
||||
const visualizationXML = await PetConverter.getVisualizationXML(habboAssetSWF);
|
||||
|
||||
if(visualizationXML) VisualizationMapper.mapXML(visualizationXML, assetData);
|
||||
|
||||
return assetData;
|
||||
}
|
||||
}
|
||||
|
@ -12,67 +12,52 @@ export class PetDownloader
|
||||
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 classNames: string[] = [];
|
||||
const petTypes = await this.parsePetTypes();
|
||||
|
||||
for(const petType of petTypes)
|
||||
if(!petTypes) throw new Error('invalid_pets');
|
||||
|
||||
const classNames: string[] = [];
|
||||
|
||||
for(const petType of petTypes)
|
||||
{
|
||||
if(classNames.indexOf(petType) >= 0) continue;
|
||||
|
||||
classNames.push(petType);
|
||||
|
||||
try
|
||||
{
|
||||
if(classNames.indexOf(petType) >= 0) continue;
|
||||
|
||||
classNames.push(petType);
|
||||
|
||||
try
|
||||
{
|
||||
await this.extractPet(petType, callback);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
await this.extractPet(petType, callback);
|
||||
}
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async parsePetTypes(): Promise<string[]>
|
||||
{
|
||||
try
|
||||
await this._config.loadExternalVariables();
|
||||
|
||||
const petTypes: string[] = [];
|
||||
|
||||
const pets = this._config.getValue('pet.configuration');
|
||||
|
||||
if(pets)
|
||||
{
|
||||
await this._config.loadExternalVariables();
|
||||
const types = pets.split(',');
|
||||
|
||||
const petTypes: string[] = [];
|
||||
|
||||
const pets = this._config.getValue('pet.configuration');
|
||||
|
||||
if(pets)
|
||||
{
|
||||
const types = pets.split(',');
|
||||
|
||||
for(const type of types) petTypes.push(type);
|
||||
}
|
||||
|
||||
return petTypes;
|
||||
for(const type of types) petTypes.push(type);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
return petTypes;
|
||||
}
|
||||
|
||||
public async extractPet(className: string, callback: (habboAssetSwf: HabboAssetSWF, className: string) => Promise<void>): Promise<void>
|
||||
public async extractPet(className: string, callback: (habboAssetSwf: HabboAssetSWF) => Promise<void>): Promise<void>
|
||||
{
|
||||
let url = this._config.getValue('dynamic.download.url.pet');
|
||||
|
||||
@ -80,19 +65,14 @@ export class PetDownloader
|
||||
|
||||
url = url.replace('%className%', className);
|
||||
|
||||
try
|
||||
{
|
||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
||||
const buffer = await FileUtilities.readFileAsBuffer(url);
|
||||
|
||||
await newHabboAssetSWF.setupAsync();
|
||||
await callback(newHabboAssetSWF, className);
|
||||
}
|
||||
if(!buffer) return;
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
||||
|
||||
await newHabboAssetSWF.setupAsync();
|
||||
|
||||
await callback(newHabboAssetSWF);
|
||||
}
|
||||
}
|
||||
|
@ -12,28 +12,19 @@ export class FileUtilities
|
||||
|
||||
let content: Buffer = null;
|
||||
|
||||
try
|
||||
if(url.startsWith('http'))
|
||||
{
|
||||
if(url.startsWith('http'))
|
||||
{
|
||||
const data = await fetch.default(url);
|
||||
const arrayBuffer = await data.arrayBuffer();
|
||||
const data = await fetch.default(url);
|
||||
const arrayBuffer = await data.arrayBuffer();
|
||||
|
||||
if(arrayBuffer) content = Buffer.from(arrayBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = await readFileAsync(url);
|
||||
}
|
||||
|
||||
return content;
|
||||
if(arrayBuffer) content = Buffer.from(arrayBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = await readFileAsync(url);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
public static async readFileAsString(url: string): Promise<string>
|
||||
@ -42,28 +33,19 @@ export class FileUtilities
|
||||
|
||||
let content = null;
|
||||
|
||||
try
|
||||
if(url.startsWith('http'))
|
||||
{
|
||||
if(url.startsWith('http'))
|
||||
{
|
||||
const data = await fetch.default(url);
|
||||
const data = await fetch.default(url);
|
||||
|
||||
if(data) content = await data.text();
|
||||
}
|
||||
else
|
||||
{
|
||||
const data = await readFileAsync(url);
|
||||
if(data) content = await data.text();
|
||||
}
|
||||
else
|
||||
{
|
||||
const data = await readFileAsync(url);
|
||||
|
||||
content = data.toString('utf-8');
|
||||
}
|
||||
|
||||
return content;
|
||||
content = data.toString('utf-8');
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.log();
|
||||
console.error(error);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user