mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-26 09:20: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);
|
// 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 }`;
|
await this._furniDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||||
|
|
||||||
spinner.render();
|
|
||||||
|
|
||||||
outputFolder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
await this._furniDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
|
||||||
{
|
|
||||||
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
|
||||||
|
|
||||||
spinner.render();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
|
spinner.text = 'Parsing Furniture: ' + habboAssetSwf.getDocumentClass();
|
||||||
|
|
||||||
|
spinner.render();
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
});
|
||||||
|
|
||||||
catch (error)
|
spinner.succeed(`Furniture finished in ${ Date.now() - now }ms`);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buffer = await nitroBundle.toBufferAsync();
|
catch (error)
|
||||||
|
{
|
||||||
await writeFile(path, buffer);
|
spinner.fail('Furniture failed: ' + error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async mapXML2JSON(habboAssetSWF: HabboAssetSWF, assetType: string): Promise<IAssetData>
|
private async mapXML2JSON(habboAssetSWF: HabboAssetSWF, assetType: string): Promise<IAssetData>
|
||||||
@ -100,31 +63,22 @@ 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);
|
||||||
|
|
||||||
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;
|
return assetData;
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,88 +2,74 @@ 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();
|
||||||
|
|
||||||
|
if(!furniData) throw new Error('invalid_furnidata');
|
||||||
|
|
||||||
|
const classNames: string[] = [];
|
||||||
|
|
||||||
|
if(furniData.roomitemtypes !== undefined)
|
||||||
{
|
{
|
||||||
const furniData = await this.parseFurniData();
|
if(furniData.roomitemtypes.furnitype !== undefined)
|
||||||
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)
|
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];
|
await this.extractFurniture(revision, className, callback);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(furniData.wallitemtypes !== undefined)
|
catch (error)
|
||||||
{
|
|
||||||
if(furniData.wallitemtypes.furnitype !== undefined)
|
|
||||||
{
|
|
||||||
for(const furniType of furniData.wallitemtypes.furnitype)
|
|
||||||
{
|
{
|
||||||
const className = furniType.classname.split('*')[0];
|
console.log();
|
||||||
const revision = furniType.revision;
|
console.error(error.message);
|
||||||
|
|
||||||
if(classNames.indexOf(className) >= 0) continue;
|
|
||||||
|
|
||||||
classNames.push(className);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await this.extractFurniture(revision, className, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
if(furniData.wallitemtypes !== undefined)
|
||||||
{
|
{
|
||||||
console.log();
|
if(furniData.wallitemtypes.furnitype !== undefined)
|
||||||
console.error(error);
|
{
|
||||||
|
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;
|
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);
|
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>
|
||||||
@ -118,23 +95,14 @@ 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;
|
||||||
|
|
||||||
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
||||||
|
|
||||||
await newHabboAssetSWF.setupAsync();
|
await newHabboAssetSWF.setupAsync();
|
||||||
|
|
||||||
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();
|
||||||
{
|
|
||||||
spinner.text = `Creating Folder: ${ outputFolder.path }`;
|
|
||||||
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
const assetData = await this.mapXML2JSON(habboAssetSWF, 'pet');
|
await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) =>
|
||||||
|
|
||||||
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);
|
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;
|
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);
|
if(assetData.palettes !== undefined)
|
||||||
|
|
||||||
const assetXML = await PetConverter.getAssetsXML(habboAssetSWF);
|
|
||||||
|
|
||||||
if(assetXML)
|
|
||||||
{
|
{
|
||||||
AssetMapper.mapXML(assetXML, assetData);
|
for(const paletteId in assetData.palettes)
|
||||||
|
|
||||||
if(assetData.palettes !== undefined)
|
|
||||||
{
|
{
|
||||||
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);
|
continue;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
const logicXML = await PetConverter.getLogicXML(habboAssetSWF);
|
||||||
{
|
|
||||||
console.log();
|
if(logicXML) LogicMapper.mapXML(logicXML, assetData);
|
||||||
console.error(error);
|
|
||||||
}
|
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)
|
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();
|
|
||||||
const classNames: string[] = [];
|
|
||||||
|
|
||||||
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;
|
await this.extractPet(petType, callback);
|
||||||
|
|
||||||
classNames.push(petType);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await this.extractPet(petType, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log();
|
console.log();
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async parsePetTypes(): Promise<string[]>
|
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[] = [];
|
for(const type of types) petTypes.push(type);
|
||||||
|
|
||||||
const pets = this._config.getValue('pet.configuration');
|
|
||||||
|
|
||||||
if(pets)
|
|
||||||
{
|
|
||||||
const types = pets.split(',');
|
|
||||||
|
|
||||||
for(const type of types) petTypes.push(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return petTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
return petTypes;
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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');
|
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);
|
|
||||||
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
|
||||||
|
|
||||||
await newHabboAssetSWF.setupAsync();
|
if(!buffer) return;
|
||||||
await callback(newHabboAssetSWF, className);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (error)
|
const newHabboAssetSWF = new HabboAssetSWF(buffer);
|
||||||
{
|
|
||||||
console.log();
|
await newHabboAssetSWF.setupAsync();
|
||||||
console.error(error);
|
|
||||||
}
|
await callback(newHabboAssetSWF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,19 @@ 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 arrayBuffer = await data.arrayBuffer();
|
||||||
const data = await fetch.default(url);
|
|
||||||
const arrayBuffer = await data.arrayBuffer();
|
|
||||||
|
|
||||||
if(arrayBuffer) content = Buffer.from(arrayBuffer);
|
if(arrayBuffer) content = Buffer.from(arrayBuffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
content = await readFileAsync(url);
|
content = await readFileAsync(url);
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
return content;
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async readFileAsString(url: string): Promise<string>
|
public static async readFileAsString(url: string): Promise<string>
|
||||||
@ -42,28 +33,19 @@ export class FileUtilities
|
|||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if(data) content = await data.text();
|
if(data) content = await data.text();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const data = await readFileAsync(url);
|
const data = await readFileAsync(url);
|
||||||
|
|
||||||
content = data.toString('utf-8');
|
content = data.toString('utf-8');
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (error)
|
return content;
|
||||||
{
|
|
||||||
console.log();
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user