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(libexpat)
add_subdirectory(libfar) add_subdirectory(libfar)
add_subdirectory(libjpeg-turbo)
add_subdirectory(libpng) add_subdirectory(libpng)
add_subdirectory(utk) add_subdirectory(utk)
add_subdirectory(xa) add_subdirectory(xa)
@ -14,6 +15,7 @@ set(FILEHANDLER_MINOR 0)
set(FILEHANDLER_SOURCES set(FILEHANDLER_SOURCES
File.cpp File.cpp
Image.cpp
) )
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler) include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
@ -32,4 +34,4 @@ set_target_properties(FileHandler_shared PROPERTIES
PREFIX "" PREFIX ""
IMPORT_PREFIX "" IMPORT_PREFIX ""
CLEAN_DIRECT_OUTPUT 1) 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 Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above 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. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stdint.h>
#include <windows.h>
#include "FileHandler.hpp" #include "FileHandler.hpp"
namespace File { namespace File {
@ -23,20 +21,27 @@ namespace File {
int Error = 0; int Error = 0;
unsigned FileSize = 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){ uint8_t * ReadFile(const char * Filename){
HANDLE hFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); HANDLE hFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(hFile == INVALID_HANDLE_VALUE){ if(hFile == INVALID_HANDLE_VALUE){
File::Error = (GetLastError() == ERROR_FILE_NOT_FOUND) ? FERR_NOT_FOUND : FERR_OPEN; File::Error = (GetLastError() == ERROR_FILE_NOT_FOUND) ? FERR_NOT_FOUND : FERR_OPEN;
return NULL; return NULL;
} }
FileSize = GetFileSize(hFile, NULL); FileSize = GetFileSize(hFile, NULL);
if(FileSize == 0){ if(FileSize == 0){
CloseHandle(hFile); CloseHandle(hFile);
File::Error = FERR_BLANK; File::Error = FERR_BLANK;
return NULL; return NULL;
} }
uint8_t * InData = (uint8_t*) malloc(FileSize); uint8_t * InData = (uint8_t*) malloc(FileSize);
if(InData == NULL){ if(InData == NULL){
CloseHandle(hFile); CloseHandle(hFile);
@ -47,7 +52,7 @@ uint8_t * ReadFile(const char * Filename){
DWORD bytestransferred; DWORD bytestransferred;
BOOL result = ::ReadFile(hFile, InData, FileSize, &bytestransferred, NULL); BOOL result = ::ReadFile(hFile, InData, FileSize, &bytestransferred, NULL);
CloseHandle(hFile); CloseHandle(hFile);
if(!result || bytestransferred != FileSize){ if(!result || bytestransferred != FileSize){
free(InData); free(InData);
File::Error = FERR_READ; File::Error = FERR_READ;

View file

@ -14,19 +14,51 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 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 { enum FErr {
FERR_NOT_FOUND, FERR_NOT_FOUND,
FERR_OPEN, FERR_OPEN,
FERR_BLANK, FERR_BLANK,
FERR_MEMORY, 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 { namespace File {
extern int Error; extern int Error;
extern unsigned FileSize; extern size_t FileSize;
uint8_t * ReadFile(const char * Filename); 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 set(LIBVITABOY_SOURCES
anim.cpp anim.cpp
apr.cpp
bnd.cpp
col.cpp
hag.cpp
libvitaboy.cpp libvitaboy.cpp
mesh.cpp mesh.cpp
oft.cpp
po.cpp
skel.cpp skel.cpp
) )
if(WIN32) if(WIN32)
@ -33,7 +39,7 @@ set_target_properties(libvitaboy_shared PROPERTIES
CLEAN_DIRECT_OUTPUT 1) CLEAN_DIRECT_OUTPUT 1)
add_executable(vbparse vbparse.cpp) add_executable(vbparse vbparse.cpp)
target_link_libraries(vbparse libvitaboy_static) target_link_libraries(vbparse libvitaboy_static FileHandler_shared)
add_executable(Renderer Renderer.cpp) 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 F11: Enter/leave fullscreen
*/ */
#include <windows.h>
#include <math.h> #include <math.h>
#include <gl\gl.h> #include <gl\gl.h>
#include <gl\glu.h> #include <gl\glu.h>
#include <gl\glext.h> #include <gl\glext.h>
#include <FileHandler.hpp> #include <FileHandler.hpp>
#include "SOIL.h"
#include "libvitaboy.hpp" #include "libvitaboy.hpp"
HDC hDC=NULL; HDC hDC=NULL;
@ -72,7 +70,7 @@ CharacterPlacement_t Character = {{0,-3,0}, {0,0,0}};
Skeleton_t Skeleton; Skeleton_t Skeleton;
const unsigned TextureCount = 3; const unsigned TextureCount = 3;
GLuint texture[3]; unsigned texture[3];
enum { Texture_Body, Texture_Head, Texture_Hand }; enum { Texture_Body, Texture_Head, Texture_Hand };
const char* const TexturePaths[] = {"body.jpg", "head.jpg", "hand.jpg"}; const char* const TexturePaths[] = {"body.jpg", "head.jpg", "hand.jpg"};
@ -94,14 +92,47 @@ float FramePeriod;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 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++){ for(int i=0; i<3; i++){
texture[i] = SOIL_load_OGL_texture(TexturePaths[i], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0); Image_t * Image = File::ReadImageFile(TexturePaths[i]);
if(texture[i] == 0) if(!Image){
DisplayFileError(TexturePaths[i]);
return false; return false;
}
glBindTexture(GL_TEXTURE_2D, texture[i]); 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_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -126,9 +157,9 @@ void ResizeScene(GLsizei width, GLsizei height)
glLoadIdentity(); glLoadIdentity();
} }
int InitGL() bool InitGL()
{ {
if(!LoadGLTextures()) if(!LoadTextures())
return false; return false;
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@ -170,7 +201,7 @@ void TransformVertices(Bone_t& Bone)
unsigned VertexIndex = Mesh.BoneBindings[BoneIndex].FirstFixedVertex + i; unsigned VertexIndex = Mesh.BoneBindings[BoneIndex].FirstFixedVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex]; Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex]; Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z); glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z);
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix); glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
AbsoluteVertex.x = Matrix[12]; AbsoluteVertex.x = Matrix[12];
@ -182,7 +213,7 @@ void TransformVertices(Bone_t& Bone)
unsigned VertexIndex = Mesh.FixedVertexCount + Mesh.BoneBindings[BoneIndex].FirstBlendedVertex + i; unsigned VertexIndex = Mesh.FixedVertexCount + Mesh.BoneBindings[BoneIndex].FirstBlendedVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex]; Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex]; Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z); glTranslatef(RelativeVertex.x, RelativeVertex.y, RelativeVertex.z);
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix); glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
AbsoluteVertex.x = Matrix[12]; AbsoluteVertex.x = Matrix[12];
@ -240,8 +271,10 @@ void DrawMeshes()
for(unsigned i=0; i<MeshCount; i++){ for(unsigned i=0; i<MeshCount; i++){
glBindTexture(GL_TEXTURE_2D, texture[Mesh_UseTexture[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); glVertexPointer(3, GL_FLOAT, offsetof(Vertex_t, y)-offsetof(Vertex_t, x)-sizeof(float),
glTexCoordPointer(2, GL_FLOAT, offsetof(TextureVertex_t, v)-offsetof(TextureVertex_t, u)-sizeof(float), Meshes[i].TransformedTextureData); 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); 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; float Duration = (float)Animation.Motions[0].FrameCount/30;
AnimationTime += TimeDelta; AnimationTime += TimeDelta;
while(AnimationTime >= Duration) AnimationTime -= Duration; 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++){ for(unsigned i=0; i<Animation.MotionsCount; i++){
unsigned BoneIndex = FindBone(Skeleton, Animation.Motions[i].BoneName, Skeleton.BoneCount); 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); MessageBox(NULL, "Failed to registrer the window class.", NULL, MB_OK | MB_ICONERROR);
return false; return false;
} }
DWORD dwStyle, dwExStyle; DWORD dwStyle, dwExStyle;
if(fullscreen){ if(fullscreen){
@ -598,7 +631,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0); PostQuitMessage(0);
} return 0; } return 0;
} }
return DefWindowProc(hWnd, uMsg, wParam, lParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);
} }
@ -609,35 +642,14 @@ bool Read(const char * Filename, uint8_t ** InData){
return true; return true;
} }
const char * Message; DisplayFileError(Filename);
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);
return false; return false;
} }
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int) int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{ {
uint8_t * InData; uint8_t * InData;
if(!Read("skeleton.skel", &InData)) if(!Read("skeleton.skel", &InData))
return 0; return 0;
ReadSkeleton(Skeleton); ReadSkeleton(Skeleton);
@ -649,7 +661,7 @@ int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
ReadMesh(Meshes[i]); ReadMesh(Meshes[i]);
free(InData); free(InData);
} }
if(!Read("animation.anim", &InData)) if(!Read("animation.anim", &InData))
return 0; return 0;
ReadAnimation(Animation); 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; 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){ void ReadPropEntry(KeyValuePair_t& Entry){
Entry.Key = VBFile.readstring(); Entry.Key = VBFile.readstring();
printf(" | | | | | Key: %s\n", Entry.Key); printf(" | | | | | Key: %s\n", Entry.Key);
@ -29,7 +38,7 @@ void ReadPropEntries(Prop_t& Prop){
unsigned count = Prop.EntriesCount = VBFile.readint32(); unsigned count = Prop.EntriesCount = VBFile.readint32();
printf(" | | | | EntriesCount: %u\n", Prop.EntriesCount); printf(" | | | | EntriesCount: %u\n", Prop.EntriesCount);
Prop.Entries = (KeyValuePair_t*) malloc(count * sizeof(KeyValuePair_t)); Prop.Entries = (KeyValuePair_t*) malloc(count * sizeof(KeyValuePair_t));
for(unsigned i=0; i<count; i++){ for(unsigned i=0; i<count; i++){
printf(" | | | | [Entry %u]\n", i+1); printf(" | | | | [Entry %u]\n", i+1);
ReadPropEntry(Prop.Entries[i]); ReadPropEntry(Prop.Entries[i]);

View file

@ -14,50 +14,54 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifndef LIBVITABOY_HPP
#define LIBVITABOY_HPP
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
#include <FileHandler.hpp>
class VBFile_t { class VBFile_t {
private: private:
const uint8_t *Buffer, *Position; const uint8_t *Buffer, *Position;
unsigned Size; unsigned Size;
public: public:
inline void set(const void *_Buffer, unsigned _Size){ inline void set(const void *_Buffer, unsigned _Size){
Buffer = (const uint8_t*) _Buffer; Buffer = (const uint8_t*) _Buffer;
Position = (const uint8_t*) _Buffer; Position = (const uint8_t*) _Buffer;
Size = _Size; Size = _Size;
} }
inline unsigned getpos(){ inline unsigned getpos(){
return Position-Buffer; return Position-Buffer;
} }
inline void seekto(unsigned offset){ inline void seekto(unsigned offset){
Position = Buffer+offset; Position = Buffer+offset;
} }
inline uint32_t readint32(){ 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))); uint32_t value = (uint32_t)((Position[0]<<(8*3)) | (Position[1]<<(8*2)) | (Position[2]<<(8*1)) | (Position[3]<<(8*0)));
Position += 4; Position += 4;
return value; return value;
} }
inline uint32_t readint16(){ inline uint32_t readint16(){
uint16_t value = (uint16_t)((Position[0]<<(8*1)) | (Position[1]<<(8*0))); uint16_t value = (uint16_t)((Position[0]<<(8*1)) | (Position[1]<<(8*0)));
Position += 2; Position += 2;
return value; return value;
} }
inline uint32_t readint8(){ inline uint32_t readint8(){
uint8_t value = (uint8_t)((Position[0]<<(8*0))); uint8_t value = (uint8_t)((Position[0]<<(8*0)));
Position += 1; Position += 1;
return value; return value;
} }
inline float readfloat(){ inline float readfloat(){
//Obviously a platform-dependent implementation //Obviously a platform-dependent implementation
float value; float value;
@ -65,12 +69,12 @@ class VBFile_t {
Position += 4; Position += 4;
return value; return value;
} }
inline void readbytes(void* Destination, unsigned length){ inline void readbytes(void* Destination, unsigned length){
memcpy(Destination, Position, length); memcpy(Destination, Position, length);
Position += length; Position += length;
} }
inline char* readstring(){ inline char* readstring(){
//Read a Pascal string with 1 length byte //Read a Pascal string with 1 length byte
unsigned length = readint8(); unsigned length = readint8();
@ -79,7 +83,7 @@ class VBFile_t {
string[length] = '\0'; string[length] = '\0';
return string; return string;
} }
inline char* readstring2(){ inline char* readstring2(){
//Read a Pascal string with 2 length bytes //Read a Pascal string with 2 length bytes
unsigned length = readint16(); unsigned length = readint16();
@ -96,6 +100,11 @@ extern VBFile_t VBFile;
** Common ** Common
*/ */
enum ReadGroup {
NOGROUP,
READGROUP
};
struct Translation_t { struct Translation_t {
float x, y, z; float x, y, z;
}; };
@ -119,6 +128,7 @@ struct PropsList_t {
Prop_t * Props; Prop_t * Props;
}; };
void ReadAsset(Asset_t& Asset, bool ReadGroup);
void ReadPropEntry(KeyValuePair_t& Entry); void ReadPropEntry(KeyValuePair_t& Entry);
void ReadPropEntries(Prop_t& Prop); void ReadPropEntries(Prop_t& Prop);
void ReadPropsList(PropsList_t& PropsList); void ReadPropsList(PropsList_t& PropsList);
@ -145,7 +155,7 @@ struct Motion_t {
uint32_t Unknown; uint32_t Unknown;
char * BoneName; char * BoneName;
uint32_t FrameCount; uint32_t FrameCount;
float Duration; float Duration; //Converted to seconds
uint8_t HasTranslation; uint8_t HasTranslation;
uint8_t HasRotation; uint8_t HasRotation;
uint32_t FirstTranslation; uint32_t FirstTranslation;
@ -165,7 +175,7 @@ struct Motion_t {
struct Animation_t { struct Animation_t {
uint32_t Version; uint32_t Version;
char * Name; char * Name;
float Duration; float Duration; //Converted to seconds
float Distance; float Distance;
uint8_t IsMoving; uint8_t IsMoving;
uint32_t TranslationsCount; uint32_t TranslationsCount;
@ -185,6 +195,64 @@ void ReadTimePropsList(TimePropsList_t& TimePropsList);
void ReadTimePropsLists(Motion_t& Motion); 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) ** Mesh (*.mesh)
*/ */
@ -237,6 +305,48 @@ struct Mesh_t {
void ReadMesh(Mesh_t& Mesh); 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) ** Skeleton (*.skel)
*/ */
@ -254,7 +364,7 @@ struct Bone_t {
uint32_t CanBlend; uint32_t CanBlend;
float WiggleValue; float WiggleValue;
float WigglePower; float WigglePower;
unsigned ChildrenCount; unsigned ChildrenCount;
Bone_t ** Children; Bone_t ** Children;
}; };
@ -268,4 +378,6 @@ struct Skeleton_t {
void ReadSkeleton(Skeleton_t& Bone); void ReadSkeleton(Skeleton_t& Bone);
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index); 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"); printf("\n========== Mesh ==========\n");
Mesh.Version = VBFile.readint32(); Mesh.Version = VBFile.readint32();
printf("Version: %u\n", Mesh.Version); printf("Version: %u\n", Mesh.Version);
Mesh.BoneCount = VBFile.readint32(); Mesh.BoneCount = VBFile.readint32();
printf("BoneCount: %u\n", Mesh.BoneCount); printf("BoneCount: %u\n", Mesh.BoneCount);
Mesh.BoneNames = (char**) malloc(Mesh.BoneCount * sizeof(char*)); Mesh.BoneNames = (char**) malloc(Mesh.BoneCount * sizeof(char*));
@ -28,7 +28,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.BoneNames[i] = VBFile.readstring(); Mesh.BoneNames[i] = VBFile.readstring();
printf("| Bone %u: %s\n", i+1, Mesh.BoneNames[i]); printf("| Bone %u: %s\n", i+1, Mesh.BoneNames[i]);
} }
Mesh.FaceCount = VBFile.readint32(); Mesh.FaceCount = VBFile.readint32();
printf("FaceCount: %u\n", Mesh.FaceCount); printf("FaceCount: %u\n", Mesh.FaceCount);
Mesh.FaceData = (Face_t*) malloc(Mesh.FaceCount * sizeof(Face_t)); 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].VertexB = VBFile.readint32();
Mesh.FaceData[i].VertexC = VBFile.readint32(); Mesh.FaceData[i].VertexC = VBFile.readint32();
} }
Mesh.BindingCount = VBFile.readint32(); Mesh.BindingCount = VBFile.readint32();
Mesh.BoneBindings = (BoneBinding_t*) malloc(Mesh.BindingCount * sizeof(BoneBinding_t)); Mesh.BoneBindings = (BoneBinding_t*) malloc(Mesh.BindingCount * sizeof(BoneBinding_t));
printf("BindingCount: %u\n", Mesh.BindingCount); printf("BindingCount: %u\n", Mesh.BindingCount);
@ -48,7 +48,7 @@ void ReadMesh(Mesh_t& Mesh){
Mesh.BoneBindings[i].FirstBlendedVertex = VBFile.readint32(); Mesh.BoneBindings[i].FirstBlendedVertex = VBFile.readint32();
Mesh.BoneBindings[i].BlendedVertexCount = VBFile.readint32(); Mesh.BoneBindings[i].BlendedVertexCount = VBFile.readint32();
} }
Mesh.FixedVertexCount = VBFile.readint32(); Mesh.FixedVertexCount = VBFile.readint32();
printf("FixedVertexCount: %u\n", Mesh.FixedVertexCount); printf("FixedVertexCount: %u\n", Mesh.FixedVertexCount);
Mesh.TextureVertexData = (TextureVertex_t*) malloc(Mesh.FixedVertexCount * sizeof(TextureVertex_t)); 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].u = VBFile.readfloat();
Mesh.TextureVertexData[i].v = VBFile.readfloat(); Mesh.TextureVertexData[i].v = VBFile.readfloat();
} }
Mesh.BlendedVertexCount = VBFile.readint32(); Mesh.BlendedVertexCount = VBFile.readint32();
printf("BlendedVertexCount: %u\n", Mesh.BlendedVertexCount); printf("BlendedVertexCount: %u\n", Mesh.BlendedVertexCount);
Mesh.BlendData = (BlendData_t*) malloc(Mesh.BlendedVertexCount * sizeof(BlendData_t)); 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].Weight = (float)VBFile.readint32()/0x8000;
Mesh.BlendData[i].OtherVertex = VBFile.readint32(); Mesh.BlendData[i].OtherVertex = VBFile.readint32();
} }
Mesh.TotalVertexCount = VBFile.readint32(); Mesh.TotalVertexCount = VBFile.readint32();
printf("TotalVertexCount: %u\n", Mesh.TotalVertexCount); printf("TotalVertexCount: %u\n", Mesh.TotalVertexCount);
Mesh.VertexData = (Vertex_t*) malloc(Mesh.TotalVertexCount * sizeof(Vertex_t)); 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].x = VBFile.readfloat();
Mesh.VertexNorms[i].y = VBFile.readfloat(); Mesh.VertexNorms[i].y = VBFile.readfloat();
Mesh.VertexNorms[i].z = VBFile.readfloat(); Mesh.VertexNorms[i].z = VBFile.readfloat();
if(i<Mesh.FixedVertexCount){ if(i<Mesh.FixedVertexCount){
//Fixed vertex //Fixed vertex
Mesh.TransformedTextureData[i].u = Mesh.TextureVertexData[i].u; 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> libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies. copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libvitaboy.hpp" #include "libvitaboy.hpp"
static unsigned bonenumber = 0; void ReadSkeleton(Skeleton_t& Skeleton){
printf("\n========== Skeleton ==========\n");
void ReadSkeleton(Skeleton_t& Skeleton){ Skeleton.Version = VBFile.readint32();
printf("\n========== Skeleton ==========\n"); printf("Version: %u\n", Skeleton.Version);
Skeleton.Version = VBFile.readint32(); Skeleton.Name = VBFile.readstring();
printf("Version: %u\n", Skeleton.Version); printf("Name: %s\n", Skeleton.Name);
Skeleton.Name = VBFile.readstring();
printf("Name: %s\n", Skeleton.Name); Skeleton.BoneCount = VBFile.readint16();
printf("BoneCount: %u\n", Skeleton.BoneCount);
Skeleton.BoneCount = VBFile.readint16(); Skeleton.Bones = (Bone_t*) malloc(Skeleton.BoneCount * sizeof(Bone_t));
printf("BoneCount: %u\n", Skeleton.BoneCount); for(unsigned i=0; i<Skeleton.BoneCount; i++){
Skeleton.Bones = (Bone_t*) malloc(Skeleton.BoneCount * sizeof(Bone_t)); printf("\n [Bone %u]\n", i);
for(unsigned i=0; i<Skeleton.BoneCount; i++){ ReadBone(Skeleton, Skeleton.Bones[i], i);
ReadBone(Skeleton, Skeleton.Bones[i], i); }
} }
}
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){
void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){ Bone.Unknown = VBFile.readint32();
bonenumber++; printf(" | Unknown: %u\n", Bone.Unknown);
printf("\n [Bone %u]\n", bonenumber); Bone.Name = VBFile.readstring();
printf(" | Name: %s\n", Bone.Name);
Bone.Unknown = VBFile.readint32(); Bone.ParentsName = VBFile.readstring();
printf(" | Unknown: %u\n", Bone.Unknown); printf(" | Parent's name: %s\n", Bone.ParentsName);
Bone.Name = VBFile.readstring();
printf(" | Name: %s\n", Bone.Name); Bone.HasProps = VBFile.readint8();
Bone.ParentsName = VBFile.readstring(); printf(" | HasProps: %u\n", Bone.HasProps);
printf(" | Parent's name: %s\n", Bone.ParentsName); if(Bone.HasProps){
ReadPropsList(Bone.PropsList);
Bone.HasProps = VBFile.readint8(); }
printf(" | HasProps: %u\n", Bone.HasProps);
if(Bone.HasProps){ printf(" | Translation:\n");
ReadPropsList(Bone.PropsList); Bone.Translation.x = VBFile.readfloat();
} printf(" | | x: %g\n", Bone.Translation.x);
Bone.Translation.y = VBFile.readfloat();
printf(" | Translation:\n"); printf(" | | y: %g\n", Bone.Translation.y);
Bone.Translation.x = VBFile.readfloat(); Bone.Translation.z = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Translation.x); printf(" | | z: %g\n", Bone.Translation.z);
Bone.Translation.y = VBFile.readfloat(); printf(" | Rotation:\n");
printf(" | | y: %g\n", Bone.Translation.y); Bone.Rotation.x = VBFile.readfloat();
Bone.Translation.z = VBFile.readfloat(); printf(" | | x: %g\n", Bone.Rotation.x);
printf(" | | z: %g\n", Bone.Translation.z); Bone.Rotation.y = VBFile.readfloat();
printf(" | Rotation:\n"); printf(" | | y: %g\n", Bone.Rotation.y);
Bone.Rotation.x = VBFile.readfloat(); Bone.Rotation.z = VBFile.readfloat();
printf(" | | x: %g\n", Bone.Rotation.x); printf(" | | z: %g\n", Bone.Rotation.z);
Bone.Rotation.y = VBFile.readfloat(); Bone.Rotation.w = VBFile.readfloat();
printf(" | | y: %g\n", Bone.Rotation.y); printf(" | | w: %g\n", Bone.Rotation.w);
Bone.Rotation.z = VBFile.readfloat();
printf(" | | z: %g\n", Bone.Rotation.z); Bone.CanTranslate = VBFile.readint32();
Bone.Rotation.w = VBFile.readfloat(); printf(" | CanTranslate: %u\n", Bone.CanTranslate);
printf(" | | w: %g\n", Bone.Rotation.w); Bone.CanRotate = VBFile.readint32();
printf(" | CanRotate: %u\n", Bone.CanRotate);
Bone.CanTranslate = VBFile.readint32(); Bone.CanBlend = VBFile.readint32();
printf(" | CanTranslate: %u\n", Bone.CanTranslate); printf(" | CanBlend: %u\n", Bone.CanBlend);
Bone.CanRotate = VBFile.readint32();
printf(" | CanRotate: %u\n", Bone.CanRotate); Bone.WiggleValue = VBFile.readfloat();
Bone.CanBlend = VBFile.readint32(); printf(" | WiggleValue: %g\n", Bone.WiggleValue);
printf(" | CanBlend: %u\n", Bone.CanBlend); Bone.WigglePower = VBFile.readfloat();
printf(" | WigglePower: %g\n", Bone.WigglePower);
Bone.WiggleValue = VBFile.readfloat();
printf(" | WiggleValue: %g\n", Bone.WiggleValue); Bone.ChildrenCount = 0;
Bone.WigglePower = VBFile.readfloat(); Bone.Children = (Bone_t**) malloc((Skeleton.BoneCount-Index-1) * sizeof(Bone_t*));
printf(" | WigglePower: %g\n", Bone.WigglePower);
unsigned Parent = FindBone(Skeleton, Bone.ParentsName, Index);
Bone.ChildrenCount = 0; if(Parent != (unsigned)-1){
Bone.Children = (Bone_t**) malloc((Skeleton.BoneCount-Index-1) * sizeof(Bone_t*)); Bone_t& ParentBone = Skeleton.Bones[Parent];
ParentBone.Children[ParentBone.ChildrenCount] = &Bone;
unsigned Parent = FindBone(Skeleton, Bone.ParentsName, Index); ParentBone.ChildrenCount++;
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;
}
unsigned FindBone(Skeleton_t& Skeleton, const char * BoneName, unsigned Count){
for(unsigned i=0; i<Count; i++){ return (unsigned)-1;
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> libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies. copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <windows.h> #include <stdio.h>
#include "libvitaboy.hpp" #include <FileHandler.hpp>
#include "libvitaboy.hpp"
enum VBFileType {
VBFILE_ANIM, enum VBFileType {
VBFILE_APR, VBFILE_ANIM,
VBFILE_BND, VBFILE_APR,
VBFILE_COL, VBFILE_BND,
VBFILE_HAG, VBFILE_COL,
VBFILE_MESH, VBFILE_HAG,
VBFILE_OFT, VBFILE_MESH,
VBFILE_PO, VBFILE_OFT,
VBFILE_SKEL VBFILE_PO,
}; VBFILE_SKEL
};
int main(int argc, char *argv[]){
int type; int main(int argc, char *argv[]){
char * InFile; int type;
char * InFile;
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
printf("Usage: vbparse [-t type] infile\n" if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
"Parse a TSO VitaBoy file.\n" printf("Usage: vbparse [-t type] infile\n"
"\n" "Parse a TSO VitaBoy file.\n"
"Supported types:\n" "\n"
" (*) ANIM - Animation\n" "Supported types:\n"
" (*) APR - Appearance\n" " (*) ANIM - Animation\n"
" (*) BND - Binding\n" " (*) APR - Appearance\n"
" (*) COL - Collection\n" " (*) BND - Binding\n"
" (*) HAG - Hand group\n" " (*) COL - Collection\n"
" (*) MESH - Mesh\n" " (*) HAG - Hand group\n"
" (*) OFT - Outfit\n" " (*) MESH - Mesh\n"
" (*) PO - Purchasable object\n" " (*) OFT - Outfit\n"
" (*) SKEL - Skeleton\n" " (*) PO - Purchasable object\n"
"\n" " (*) SKEL - Skeleton\n"
"Report bugs to <X-Fi6@phppoll.org>.\n" "\n"
"vbparse is maintained by the Niotso project.\n" "Report bugs to <X-Fi6@phppoll.org>.\n"
"Home page: <http://www.niotso.org/>"); "vbparse is maintained by the Niotso project.\n"
return 0; "Home page: <http://www.niotso.org/>");
} return 0;
}
if(argc >= 4 && !strcmp(argv[1], "-t")){
if(!stricmp(argv[2], "anim")) type = 0; if(argc >= 4 && !strcmp(argv[1], "-t")){
else if(!stricmp(argv[2], "apr")) type = 1; if(!stricmp(argv[2], "anim")) type = 0;
else if(!stricmp(argv[2], "bnd")) type = 2; else if(!stricmp(argv[2], "apr")) type = 1;
else if(!stricmp(argv[2], "col")) type = 3; else if(!stricmp(argv[2], "bnd")) type = 2;
else if(!stricmp(argv[2], "hag")) type = 4; else if(!stricmp(argv[2], "col")) type = 3;
else if(!stricmp(argv[2], "mesh")) type = 5; else if(!stricmp(argv[2], "hag")) type = 4;
else if(!stricmp(argv[2], "oft")) type = 6; else if(!stricmp(argv[2], "mesh")) type = 5;
else if(!stricmp(argv[2], "po")) type = 7; else if(!stricmp(argv[2], "oft")) type = 6;
else if(!stricmp(argv[2], "skel")) type = 8; else if(!stricmp(argv[2], "po")) type = 7;
else{ else if(!stricmp(argv[2], "skel")) type = 8;
printf("%sUnrecognized type '%s'", "vbparse: Error: ", argv[2]); else{
return -1; printf("%sUnrecognized type '%s'", "vbparse: Error: ", argv[2]);
} return -1;
InFile = argv[3]; }
}else{ InFile = argv[3];
char * pos = strrchr(argv[1], '.') + 1; }else{
if(!stricmp(pos, "anim")) type = 0; char * pos = strrchr(argv[1], '.') + 1;
else if(!stricmp(pos, "apr")) type = 1; if(!stricmp(pos, "anim")) type = 0;
else if(!stricmp(pos, "bnd")) type = 2; else if(!stricmp(pos, "apr")) type = 1;
else if(!stricmp(pos, "col")) type = 3; else if(!stricmp(pos, "bnd")) type = 2;
else if(!stricmp(pos, "hag")) type = 4; else if(!stricmp(pos, "col")) type = 3;
else if(!stricmp(pos, "mesh")) type = 5; else if(!stricmp(pos, "hag")) type = 4;
else if(!stricmp(pos, "oft")) type = 6; else if(!stricmp(pos, "mesh")) type = 5;
else if(!stricmp(pos, "po")) type = 7; else if(!stricmp(pos, "oft")) type = 6;
else if(!stricmp(pos, "skel")) type = 8; else if(!stricmp(pos, "po")) type = 7;
else{ else if(!stricmp(pos, "skel")) type = 8;
printf("%sUnrecognized type", "vbparse: Error: "); else{
return -1; printf("%sUnrecognized type", "vbparse: Error: ");
} return -1;
InFile = argv[1]; }
} InFile = argv[1];
}
HANDLE ProcessHeap = GetProcessHeap();
HANDLE hFile; uint8_t *InData = File::ReadFile(InFile);
unsigned FileSize; if(InData == NULL){
uint8_t *InData; const char * Message;
DWORD bytestransferred; switch(File::Error){
case FERR_NOT_FOUND:
hFile = CreateFile(InFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); Message = "%s does not exist.";
if(hFile == INVALID_HANDLE_VALUE){ break;
if(GetLastError() == ERROR_FILE_NOT_FOUND){ case FERR_OPEN:
printf("%sThe specified input file does not exist.", "vbparse: Error: "); Message = "%s could not be opened for reading.";
return -1; break;
} case FERR_BLANK:
printf("%sThe input file could not be opened for reading.", "vbparse: Error: "); Message = "%s is corrupt or invalid.";
return -1; break;
} case FERR_MEMORY:
FileSize = GetFileSize(hFile, NULL); Message = "Memory for %s could not be allocated.";
InData = (uint8_t*) HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, FileSize); break;
if(InData == NULL){ default:
printf("%sMemory for this file could not be allocated.", "vbparse: Error: "); Message = "%s could not be read.";
return -1; break;
} }
if(!ReadFile(hFile, InData, FileSize, &bytestransferred, NULL) || bytestransferred != FileSize){ printf(Message, InFile);
printf("%sThe input file could not be read.", "vbparse: Error: "); return -1;
return -1; }
}
CloseHandle(hFile); VBFile.set(InData, File::FileSize);
VBFile.set(InData, FileSize); switch(type){
case VBFILE_ANIM:
if(type == VBFILE_ANIM){ Animation_t Animation;
Animation_t Animation; ReadAnimation(Animation);
ReadAnimation(Animation); break;
} case VBFILE_APR:
Appearance_t Appearance;
return 0; 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/>.
*/