Various library changes

This commit is contained in:
Fatbag 2012-02-04 01:19:52 -06:00
parent 74169b403b
commit aa9ef65d64
12 changed files with 463 additions and 47 deletions

View file

View file

@ -1,3 +0,0 @@
ifdef niotso_buildsys
niotso_exes += TSO$(EXE)
endif

View file

@ -0,0 +1,146 @@
#include "libvitaboy.hpp"
static unsigned motionnumber = 0;
void ReadAnimation(Animation_t& Animation){
printf("===== Animation =====\n");
Animation.Version = VBFile.readint32();
printf("Version: %u\n", Animation.Version);
Animation.Name = VBFile.readstring2();
printf("Name: %s\n", Animation.Name);
Animation.Duration = VBFile.readfloat();
printf("Duration: %g\n", Animation.Duration/1000);
Animation.Distance = VBFile.readfloat();
printf("Distance: %g\n", Animation.Distance);
Animation.IsMoving = VBFile.readint8();
printf("IsMoving: %u\n", Animation.IsMoving);
Animation.TranslationsCount = VBFile.readint32();
printf("TranslationsCount: %u\n", Animation.TranslationsCount);
Animation.TranslationsOffset = VBFile.getpos();
VBFile.seekto(Animation.TranslationsOffset + 12*Animation.TranslationsCount);
Animation.RotationsCount = VBFile.readint32();
printf("RotationsCount: %u\n", Animation.RotationsCount);
Animation.RotationsOffset = VBFile.getpos();
VBFile.seekto(Animation.RotationsOffset + 16*Animation.RotationsCount);
Animation.MotionsCount = VBFile.readint32();
printf("MotionsCount: %u\n", Animation.MotionsCount);
Animation.Motions = (Motion_t*) malloc(Animation.MotionsCount * sizeof(Motion_t));
for(unsigned i=0; i<Animation.MotionsCount; i++){
ReadMotion(Animation, Animation.Motions[i]);
}
}
void ReadMotion(Animation_t& Animation, Motion_t& Motion){
motionnumber++;
printf("\n\n [Motion %u]\n", motionnumber);
Motion.Unknown = VBFile.readint32();
printf(" | Unknown: %u\n", Motion.Unknown);
Motion.BoneName = VBFile.readstring();
printf(" | BoneName: %s\n", Motion.BoneName);
Motion.FrameCount = VBFile.readint32();
printf(" | FrameCount: %u\n", Motion.FrameCount);
Motion.Duration = VBFile.readfloat();
printf(" | Duration: %g\n", Motion.Duration/1000);
Motion.HasTranslation = VBFile.readint8();
printf(" | HasTranslation: %u\n", Motion.HasTranslation);
Motion.HasRotation = VBFile.readint8();
printf(" | HasRotation: %u\n", Motion.HasRotation);
Motion.TranslationsOffset = VBFile.readint32();
if(Motion.HasTranslation)
printf(" | TranslationsOffset: %u\n", Motion.TranslationsOffset);
Motion.RotationsOffset = VBFile.readint32();
if(Motion.HasRotation)
printf(" | RotationsOffset: %u\n", Motion.RotationsOffset);
if(Motion.HasTranslation){
Motion.Translations = (Translation_t*) malloc(Motion.FrameCount * sizeof(Translation_t));
unsigned pos = VBFile.getpos();
VBFile.seekto(Animation.TranslationsOffset + 12*Motion.TranslationsOffset);
for(unsigned i=0; i<Motion.FrameCount; i++){
Motion.Translations[i].x = VBFile.readfloat();
Motion.Translations[i].y = VBFile.readfloat();
Motion.Translations[i].z = VBFile.readfloat();
}
VBFile.seekto(pos);
}
if(Motion.HasRotation){
Motion.Rotations = (Rotation_t*) malloc(Motion.FrameCount * sizeof(Rotation_t));
unsigned pos = VBFile.getpos();
VBFile.seekto(Animation.RotationsOffset + 16*Motion.RotationsOffset);
for(unsigned i=0; i<Motion.FrameCount; i++){
Motion.Rotations[i].w = VBFile.readfloat();
Motion.Rotations[i].x = VBFile.readfloat();
Motion.Rotations[i].y = VBFile.readfloat();
Motion.Rotations[i].z = VBFile.readfloat();
}
VBFile.seekto(pos);
}
Motion.HasPropsLists = VBFile.readint8();
printf(" | HasPropsLists: %u\n", Motion.HasPropsLists);
if(Motion.HasPropsLists){
ReadPropsLists(Motion);
}
Motion.HasTimePropsLists = VBFile.readint8();
printf(" | HasTimePropsLists: %u\n", Motion.HasTimePropsLists);
if(Motion.HasTimePropsLists){
ReadTimePropsLists(Motion);
}
}
void ReadPropsList(PropsList_t& PropsList){
unsigned count = PropsList.PropsCount = VBFile.readint32();
printf(" | | | PropsCount: %u\n", count);
PropsList.Props = (Prop_t*) malloc(count * sizeof(Prop_t));
for(unsigned i=0; i<count; i++){
printf(" | | | [Prop %u]\n", i+1);
PropsList.Props[i].Property = VBFile.readint32();
printf(" | | | | Property: %u\n", PropsList.Props[i].Property);
PropsList.Props[i].Key = VBFile.readstring();
printf(" | | | | Key: %s\n", PropsList.Props[i].Key);
PropsList.Props[i].Value = VBFile.readstring();
printf(" | | | | Value: %s\n", PropsList.Props[i].Value);
}
}
void ReadPropsLists(Motion_t& Motion){
unsigned count = Motion.PropsListsCount = VBFile.readint32();
Motion.PropsLists = (PropsList_t*) malloc(count * sizeof(PropsList_t));
for(unsigned i=0; i<count; i++){
ReadPropsList(Motion.PropsLists[i]);
}
}
void ReadTimePropsList(TimePropsList_t& TimePropsList){
unsigned count = TimePropsList.TimePropsCount = VBFile.readint32();
printf(" | | TimePropsCount: %u\n", count);
TimePropsList.TimeProps = (TimeProp_t*) malloc(count * sizeof(TimeProp_t));
for(unsigned i=0; i<count; i++){
printf(" | | [TimeProp %u]\n", i+1);
TimePropsList.TimeProps[i].ID = VBFile.readint32();
printf(" | | | ID: %u\n", TimePropsList.TimeProps[i].ID);
ReadPropsList(TimePropsList.TimeProps[i].PropsList);
}
}
void ReadTimePropsLists(Motion_t& Motion){
unsigned count = Motion.TimePropsListsCount = VBFile.readint32();
printf(" | TimePropsListsCount: %u\n", count);
Motion.TimePropsLists = (TimePropsList_t*) malloc(count * sizeof(TimePropsList_t));
for(unsigned i=0; i<count; i++){
printf(" | [TimePropsList %u]\n", i+1);
ReadTimePropsList(Motion.TimePropsLists[i]);
}
}

