Added libjpeg-turbo to FileHandler with a working File::ReadImageFile() function. The dependency on SOIL in libvitaboy Renderer has therefore been removed.

Also fixed formatting in recent source files.

My next task is implementing IFF chunk reading. I'll also make a tool that can convert the game's behavior.iff file to an HTML page.
This commit is contained in:
Fatbag 2012-02-27 02:55:53 -06:00
parent 83ad5d89d1
commit f23bcd7b4d
18 changed files with 816 additions and 295 deletions

View file

@ -3,6 +3,7 @@ project(FileHandler)
add_subdirectory(libexpat)
add_subdirectory(libfar)
add_subdirectory(libjpeg-turbo)
add_subdirectory(libpng)
add_subdirectory(utk)
add_subdirectory(xa)
@ -14,6 +15,7 @@ set(FILEHANDLER_MINOR 0)
set(FILEHANDLER_SOURCES
File.cpp
Image.cpp
)
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
@ -32,4 +34,4 @@ set_target_properties(FileHandler_shared PROPERTIES
PREFIX ""
IMPORT_PREFIX ""
CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(FileHandler_shared kernel32)
target_link_libraries(FileHandler_shared kernel32 jpegturbo_static)

View file

@ -1,5 +1,5 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
FileHandler - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -14,8 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <windows.h>
#include "FileHandler.hpp"
namespace File {
@ -23,20 +21,27 @@ namespace File {
int Error = 0;
unsigned FileSize = 0;
const uint8_t Signature[][4] = {
{0xFF,0xD8,0xFF,0xE0} //JPEG
};
const uint8_t SignatureSize[] = {
4 //JPEG
};
uint8_t * ReadFile(const char * Filename){
HANDLE hFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(hFile == INVALID_HANDLE_VALUE){
File::Error = (GetLastError() == ERROR_FILE_NOT_FOUND) ? FERR_NOT_FOUND : FERR_OPEN;
return NULL;
}
FileSize = GetFileSize(hFile, NULL);
if(FileSize == 0){
CloseHandle(hFile);
File::Error = FERR_BLANK;
return NULL;
}
uint8_t * InData = (uint8_t*) malloc(FileSize);
if(InData == NULL){
CloseHandle(hFile);
@ -47,7 +52,7 @@ uint8_t * ReadFile(const char * Filename){
DWORD bytestransferred;
BOOL result = ::ReadFile(hFile, InData, FileSize, &bytestransferred, NULL);
CloseHandle(hFile);
if(!result || bytestransferred != FileSize){
free(InData);
File::Error = FERR_READ;

View file

@ -14,19 +14,51 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef FILEHANDLER_HPP
#define FILEHANDLER_HPP
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#ifndef NOWINDOWS
#include <windows.h>
#endif
struct Asset_t {
uint32_t Group;
uint32_t File;
uint32_t Type;
};
enum FErr {
FERR_NOT_FOUND,
FERR_OPEN,
FERR_BLANK,
FERR_MEMORY,
FERR_READ
FERR_READ,
FERR_UNRECOGNIZED
};
enum ImageFormat_t {
FIMG_BGR24
};
struct Image_t {
unsigned Width, Height;
ImageFormat_t Format;
uint8_t * Data;
};
namespace File {
extern int Error;
extern unsigned FileSize;
extern size_t FileSize;
uint8_t * ReadFile(const char * Filename);
Image_t * ReadImageFile(const char * Filename);
uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize);
}
}
#endif

View file

@ -0,0 +1,95 @@
/*
FileHandler - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <memory.h>
#include "libjpeg-turbo/jpeglib.h"
#define NOWINDOWS
#include "FileHandler.hpp"
namespace File {
Image_t * ReadImageFile(const char * Filename){
uint8_t * InData = File::ReadFile(Filename);
if(InData == NULL) return NULL;
Image_t * Image = (Image_t*) malloc(sizeof(Image_t));
if(Image == NULL){
free(InData);
return NULL;
}
uint8_t * OutData = ReadJPG(Image, InData, File::FileSize);
free(InData);
if(OutData != NULL){
return Image;
}
File::Error = FERR_UNRECOGNIZED;
free(Image);
return NULL;
}
uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize){
//Initialize
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, (unsigned char*) InData, FileSize);
if(jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK){
jpeg_destroy_decompress(&cinfo);
return NULL;
}
if(!jpeg_start_decompress(&cinfo)){
jpeg_destroy_decompress(&cinfo);
return NULL;
}
//Read
unsigned row_stride = cinfo.output_width * cinfo.output_components;
uint8_t * OutData = (uint8_t*) malloc(cinfo.output_width * cinfo.output_height * cinfo.output_components);
if(OutData == NULL){
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return NULL;
}
for(unsigned i=0; cinfo.output_scanline < cinfo.output_height; i++){
//According to the libjpeg documentation,
//jpeg_read_scanlines can only really read 1 scanline at a time.
uint8_t * Location = OutData + i*row_stride;
if(!jpeg_read_scanlines(&cinfo, &Location, 1)){
free(OutData);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return NULL;
}
}
//Close up
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
if(Image){
Image->Width = cinfo.output_width;
Image->Height = cinfo.output_height;
Image->Format = FIMG_BGR24;
Image->Data = OutData;
}
return OutData;
}
}

View file

@ -7,8 +7,14 @@ set(LIBVITABOY_MINOR 1)
set(LIBVITABOY_SOURCES
anim.cpp
apr.cpp
bnd.cpp
col.cpp
hag.cpp
libvitaboy.cpp
mesh.cpp
oft.cpp
po.cpp
skel.cpp
)
if(WIN32)
@ -33,7 +39,7 @@ set_target_properties(libvitaboy_shared PROPERTIES
CLEAN_DIRECT_OUTPUT 1)
add_executable(vbparse vbparse.cpp)
target_link_libraries(vbparse libvitaboy_static)
target_link_libraries(vbparse libvitaboy_static FileHandler_shared)
add_executable(Renderer Renderer.cpp)
target_link_libraries(Renderer libvitaboy_shared "${CMAKE_SOURCE_DIR}/Libraries/libvitaboy/libSOIL.a" FileHandler_shared opengl32 glu32 winmm)
target_link_libraries(Renderer libvitaboy_shared FileHandler_shared opengl32 glu32 winmm)

View file

@ -44,13 +44,11 @@
F11: Enter/leave fullscreen
*/
#include <windows.h>
#include <math.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glext.h>
#include <FileHandler.hpp>
#include "SOIL.h"
#include "libvitaboy.hpp"
HDC hDC=NULL;
@ -72,7 +70,7 @@ CharacterPlacement_t Character = {{0,-3,0}, {0,0,0}};
Skeleton_t Skeleton;
const unsigned TextureCount = 3;
GLuint texture[3];
unsigned texture[3];
enum { Texture_Body, Texture_Head, Texture_Hand };
const char* const TexturePaths[] = {"body.jpg", "head.jpg", "hand.jpg"};
@ -94,14 +92,47 @@ float FramePeriod;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int LoadGLTextures()
void DisplayFileError(const char * Filename){
const char * Message;
switch(File::Error){
case FERR_NOT_FOUND:
Message = "%s does not exist.";
break;
case FERR_OPEN:
Message = "%s could not be opened for reading.";
break;
case FERR_BLANK:
case FERR_UNRECOGNIZED:
Message = "%s is corrupt or invalid.";
break;
case FERR_MEMORY:
Message = "Memory for %s could not be allocated.";
break;
default:
Message = "%s could not be read.";
break;
}
char Buffer[1024];
sprintf(Buffer, Message, Filename);
MessageBox(hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
}
bool LoadTextures()
{
glGenTextures(3, texture);
for(int i=0; i<3; i++){
texture[i] = SOIL_load_OGL_texture(TexturePaths[i], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0);
if(texture[i] == 0)
Image_t * Image = File::ReadImageFile(TexturePaths[i]);
if(!Image){
DisplayFileError(TexturePaths[i]);
return false;
}
glBindTexture(GL_TEXTURE_2D, texture[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, Image->Width, Image->Height, 0, GL_RGB, GL_UNSIGNED_BYTE, Image->Data);
free(Image->Data);
free(Image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -126,9 +157,9 @@ void ResizeScene(GLsizei width, GLsizei height)
glLoadIdentity();
}
int InitGL()
bool InitGL()
{
if(!LoadGLTextures())
if(!LoadTextures())
return false;
glShadeModel(GL_SMOOTH);
@ -170,7 +201,7 @@ void TransformVertices(Bone_t& Bone)
unsigned VertexIndex = Mesh.BoneBindings[BoneIndex].FirstFixedVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z);
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
AbsoluteVertex.x = Matrix[12];
@ -182,7 +213,7 @@ void TransformVertices(Bone_t& Bone)
unsigned VertexIndex = Mesh.FixedVertexCount + Mesh.BoneBindings[BoneIndex].FirstBlendedVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z);
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
AbsoluteVertex.x = Matrix[12];
@ -240,8 +271,10 @@ void DrawMeshes()
for(unsigned i=0; i<MeshCount; i++){
glBindTexture(GL_TEXTURE_2D, texture[Mesh_UseTexture[i]]);
glVertexPointer(3, GL_FLOAT, offsetof(Vertex_t, y)-offsetof(Vertex_t, x)-sizeof(float), Meshes[i].TransformedVertexData);
glTexCoordPointer(2, GL_FLOAT, offsetof(TextureVertex_t, v)-offsetof(TextureVertex_t, u)-sizeof(float), Meshes[i].TransformedTextureData);
glVertexPointer(3, GL_FLOAT, offsetof(Vertex_t, y)-offsetof(Vertex_t, x)-sizeof(float),
Meshes[i].TransformedVertexData);
glTexCoordPointer(2, GL_FLOAT, offsetof(TextureVertex_t, v)-offsetof(TextureVertex_t, u)-sizeof(float),
Meshes[i].TransformedTextureData);
glDrawElements(GL_TRIANGLES, Meshes[i].FaceCount*3, GL_UNSIGNED_INT, Meshes[i].FaceData);
}
@ -255,7 +288,7 @@ void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
float Duration = (float)Animation.Motions[0].FrameCount/30;
AnimationTime += TimeDelta;
while(AnimationTime >= Duration) AnimationTime -= Duration;
if(AnimationTime<0) AnimationTime = 0;
if(AnimationTime<0) AnimationTime = 0; //Safe-guard against rounding error
for(unsigned i=0; i<Animation.MotionsCount; i++){
unsigned BoneIndex = FindBone(Skeleton, Animation.Motions[i].BoneName, Skeleton.BoneCount);
@ -435,7 +468,7 @@ BOOL CreateGLWindow(const char * title, int width, int height, int bits, bool fu
MessageBox(NULL, "Failed to registrer the window class.", NULL, MB_OK | MB_ICONERROR);
return false;
}
DWORD dwStyle, dwExStyle;
if(fullscreen){
@ -598,7 +631,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0);
} return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
@ -609,35 +642,14 @@ bool Read(const char * Filename, uint8_t ** InData){
return true;
}
const char * Message;
switch(File::Error){
case FERR_NOT_FOUND:
Message = "%s does not exist.";
break;
case FERR_OPEN:
Message = "%s could not be opened for reading.";
break;
case FERR_BLANK:
Message = "%s is corrupt or invalid.";
break;
case FERR_MEMORY:
Message = "Memory for %s could not be allocated.";
break;
default:
Message = "%s could not be read.";
break;
}
char Buffer[1024];
sprintf(Buffer, Message, Filename);
MessageBox(hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
DisplayFileError(Filename);
return false;
}
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
uint8_t * InData;
if(!Read("skeleton.skel", &InData))
return 0;
ReadSkeleton(Skeleton);
@ -649,7 +661,7 @@ int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
ReadMesh(Meshes[i]);
free(InData);
}
if(!Read("animation.anim", &InData))
return 0;
ReadAnimation(Animation);

View file

@ -0,0 +1,33 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadAppearance(Appearance_t& Appearance){
printf("\n========== Appearance ==========\n");
Appearance.Version = VBFile.readint32();
printf("Version: %u\n", Appearance.Version);
ReadAsset(Appearance.Thumbnail, NOGROUP);
Appearance.BindingCount = VBFile.readint32();
printf("Binding count: %u\n", Appearance.BindingCount);
Appearance.Bindings = (Asset_t*) malloc(Appearance.BindingCount * sizeof(Asset_t));
for(unsigned i=0; i<Appearance.BindingCount; i++){
printf("\n [Binding %u]\n", i);
ReadAsset(Appearance.Bindings[i], NOGROUP);
}
}

View file

@ -0,0 +1,38 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadBinding(Binding_t& Binding){
printf("\n========== Binding ==========\n");
Binding.Version = VBFile.readint32();
printf("Version: %u\n", Binding.Version);
Binding.BoneName = VBFile.readstring();
printf("Bone name: %s\n", Binding.BoneName);
Binding.MeshDef = VBFile.readint32();
if(Binding.MeshDef){
printf("\n Mesh:\n");
ReadAsset(Binding.Mesh, READGROUP);
}
Binding.AppearanceDef = VBFile.readint32();
if(Binding.AppearanceDef){
printf("\n Appearance:\n");
ReadAsset(Binding.Appearance, READGROUP);
}
}

View file

@ -0,0 +1,31 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadCollection(Collection_t& Collection){
printf("\n========== Collection ==========\n");
Collection.POCount = VBFile.readint32();
printf("Purchasable Outfit count: %u\n", Collection.POCount);
Collection.PurchasableOutfits = (PODef_t*) malloc(Collection.POCount * sizeof(PODef_t));
for(unsigned i=0; i<Collection.POCount; i++){
printf("\n [Purchasable Outfit %u]\n", i);
Collection.PurchasableOutfits[i].Index = VBFile.readint32();
printf(" | Index: %u\n", Collection.PurchasableOutfits[i].Index);
ReadAsset(Collection.PurchasableOutfits[i].PO, NOGROUP);
}
}

View file

@ -0,0 +1,28 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadHandGroup(HandGroup_t& HandGroup){
printf("\n========== Hand Group ==========\n");
HandGroup.Version = VBFile.readint32();
printf("Version: %u\n", HandGroup.Version);
for(unsigned i=0; i<18; i++){
printf("\n [Purchasable Outfit %u]\n", i);
ReadAsset(HandGroup.HandAppearances[i], NOGROUP);
}
}

View file

@ -18,6 +18,15 @@
VBFile_t VBFile;
void ReadAsset(Asset_t& Asset, bool ReadGroup){
Asset.Group = (ReadGroup) ? VBFile.readint32() : 0xA96F6D42;
printf(" | Group: %u\n", Asset.Group);
Asset.File = VBFile.readint32();
printf(" | File: %u\n", Asset.File);
Asset.Type = VBFile.readint32();
printf(" | Type: %u\n", Asset.Type);
}
void ReadPropEntry(KeyValuePair_t& Entry){
Entry.Key = VBFile.readstring();
printf(" | | | | | Key: %s\n", Entry.Key);
@ -29,7 +38,7 @@ void ReadPropEntries(Prop_t& Prop){
unsigned count = Prop.EntriesCount = VBFile.readint32();
printf(" | | | | EntriesCount: %u\n", Prop.EntriesCount);
Prop.Entries = (KeyValuePair_t*) malloc(count * sizeof(KeyValuePair_t));
for(unsigned i=0; i<count; i++){
printf(" | | | | [Entry %u]\n", i+1);
ReadPropEntry(Prop.Entries[i]);

View file

@ -14,50 +14,54 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef LIBVITABOY_HPP
#define LIBVITABOY_HPP
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <memory.h>
#include <FileHandler.hpp>
class VBFile_t {
private:
const uint8_t *Buffer, *Position;
unsigned Size;
public:
inline void set(const void *_Buffer, unsigned _Size){
Buffer = (const uint8_t*) _Buffer;
Position = (const uint8_t*) _Buffer;
Size = _Size;
}
inline unsigned getpos(){
return Position-Buffer;
}
inline void seekto(unsigned offset){
Position = Buffer+offset;
}
inline uint32_t readint32(){
uint32_t value = (uint32_t)((Position[0]<<(8*3)) | (Position[1]<<(8*2)) | (Position[2]<<(8*1)) | (Position[3]<<(8*0)));
Position += 4;
return value;
}
inline uint32_t readint16(){
uint16_t value = (uint16_t)((Position[0]<<(8*1)) | (Position[1]<<(8*0)));
Position += 2;
return value;
}
inline uint32_t readint8(){
uint8_t value = (uint8_t)((Position[0]<<(8*0)));
Position += 1;
return value;
}
inline float readfloat(){
//Obviously a platform-dependent implementation
float value;
@ -65,12 +69,12 @@ class VBFile_t {
Position += 4;
return value;
}
inline void readbytes(void* Destination, unsigned length){
memcpy(Destination, Position, length);
Position += length;
}
inline char* readstring(){
//Read a Pascal string with 1 length byte
unsigned length = readint8();
@ -79,7 +83,7 @@ class VBFile_t {
string[length] = '\0';
return string;
}
inline char* readstring2(){
//Read a Pascal string with 2 length bytes
unsigned length = readint16();
@ -96,6 +100,11 @@ extern VBFile_t VBFile;
** Common
*/
enum ReadGroup {
NOGROUP,
READGROUP
};
struct Translation_t {
float x, y, z;
};
@ -119,6 +128,7 @@ struct PropsList_t {
Prop_t * Props;
};
void ReadAsset(Asset_t& Asset, bool ReadGroup);
void ReadPropEntry(KeyValuePair_t& Entry);
void ReadPropEntries(Prop_t& Prop);
void ReadPropsList(PropsList_t& PropsList);
@ -145,7 +155,7 @@ struct Motion_t {
uint32_t Unknown;
char * BoneName;
uint32_t FrameCount;
float Duration;
float Duration; //Converted to seconds
uint8_t HasTranslation;
uint8_t HasRotation;
uint32_t FirstTranslation;
@ -165,7 +175,7 @@ struct Motion_t {
struct Animation_t {
uint32_t Version;
char * Name;
float Duration;
float Duration; //Converted to seconds
float Distance;
uint8_t IsMoving;
uint32_t TranslationsCount;
@ -185,6 +195,64 @@ void ReadTimePropsList(TimePropsList_t& TimePropsList);
void ReadTimePropsLists(Motion_t& Motion);
/****
** Appearance (*.apr)
*/
struct Appearance_t {
uint32_t Version;
Asset_t Thumbnail;
uint32_t BindingCount;
Asset_t * Bindings;
};
void ReadAppearance(Appearance_t& Appearance);
/****
** Binding (*.bnd)
*/
struct Binding_t {
uint32_t Version;
char * BoneName;
uint32_t MeshDef;
Asset_t Mesh;
uint32_t AppearanceDef;
Asset_t Appearance;
};
void ReadBinding(Binding_t& Binding);
/****
** Collection (*.col)
*/
struct PODef_t {
uint32_t Index;
Asset_t PO;
};
struct Collection_t {
uint32_t POCount;
PODef_t * PurchasableOutfits;
};
void ReadCollection(Collection_t& Collection);
/****
** Hand Group (*.hag)
*/
struct HandGroup_t {
uint32_t Version;
Asset_t HandAppearances[18];
};
void ReadHandGroup(HandGroup_t& HandGroup);
/****
** Mesh (*.mesh)
*/
@ -237,6 +305,48 @@ struct Mesh_t {
void ReadMesh(Mesh_t& Mesh);
/****
** Outfit (*.oft)
*/
enum OutfitColor {
OutfitColor_Light,
OutfitColor_Medium,
OutfitColor_Dark
};
enum OutfitRegion {
OutfitRegion_Head = 0,
OutfitRegion_Body = 18
};
struct Outfit_t {
uint32_t Version;
uint32_t Unknown;
Asset_t Appearance[3];
uint32_t Group;
uint32_t Region;
};
void ReadOutfit(Outfit_t& Outfit);
/****
** Purchasable Outfit (*.po)
*/
struct PurchasableOutfit_t {
uint32_t Version;
uint32_t Unknown;
uint32_t OutfitDef;
Asset_t Outfit;
uint32_t CollectionDef;
Asset_t Collection;
};
void ReadPurchasableOutfit(PurchasableOutfit_t& PurchasableOutfit);
/****
** Skeleton (*.skel)
*/
@ -254,7 +364,7 @@ struct Bone_t {
uint32_t CanBlend;
float WiggleValue;
float WigglePower;
unsigned ChildrenCount;
Bone_t ** Children;
};
@ -268,4 +378,6 @@ struct Skeleton_t {
void ReadSkeleton(Skeleton_t& Bone);
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index);
unsigned FindBone(Skeleton_t& Skeleton, const char * BoneName, unsigned Count);
unsigned FindBone(Skeleton_t& Skeleton, const char * BoneName, unsigned Count);
#endif

View file

@ -20,7 +20,7 @@ void ReadMesh(Mesh_t& Mesh){
printf("\n========== Mesh ==========\n");
Mesh.Version = VBFile.readint32();
printf("Version: %u\n", Mesh.Version);
Mesh.BoneCount = VBFile.readint32();
printf("BoneCount: %u\n", Mesh.BoneCount);
Mesh.BoneNames = (char**) malloc(Mesh.BoneCount * sizeof(char*));
@ -28,7 +28,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.BoneNames[i] = VBFile.readstring();
printf("| Bone %u: %s\n", i+1, Mesh.BoneNames[i]);
}
Mesh.FaceCount = VBFile.readint32();
printf("FaceCount: %u\n", Mesh.FaceCount);
Mesh.FaceData = (Face_t*) malloc(Mesh.FaceCount * sizeof(Face_t));
@ -37,7 +37,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.FaceData[i].VertexB = VBFile.readint32();
Mesh.FaceData[i].VertexC = VBFile.readint32();
}
Mesh.BindingCount = VBFile.readint32();
Mesh.BoneBindings = (BoneBinding_t*) malloc(Mesh.BindingCount * sizeof(BoneBinding_t));
printf("BindingCount: %u\n", Mesh.BindingCount);
@ -48,7 +48,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.BoneBindings[i].FirstBlendedVertex = VBFile.readint32();
Mesh.BoneBindings[i].BlendedVertexCount = VBFile.readint32();
}
Mesh.FixedVertexCount = VBFile.readint32();
printf("FixedVertexCount: %u\n", Mesh.FixedVertexCount);
Mesh.TextureVertexData = (TextureVertex_t*) malloc(Mesh.FixedVertexCount * sizeof(TextureVertex_t));
@ -56,7 +56,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.TextureVertexData[i].u = VBFile.readfloat();
Mesh.TextureVertexData[i].v = VBFile.readfloat();
}
Mesh.BlendedVertexCount = VBFile.readint32();
printf("BlendedVertexCount: %u\n", Mesh.BlendedVertexCount);
Mesh.BlendData = (BlendData_t*) malloc(Mesh.BlendedVertexCount * sizeof(BlendData_t));
@ -64,7 +64,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.BlendData[i].Weight = (float)VBFile.readint32()/0x8000;
Mesh.BlendData[i].OtherVertex = VBFile.readint32();
}
Mesh.TotalVertexCount = VBFile.readint32();
printf("TotalVertexCount: %u\n", Mesh.TotalVertexCount);
Mesh.VertexData = (Vertex_t*) malloc(Mesh.TotalVertexCount * sizeof(Vertex_t));
@ -79,7 +79,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.VertexNorms[i].x = VBFile.readfloat();
Mesh.VertexNorms[i].y = VBFile.readfloat();
Mesh.VertexNorms[i].z = VBFile.readfloat();
if(i<Mesh.FixedVertexCount){
//Fixed vertex
Mesh.TransformedTextureData[i].u = Mesh.TextureVertexData[i].u;

View file

@ -0,0 +1,37 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadOutfit(Outfit_t& Outfit){
printf("\n========== Outfit ==========\n");
Outfit.Version = VBFile.readint32();
printf("Version: %u\n", Outfit.Version);
Outfit.Unknown = VBFile.readint32();
printf("Unknown: %u\n", Outfit.Unknown);
const char* Colors[] = {"Light", "Medium", "Dark"};
for(unsigned i=0; i<3; i++){
printf("\n [%s Appearance]\n", Colors[i]);
ReadAsset(Outfit.Appearance[i], NOGROUP);
}
Outfit.Group = VBFile.readint32();
printf("Group: %u\n", Outfit.Group);
Outfit.Region = VBFile.readint32();
printf("Region: %u\n", Outfit.Region);
}

View file

@ -0,0 +1,38 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadPurchasableOutfit(PurchasableOutfit_t& PurchasableOutfit){
printf("\n========== Purchasable Outfit ==========\n");
PurchasableOutfit.Version = VBFile.readint32();
printf("Version: %u\n", PurchasableOutfit.Version);
PurchasableOutfit.Unknown = VBFile.readint32();
printf("Unknown: %u\n", PurchasableOutfit.Unknown);
PurchasableOutfit.OutfitDef = VBFile.readint32();
if(PurchasableOutfit.OutfitDef){
printf("\n Outfit:\n");
ReadAsset(PurchasableOutfit.Outfit, READGROUP);
}
PurchasableOutfit.CollectionDef = VBFile.readint32();
if(PurchasableOutfit.CollectionDef){
printf("\n Collection:\n");
ReadAsset(PurchasableOutfit.Collection, READGROUP);
}
}

View file

@ -1,99 +1,95 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
static unsigned bonenumber = 0;
void ReadSkeleton(Skeleton_t& Skeleton){
printf("\n========== Skeleton ==========\n");
Skeleton.Version = VBFile.readint32();
printf("Version: %u\n", Skeleton.Version);
Skeleton.Name = VBFile.readstring();
printf("Name: %s\n", Skeleton.Name);
Skeleton.BoneCount = VBFile.readint16();
printf("BoneCount: %u\n", Skeleton.BoneCount);
Skeleton.Bones = (Bone_t*) malloc(Skeleton.BoneCount * sizeof(Bone_t));
for(unsigned i=0; i<Skeleton.BoneCount; i++){
ReadBone(Skeleton, Skeleton.Bones[i], i);
}
}
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){
bonenumber++;
printf("\n [Bone %u]\n", bonenumber);
Bone.Unknown = VBFile.readint32();
printf(" | Unknown: %u\n", Bone.Unknown);
Bone.Name = VBFile.readstring();
printf(" | Name: %s\n", Bone.Name);
Bone.ParentsName = VBFile.readstring();
printf(" | Parent's name: %s\n", Bone.ParentsName);
Bone.HasProps = VBFile.readint8();
printf(" | HasProps: %u\n", Bone.HasProps);
if(Bone.HasProps){
ReadPropsList(Bone.PropsList);
}
printf(" | Translation:\n");
Bone.Translation.x = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Translation.x);
Bone.Translation.y = VBFile.readfloat();
printf(" | | y: %g\n", Bone.Translation.y);
Bone.Translation.z = VBFile.readfloat();
printf(" | | z: %g\n", Bone.Translation.z);
printf(" | Rotation:\n");
Bone.Rotation.x = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Rotation.x);
Bone.Rotation.y = VBFile.readfloat();
printf(" | | y: %g\n", Bone.Rotation.y);
Bone.Rotation.z = VBFile.readfloat();
printf(" | | z: %g\n", Bone.Rotation.z);
Bone.Rotation.w = VBFile.readfloat();
printf(" | | w: %g\n", Bone.Rotation.w);
Bone.CanTranslate = VBFile.readint32();
printf(" | CanTranslate: %u\n", Bone.CanTranslate);
Bone.CanRotate = VBFile.readint32();
printf(" | CanRotate: %u\n", Bone.CanRotate);
Bone.CanBlend = VBFile.readint32();
printf(" | CanBlend: %u\n", Bone.CanBlend);
Bone.WiggleValue = VBFile.readfloat();
printf(" | WiggleValue: %g\n", Bone.WiggleValue);
Bone.WigglePower = VBFile.readfloat();
printf(" | WigglePower: %g\n", Bone.WigglePower);
Bone.ChildrenCount = 0;
Bone.Children = (Bone_t**) malloc((Skeleton.BoneCount-Index-1) * sizeof(Bone_t*));
unsigned Parent = FindBone(Skeleton, Bone.ParentsName, Index);
if(Parent != (unsigned)-1){
Bone_t& ParentBone = Skeleton.Bones[Parent];
ParentBone.Children[ParentBone.ChildrenCount] = &Bone;
ParentBone.ChildrenCount++;
}
}
unsigned FindBone(Skeleton_t& Skeleton, const char * BoneName, unsigned Count){
for(unsigned i=0; i<Count; i++){
if(!strcmp(Skeleton.Bones[i].Name, BoneName)) return i;
}
return (unsigned)-1;
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libvitaboy.hpp"
void ReadSkeleton(Skeleton_t& Skeleton){
printf("\n========== Skeleton ==========\n");
Skeleton.Version = VBFile.readint32();
printf("Version: %u\n", Skeleton.Version);
Skeleton.Name = VBFile.readstring();
printf("Name: %s\n", Skeleton.Name);
Skeleton.BoneCount = VBFile.readint16();
printf("BoneCount: %u\n", Skeleton.BoneCount);
Skeleton.Bones = (Bone_t*) malloc(Skeleton.BoneCount * sizeof(Bone_t));
for(unsigned i=0; i<Skeleton.BoneCount; i++){
printf("\n [Bone %u]\n", i);
ReadBone(Skeleton, Skeleton.Bones[i], i);
}
}
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){
Bone.Unknown = VBFile.readint32();
printf(" | Unknown: %u\n", Bone.Unknown);
Bone.Name = VBFile.readstring();
printf(" | Name: %s\n", Bone.Name);
Bone.ParentsName = VBFile.readstring();
printf(" | Parent's name: %s\n", Bone.ParentsName);
Bone.HasProps = VBFile.readint8();
printf(" | HasProps: %u\n", Bone.HasProps);
if(Bone.HasProps){
ReadPropsList(Bone.PropsList);
}
printf(" | Translation:\n");
Bone.Translation.x = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Translation.x);
Bone.Translation.y = VBFile.readfloat();
printf(" | | y: %g\n", Bone.Translation.y);
Bone.Translation.z = VBFile.readfloat();
printf(" | | z: %g\n", Bone.Translation.z);
printf(" | Rotation:\n");
Bone.Rotation.x = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Rotation.x);
Bone.Rotation.y = VBFile.readfloat();
printf(" | | y: %g\n", Bone.Rotation.y);
Bone.Rotation.z = VBFile.readfloat();
printf(" | | z: %g\n", Bone.Rotation.z);
Bone.Rotation.w = VBFile.readfloat();
printf(" | | w: %g\n", Bone.Rotation.w);
Bone.CanTranslate = VBFile.readint32();
printf(" | CanTranslate: %u\n", Bone.CanTranslate);
Bone.CanRotate = VBFile.readint32();
printf(" | CanRotate: %u\n", Bone.CanRotate);
Bone.CanBlend = VBFile.readint32();
printf(" | CanBlend: %u\n", Bone.CanBlend);
Bone.WiggleValue = VBFile.readfloat();
printf(" | WiggleValue: %g\n", Bone.WiggleValue);
Bone.WigglePower = VBFile.readfloat();
printf(" | WigglePower: %g\n", Bone.WigglePower);
Bone.ChildrenCount = 0;
Bone.Children = (Bone_t**) malloc((Skeleton.BoneCount-Index-1) * sizeof(Bone_t*));
unsigned Parent = FindBone(Skeleton, Bone.ParentsName, Index);
if(Parent != (unsigned)-1){
Bone_t& ParentBone = Skeleton.Bones[Parent];
ParentBone.Children[ParentBone.ChildrenCount] = &Bone;
ParentBone.ChildrenCount++;
}
}
unsigned FindBone(Skeleton_t& Skeleton, const char * BoneName, unsigned Count){
for(unsigned i=0; i<Count; i++){
if(!strcmp(Skeleton.Bones[i].Name, BoneName)) return i;
}
return (unsigned)-1;
}

View file

@ -1,125 +1,156 @@
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <windows.h>
#include "libvitaboy.hpp"
enum VBFileType {
VBFILE_ANIM,
VBFILE_APR,
VBFILE_BND,
VBFILE_COL,
VBFILE_HAG,
VBFILE_MESH,
VBFILE_OFT,
VBFILE_PO,
VBFILE_SKEL
};
int main(int argc, char *argv[]){
int type;
char * InFile;
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
printf("Usage: vbparse [-t type] infile\n"
"Parse a TSO VitaBoy file.\n"
"\n"
"Supported types:\n"
" (*) ANIM - Animation\n"
" (*) APR - Appearance\n"
" (*) BND - Binding\n"
" (*) COL - Collection\n"
" (*) HAG - Hand group\n"
" (*) MESH - Mesh\n"
" (*) OFT - Outfit\n"
" (*) PO - Purchasable object\n"
" (*) SKEL - Skeleton\n"
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"
"vbparse is maintained by the Niotso project.\n"
"Home page: <http://www.niotso.org/>");
return 0;
}
if(argc >= 4 && !strcmp(argv[1], "-t")){
if(!stricmp(argv[2], "anim")) type = 0;
else if(!stricmp(argv[2], "apr")) type = 1;
else if(!stricmp(argv[2], "bnd")) type = 2;
else if(!stricmp(argv[2], "col")) type = 3;
else if(!stricmp(argv[2], "hag")) type = 4;
else if(!stricmp(argv[2], "mesh")) type = 5;
else if(!stricmp(argv[2], "oft")) type = 6;
else if(!stricmp(argv[2], "po")) type = 7;
else if(!stricmp(argv[2], "skel")) type = 8;
else{
printf("%sUnrecognized type '%s'", "vbparse: Error: ", argv[2]);
return -1;
}
InFile = argv[3];
}else{
char * pos = strrchr(argv[1], '.') + 1;
if(!stricmp(pos, "anim")) type = 0;
else if(!stricmp(pos, "apr")) type = 1;
else if(!stricmp(pos, "bnd")) type = 2;
else if(!stricmp(pos, "col")) type = 3;
else if(!stricmp(pos, "hag")) type = 4;
else if(!stricmp(pos, "mesh")) type = 5;
else if(!stricmp(pos, "oft")) type = 6;
else if(!stricmp(pos, "po")) type = 7;
else if(!stricmp(pos, "skel")) type = 8;
else{
printf("%sUnrecognized type", "vbparse: Error: ");
return -1;
}
InFile = argv[1];
}
HANDLE ProcessHeap = GetProcessHeap();
HANDLE hFile;
unsigned FileSize;
uint8_t *InData;
DWORD bytestransferred;
hFile = CreateFile(InFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(hFile == INVALID_HANDLE_VALUE){
if(GetLastError() == ERROR_FILE_NOT_FOUND){
printf("%sThe specified input file does not exist.", "vbparse: Error: ");
return -1;
}
printf("%sThe input file could not be opened for reading.", "vbparse: Error: ");
return -1;
}
FileSize = GetFileSize(hFile, NULL);
InData = (uint8_t*) HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, FileSize);
if(InData == NULL){
printf("%sMemory for this file could not be allocated.", "vbparse: Error: ");
return -1;
}
if(!ReadFile(hFile, InData, FileSize, &bytestransferred, NULL) || bytestransferred != FileSize){
printf("%sThe input file could not be read.", "vbparse: Error: ");
return -1;
}
CloseHandle(hFile);
VBFile.set(InData, FileSize);
if(type == VBFILE_ANIM){
Animation_t Animation;
ReadAnimation(Animation);
}
return 0;
/*
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <FileHandler.hpp>
#include "libvitaboy.hpp"
enum VBFileType {
VBFILE_ANIM,
VBFILE_APR,
VBFILE_BND,
VBFILE_COL,
VBFILE_HAG,
VBFILE_MESH,
VBFILE_OFT,
VBFILE_PO,
VBFILE_SKEL
};
int main(int argc, char *argv[]){
int type;
char * InFile;
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
printf("Usage: vbparse [-t type] infile\n"
"Parse a TSO VitaBoy file.\n"
"\n"
"Supported types:\n"
" (*) ANIM - Animation\n"
" (*) APR - Appearance\n"
" (*) BND - Binding\n"
" (*) COL - Collection\n"
" (*) HAG - Hand group\n"
" (*) MESH - Mesh\n"
" (*) OFT - Outfit\n"
" (*) PO - Purchasable object\n"
" (*) SKEL - Skeleton\n"
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"
"vbparse is maintained by the Niotso project.\n"
"Home page: <http://www.niotso.org/>");
return 0;
}
if(argc >= 4 && !strcmp(argv[1], "-t")){
if(!stricmp(argv[2], "anim")) type = 0;
else if(!stricmp(argv[2], "apr")) type = 1;
else if(!stricmp(argv[2], "bnd")) type = 2;
else if(!stricmp(argv[2], "col")) type = 3;
else if(!stricmp(argv[2], "hag")) type = 4;
else if(!stricmp(argv[2], "mesh")) type = 5;
else if(!stricmp(argv[2], "oft")) type = 6;
else if(!stricmp(argv[2], "po")) type = 7;
else if(!stricmp(argv[2], "skel")) type = 8;
else{
printf("%sUnrecognized type '%s'", "vbparse: Error: ", argv[2]);
return -1;
}
InFile = argv[3];
}else{
char * pos = strrchr(argv[1], '.') + 1;
if(!stricmp(pos, "anim")) type = 0;
else if(!stricmp(pos, "apr")) type = 1;
else if(!stricmp(pos, "bnd")) type = 2;
else if(!stricmp(pos, "col")) type = 3;
else if(!stricmp(pos, "hag")) type = 4;
else if(!stricmp(pos, "mesh")) type = 5;
else if(!stricmp(pos, "oft")) type = 6;
else if(!stricmp(pos, "po")) type = 7;
else if(!stricmp(pos, "skel")) type = 8;
else{
printf("%sUnrecognized type", "vbparse: Error: ");
return -1;
}
InFile = argv[1];
}
uint8_t *InData = File::ReadFile(InFile);
if(InData == NULL){
const char * Message;
switch(File::Error){
case FERR_NOT_FOUND:
Message = "%s does not exist.";
break;
case FERR_OPEN:
Message = "%s could not be opened for reading.";
break;
case FERR_BLANK:
Message = "%s is corrupt or invalid.";
break;
case FERR_MEMORY:
Message = "Memory for %s could not be allocated.";
break;
default:
Message = "%s could not be read.";
break;
}
printf(Message, InFile);
return -1;
}
VBFile.set(InData, File::FileSize);
switch(type){
case VBFILE_ANIM:
Animation_t Animation;
ReadAnimation(Animation);
break;
case VBFILE_APR:
Appearance_t Appearance;
ReadAppearance(Appearance);
break;
case VBFILE_BND:
Binding_t Binding;
ReadBinding(Binding);
break;
case VBFILE_COL:
Collection_t Collection;
ReadCollection(Collection);
break;
case VBFILE_HAG:
HandGroup_t HandGroup;
ReadHandGroup(HandGroup);
break;
case VBFILE_MESH:
Mesh_t Mesh;
ReadMesh(Mesh);
break;
case VBFILE_OFT:
Outfit_t Outfit;
ReadOutfit(Outfit);
break;
case VBFILE_PO:
PurchasableOutfit_t PurchasableOutfit;
ReadPurchasableOutfit(PurchasableOutfit);
break;
case VBFILE_SKEL:
Skeleton_t Skeleton;
ReadSkeleton(Skeleton);
}
return 0;
}

16
Server/NiotsoServer.cpp Normal file
View file

@ -0,0 +1,16 @@
/*
Niotso Server - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/