View file

@ -0,0 +1,12 @@
/* config.h - libvitaboy build configuration */
/* Name of package */
#define PACKAGE "libvitaboy"
/* Version number of package */
#define VERSION_A 0
#define VERSION_B 0
#define VERSION_C 1
#define VERSION_STR "0.0.1"
/* You should fill the revision in if you're compiling from the trunk */
#define REVISION 0

View file

@ -0,0 +1,3 @@
#include "libvitaboy.hpp"
VBFile_t VBFile;

View file

@ -0,0 +1,150 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <memory.h>
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;
memcpy(&value, Position, 4);
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();
char *string = (char*) malloc((length+1) * sizeof(char));
readbytes(string, length);
string[length] = '\0';
return string;
}
inline char* readstring2(){
//Read a Pascal string with 2 length bytes
unsigned length = readint16();
char *string = (char*) malloc((length+1) * sizeof(char));
readbytes(string, length);
string[length] = '\0';
return string;
}
};
extern VBFile_t VBFile;
struct Translation_t {
float x, y, z;
};
struct Rotation_t {
float w, x, y, z;
};
struct Prop_t {
uint32_t Property;
char * Key;
char * Value;
};
struct PropsList_t {
uint32_t PropsCount;
Prop_t * Props;
};
struct TimeProp_t {
uint32_t ID;
PropsList_t PropsList;
};
struct TimePropsList_t {
uint32_t TimePropsCount;
TimeProp_t * TimeProps;
};
struct Motion_t {
uint32_t Unknown;
char * BoneName;
uint32_t FrameCount;
float Duration;
uint8_t HasTranslation;
uint8_t HasRotation;
uint32_t TranslationsOffset;
uint32_t RotationsOffset;
Translation_t * Translations;
Rotation_t * Rotations;
uint8_t HasPropsLists;
uint32_t PropsListsCount;
PropsList_t * PropsLists;
uint8_t HasTimePropsLists;
uint32_t TimePropsListsCount;
TimePropsList_t * TimePropsLists;
};
struct Animation_t {
uint32_t Version;
char * Name;
float Duration;
float Distance;
uint8_t IsMoving;
uint32_t TranslationsCount;
uint32_t RotationsCount;
uint32_t MotionsCount;
unsigned TranslationsOffset;
unsigned RotationsOffset;
Motion_t * Motions;
};
void ReadAnimation(Animation_t& Animation);
void ReadMotion(Animation_t& Animation, Motion_t& Motion);
void ReadPropsList(PropsList_t& PropsList);
void ReadPropsLists(Motion_t& Motion);
void ReadTimePropsList(TimePropsList_t& TimePropsList);
void ReadTimePropsLists(Motion_t& Motion);

View file

@ -0,0 +1,27 @@
#include "config.h"
1 VERSIONINFO
FILEVERSION VERSION_A,VERSION_B,VERSION_C,REVISION
PRODUCTVERSION VERSION_A,VERSION_B,VERSION_C,REVISION
FILEOS 0x00040000L /* VOS_NT - 32-bit Windows */
FILETYPE 2 /* DLL */
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Niotso project"
VALUE "FileDescription", "Free, open source C++ OpenGL TSO character rendering and animation library"
VALUE "FileVersion", VERSION_STR
VALUE "InternalName", PACKAGE
VALUE "LegalCopyright", "Copyright © 2012"
VALUE "OriginalFilename", PACKAGE".dll"
VALUE "ProductName", PACKAGE
VALUE "ProductVersion", VERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END

View file

@ -0,0 +1,125 @@
/*
vbparse.cpp - 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;
}

View file

View file

@ -1,44 +0,0 @@
# macros --------------------------------------------------------------------
CC = gcc
LD = gcc
CFLAGS = -m32 -Os -march=i686 -fomit-frame-pointer -ffast-math -funsafe-loop-optimizations -fmerge-all-constants -g0 -fno-exceptions
LDFLAGS = -m32 -s -fwhole-program
WINDRES = windres -F pe-i386
LIBS = -mwindows -lole32 -luxtheme -L. -lpng15
OBJS = obj/windows/common.o \
obj/windows/Startup.o \
obj/windows/Interaction.o \
obj/windows/MainWindow.o \
obj/windows/ReadPNGIcon.o \
obj/windows/Dialog/AddToArchive.o \
obj/windows/Dialog/NewArchive.o \
obj/windows/resource.o
# These will rebuild the entire program upon edit.
DEPS = Makefile \
FARDive.hpp \
version.hpp \
windows/GUI.hpp \
windows/resource.hpp \
windows/Windows.hpp
# dependencies --------------------------------------------------------------
all: ./FARDive.exe
./FARDive.exe: $(OBJS)
$(LD) $(LDFLAGS) -L. -o $@ $(OBJS) $(LIBS)
$(OBJS): $(DEPS)
# make rules ----------------------------------------------------------------
./obj/%.o: %.cpp
$(CC) -c $(CFLAGS) -o $@ $<
./obj/%.o: %.rc
$(WINDRES) -i $< -o $@
# maintenance ---------------------------------------------------------------
clean:
del /Q /S FARDive.exe obj