From bc51bb4aad096aa62e4543b118724afaeb0c2eec Mon Sep 17 00:00:00 2001 From: Fatbag Date: Mon, 21 May 2012 23:27:44 -0500 Subject: [PATCH] * License header formatting change * New IFF chunk formats supported: CST, FBMP, CATS * Rebranded libfar to simply far * Started preliminary work on the hitutils package --- Client/Audio/Audio.hpp | 5 +- Client/Audio/Startup.cpp | 15 +- Client/Client.cpp | 27 +- Client/EngineInterface.hpp | 8 +- Client/Graphics/Font.cpp | 37 +- Client/Graphics/Graphics.hpp | 11 +- Client/Graphics/Startup.cpp | 19 +- Client/Graphics/Viewport.cpp | 5 +- Client/Scene/LoginScreen/LoginScreen.cpp | 23 +- Client/Scene/LoginScreen/LoginScreen.hpp | 7 +- Client/Scene/Scene.hpp | 9 +- Client/System/System.cpp | 11 +- Client/System/System.hpp | 9 +- Client/TODO | 2 +- Client/Window/Window.cpp | 5 +- Client/Window/Window.hpp | 5 +- Libraries/FileHandler/AUTHORS | 2 + Libraries/FileHandler/Audio.cpp | 26 +- Libraries/FileHandler/CMakeLists.txt | 2 +- Libraries/FileHandler/COPYING | 15 + Libraries/FileHandler/File.cpp | 4 +- Libraries/FileHandler/FileHandler.hpp | 4 +- Libraries/FileHandler/Image.cpp | 22 +- Libraries/FileHandler/README | 32 ++ Libraries/FileHandler/bmp/read_bmp.c | 18 +- Libraries/FileHandler/bmp/read_bmp.h | 6 +- Libraries/FileHandler/cst/cst.c | 4 +- Libraries/FileHandler/cst/cst.h | 4 +- Libraries/FileHandler/cur/read_cur.c | 25 +- Libraries/FileHandler/cur/read_cur.h | 25 +- Libraries/FileHandler/far/CMakeLists.txt | 22 + Libraries/FileHandler/far/Makefile | 42 ++ Libraries/FileHandler/far/config.h | 24 + Libraries/FileHandler/far/farextract.c | 287 +++++++++++ Libraries/FileHandler/far/libfar.c | 469 ++++++++++++++++++ Libraries/FileHandler/far/libfar.h | 176 +++++++ Libraries/FileHandler/far/libfar.svg | 200 ++++++++ Libraries/FileHandler/far/refpack_dec.c | 167 +++++++ Libraries/FileHandler/hit/evt.c | 17 + Libraries/FileHandler/hit/hit.c | 17 + Libraries/FileHandler/hit/hot.c | 17 + Libraries/FileHandler/hit/hsm.c | 17 + Libraries/FileHandler/iff/CMakeLists.txt | 4 +- Libraries/FileHandler/iff/bcon.c | 13 +- Libraries/FileHandler/iff/bhav.c | 18 + Libraries/FileHandler/iff/cats.c | 55 ++ .../FileHandler/iff/fcns.c | 0 Libraries/FileHandler/iff/glob.c | 0 Libraries/FileHandler/iff/iff.c | 35 +- Libraries/FileHandler/iff/iff.h | 25 +- Libraries/FileHandler/iff/iffexport.c | 7 +- Libraries/FileHandler/iff/rsmp.c | 4 +- Libraries/FileHandler/iff/str.c | 72 +-- Libraries/FileHandler/iff/string.c | 38 ++ Libraries/FileHandler/iff/tprp.c | 0 Libraries/FileHandler/iff/trcn.c | 117 ++++- Libraries/FileHandler/iff/ttab.c | 0 Libraries/FileHandler/ini/read_ini.c | 17 + Libraries/FileHandler/tga/read_tga.c | 17 + Libraries/FileHandler/tga/read_tga.h | Bin 7291 -> 0 bytes Libraries/FileHandler/uis/uis.c | 4 +- Libraries/FileHandler/uis/uis.h | 4 +- Libraries/FileHandler/utk/CMakeLists.txt | 2 +- Libraries/FileHandler/utk/read_utk.c | 4 +- Libraries/FileHandler/utk/read_utk.h | 4 +- Libraries/FileHandler/utk/utkdecode.c | 6 +- Libraries/FileHandler/wav/read_wav.c | 10 +- Libraries/FileHandler/wav/read_wav.h | 4 +- Libraries/FileHandler/xa/read_xa.c | 39 +- Libraries/FileHandler/xa/read_xa.h | 4 +- Libraries/libvitaboy/COPYING | 4 +- Libraries/libvitaboy/Renderer.cpp | 4 +- Libraries/libvitaboy/anim.cpp | 4 +- Libraries/libvitaboy/apr.cpp | 4 +- Libraries/libvitaboy/bnd.cpp | 4 +- Libraries/libvitaboy/col.cpp | 4 +- Libraries/libvitaboy/libvitaboy.cpp | 4 +- Libraries/libvitaboy/libvitaboy.hpp | 11 +- Libraries/libvitaboy/mesh.cpp | 6 +- Libraries/libvitaboy/oft.cpp | 4 +- Libraries/libvitaboy/po.cpp | 4 +- Libraries/libvitaboy/skel.cpp | 4 +- Libraries/libvitaboy/vbparse.cpp | 4 +- Server/{NiotsoServer.cpp => Server.cpp} | 5 +- Tools/CMakeLists.txt | 4 +- .../TSOSimulatorClient/TSOSimulatorClient.cpp | 4 +- Tools/hitutils/CMakeLists.txt | 18 + Tools/hitutils/hitasm.cpp | 32 ++ Tools/hitutils/hitdump.cpp | 35 ++ Tools/hitutils/hitld.cpp | 35 ++ Tools/iff2html/iff2html.c | 72 ++- Tools/iff2html/iff2html.html | 125 ----- Tools/iff2html/md5.c | 2 +- Tools/iff2html/md5.h | 2 +- Tools/tsoscan/tsoscan.txt | 0 Tools/zbuffer/Instructions.txt | 5 +- 96 files changed, 2321 insertions(+), 424 deletions(-) create mode 100644 Libraries/FileHandler/AUTHORS create mode 100644 Libraries/FileHandler/COPYING create mode 100644 Libraries/FileHandler/README create mode 100644 Libraries/FileHandler/far/CMakeLists.txt create mode 100644 Libraries/FileHandler/far/Makefile create mode 100644 Libraries/FileHandler/far/config.h create mode 100644 Libraries/FileHandler/far/farextract.c create mode 100644 Libraries/FileHandler/far/libfar.c create mode 100644 Libraries/FileHandler/far/libfar.h create mode 100644 Libraries/FileHandler/far/libfar.svg create mode 100644 Libraries/FileHandler/far/refpack_dec.c create mode 100644 Libraries/FileHandler/hit/evt.c create mode 100644 Libraries/FileHandler/hit/hit.c create mode 100644 Libraries/FileHandler/hit/hot.c create mode 100644 Libraries/FileHandler/hit/hsm.c create mode 100644 Libraries/FileHandler/iff/bhav.c create mode 100644 Libraries/FileHandler/iff/cats.c rename Tools/misc/CMakeLists.txt => Libraries/FileHandler/iff/fcns.c (100%) create mode 100644 Libraries/FileHandler/iff/glob.c create mode 100644 Libraries/FileHandler/iff/string.c create mode 100644 Libraries/FileHandler/iff/tprp.c create mode 100644 Libraries/FileHandler/iff/ttab.c delete mode 100644 Libraries/FileHandler/tga/read_tga.h rename Server/{NiotsoServer.cpp => Server.cpp} (79%) create mode 100644 Tools/hitutils/CMakeLists.txt create mode 100644 Tools/hitutils/hitasm.cpp create mode 100644 Tools/hitutils/hitdump.cpp create mode 100644 Tools/hitutils/hitld.cpp delete mode 100644 Tools/iff2html/iff2html.html create mode 100644 Tools/tsoscan/tsoscan.txt diff --git a/Client/Audio/Audio.hpp b/Client/Audio/Audio.hpp index ec97119..78ab719 100644 --- a/Client/Audio/Audio.hpp +++ b/Client/Audio/Audio.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Audio/Audio.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 diff --git a/Client/Audio/Startup.cpp b/Client/Audio/Startup.cpp index 161f2c6..93496b6 100644 --- a/Client/Audio/Startup.cpp +++ b/Client/Audio/Startup.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Audio/Startup.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -24,7 +27,7 @@ IXAudio2MasteringVoice *MasterVoice = NULL; int Initialize(){ HRESULT result; - + result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE | COINIT_SPEED_OVER_MEMORY); if(result != S_OK){ MessageBox(Window::hWnd, "Failed to initialize Microsoft COM.", NULL, MB_OK | MB_ICONERROR); @@ -39,7 +42,7 @@ int Initialize(){ Shutdown(); return ERROR_AUDIO_INIT_XAUDIO2; } - + result = pXAudio2->CreateMasteringVoice(&MasterVoice, 2, 44100, 0, 0, NULL); if(result != S_OK){ MessageBox(Window::hWnd, "Failed to create the mastering voice for XAudio2.", NULL, MB_OK | MB_ICONERROR); @@ -59,7 +62,7 @@ PlayableSound_t * LoadSound(const Sound_t * Sound){ Sound->BitDepth, //wBitsPerSample 0 //cbSize }; - + const XAUDIO2_BUFFER buffer = { 0, //Flags Sound->Duration * wfx.nBlockAlign, //AudioBytes @@ -71,13 +74,13 @@ PlayableSound_t * LoadSound(const Sound_t * Sound){ XAUDIO2_LOOP_INFINITE, //LoopCount NULL, //pContext }; - + IXAudio2SourceVoice* pSourceVoice; if(FAILED(pXAudio2->CreateSourceVoice(&pSourceVoice, &wfx))) return NULL; if(FAILED(pSourceVoice->SubmitSourceBuffer(&buffer))) return NULL; - + PlayableSound_t * PlayableSound = (PlayableSound_t*) malloc(sizeof(PlayableSound_t)); if(!PlayableSound) return NULL; diff --git a/Client/Client.cpp b/Client/Client.cpp index d49c2fa..4c5ebb1 100644 --- a/Client/Client.cpp +++ b/Client/Client.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Client.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -23,7 +26,7 @@ Scene * CurrentScene; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { int result; - + //Disallow multiple instances of the game from running CreateMutex(NULL, TRUE, "Global\\TSO_NIOTSO_MUTEX"); if(GetLastError() == ERROR_ALREADY_EXISTS){ @@ -40,13 +43,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) Window::Height = 600; Window::Fullscreen = false; System::hInst = hInstance; - + result = Window::Initialize(); if(result != 0){ Shutdown(); return ERROR_INIT | ERROR_INIT_WINDOW | result; } - + result = System::Initialize(); if(result != 0){ Shutdown(); @@ -64,20 +67,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) Shutdown(); return ERROR_INIT | ERROR_INIT_AUDIO | result; } - + CurrentScene = new LoginScreen(); if(CurrentScene == NULL || System::SceneFailed){ Shutdown(); return ERROR_INIT | ERROR_INIT_LOGIC | ERROR_LOGIC_CREATE_SCENE; } - + ShowWindow(Window::hWnd, SW_SHOW); SetForegroundWindow(Window::hWnd); SetFocus(Window::hWnd); - + LARGE_INTEGER PreviousTime; QueryPerformanceCounter(&PreviousTime); - + while(true){ LARGE_INTEGER CurrentTime; QueryPerformanceCounter(&CurrentTime); @@ -86,9 +89,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) PreviousTime.QuadPart = CurrentTime.QuadPart; continue; } - + memcpy(&System::UserInput, (const void*) &System::UserInput_v, sizeof(System::UserInput_t)); - + int result = CurrentScene->RunFor(TimeDelta); if(result == System::SHUTDOWN) break; @@ -97,7 +100,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) CurrentScene->Render(); SwapBuffers(Graphics::hDC); } - + PreviousTime.QuadPart = CurrentTime.QuadPart; QueryPerformanceCounter(&CurrentTime); float SleepDuration = @@ -107,7 +110,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) ShowWindow(Window::hWnd, SW_HIDE); delete CurrentScene; - + Shutdown(); return 0; } diff --git a/Client/EngineInterface.hpp b/Client/EngineInterface.hpp index fb80649..a17f080 100644 --- a/Client/EngineInterface.hpp +++ b/Client/EngineInterface.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + EngineInterface.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -22,8 +25,9 @@ //Standard libraries #include +#include +#include #include -#include #include #undef NULL #define NULL 0 diff --git a/Client/Graphics/Font.cpp b/Client/Graphics/Font.cpp index a9a9b7f..580814d 100644 --- a/Client/Graphics/Font.cpp +++ b/Client/Graphics/Font.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Graphics/Font.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -25,25 +28,25 @@ FT_Face FontFace; static void FindStringSize(const wchar_t * String, unsigned * width, unsigned * height, int * xoffset, int * yoffset, int font){ int x = 0, y = 0; int lowestx = 0, lowesty = 0, highestx = 0, highesty = 0; - + for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){ int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER); if(error) continue; - + int bottomx = x + FontFace->glyph->bitmap_left; int bottomy = y + FontFace->glyph->bitmap_top - FontFace->glyph->bitmap.rows; if(bottomx < lowestx) lowestx = bottomx; if(bottomy < lowesty) lowesty = bottomy; - + int topx = x + FontFace->glyph->bitmap_left + FontFace->glyph->bitmap.width; int topy = y + FontFace->glyph->bitmap_top; if(topx > highestx) highestx = topx; if(topy > highesty) highesty = topy; - + x += FontFace->glyph->advance.x >> 6; y += FontFace->glyph->advance.y >> 6; } - + *width = highestx-lowestx, *height = highesty-lowesty; *xoffset = -lowestx, *yoffset = -lowesty; } @@ -53,14 +56,14 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi //x, y, width, height form the bounding rectangle into which the text should be drawn. //(x,y) defines the offset to the top-left of the rectangle from the top left of the background. //The destination image must be stored in bottom-up order. - + if(x >= (signed)Image->Width || y >= (signed)Image->Height) return; //(stringx,stringy) will refer to the top-left of the string in bottom-up coordinates int stringx, stringy; unsigned StringWidth, StringHeight; FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font); - + //Horizontal alignment if(Alignment < 2) stringx = x; //Left else if(Alignment < 4) stringx = x+(width-StringWidth+1)/2; //Middle @@ -69,17 +72,17 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi if(!(Alignment&1)) stringy = y; //Top else stringy = y+(height-StringHeight+1)/2; //Middle stringy = Image->Height-stringy-StringHeight; - + //Now that we've done the alignment, we can crop the bounding box within the limits of the background image if(x < 0){ Image->Width += x; x = 0; } if(y < 0){ Image->Height += y; y = 0; } if(width > Image->Width) width = Image->Width; if(height > Image->Height) height = Image->Height; - + for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){ int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER); if(error) continue; - + int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows; if(cWidth && cHeight){ uint8_t * cRender; /* Convert to Bottom-up */ @@ -108,7 +111,7 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi } stringx -= FontFace->glyph->bitmap_left; stringy -= FontFace->glyph->bitmap_top-cHeight; - + if(FontFace->glyph->bitmap.pitch > 0) free(cRender); } stringx += FontFace->glyph->advance.x >> 6; @@ -123,7 +126,7 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){ unsigned StringWidth, StringHeight; int stringx, stringy; FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font); - + Image->Data = (uint8_t*) malloc(4 * StringWidth * StringHeight); if(Image->Data == NULL){ free(Image); @@ -135,11 +138,11 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){ Image->Data[i++] = GetRValue(Color); Image->Data[i++] = 0; } - + for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){ int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER); if(error) continue; - + int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows; if(cWidth && cHeight){ uint8_t * cRender; /* Convert to Bottom-up */ @@ -160,13 +163,13 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){ } stringx -= FontFace->glyph->bitmap_left; stringy -= FontFace->glyph->bitmap_top-cHeight; - + if(FontFace->glyph->bitmap.pitch > 0) free(cRender); } stringx += FontFace->glyph->advance.x >> 6; stringy += FontFace->glyph->advance.y >> 6; } - + Image->Width = StringWidth; Image->Height = StringHeight; Image->Format = FIMG_BGRA32; diff --git a/Client/Graphics/Graphics.hpp b/Client/Graphics/Graphics.hpp index 53f3666..f9e5a85 100644 --- a/Client/Graphics/Graphics.hpp +++ b/Client/Graphics/Graphics.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Graphics/Graphics.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -24,10 +27,10 @@ namespace Graphics { void Shutdown(); extern HDC hDC; extern HGLRC hRC; - + int InitGL(); void ResizeViewport(unsigned width, unsigned height); - + enum TextAlignment { ALIGN_LEFT_TOP, ALIGN_LEFT_CENTER, @@ -36,7 +39,7 @@ namespace Graphics { ALIGN_RIGHT_TOP, ALIGN_RIGHT_CENTER }; - + //Font.cpp extern FT_Library FreeTypeLibrary; extern FT_Face FontFace; diff --git a/Client/Graphics/Startup.cpp b/Client/Graphics/Startup.cpp index ff8dd38..35f44ae 100644 --- a/Client/Graphics/Startup.cpp +++ b/Client/Graphics/Startup.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Graphics/Startup.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -29,7 +32,7 @@ int Initialize(){ Shutdown(); return ERROR_GRAPHICS_OBTAIN_DC; } - + const PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, //Size and version PFD_DRAW_TO_WINDOW | //dwFlags @@ -46,7 +49,7 @@ int Initialize(){ 0, //Reserved 0, 0, 0 //Masks }; - + unsigned PixelFormat = ChoosePixelFormat(hDC, &pfd); if(!PixelFormat){ MessageBox(Window::hWnd, "Failed to find a suitable pixel format for the device context.", NULL, MB_OK | MB_ICONERROR); @@ -59,31 +62,31 @@ int Initialize(){ Shutdown(); return ERROR_GRAPHICS_SET_PIXELFORMAT; } - + hRC = wglCreateContext(hDC); if(!hRC){ MessageBox(Window::hWnd, "Failed to create an OpenGL rendering context.", NULL, MB_OK | MB_ICONERROR); Shutdown(); return ERROR_GRAPHICS_CREATE_GLRC; } - + if(!wglMakeCurrent(hDC, hRC)){ MessageBox(Window::hWnd, "Failed to activate the OpenGL device context.", NULL, MB_OK | MB_ICONERROR); Shutdown(); return ERROR_GRAPHICS_ACTIVATE_GLRC; } - + BOOL (WINAPI *wglSwapIntervalEXT)(int) = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT"); if(wglSwapIntervalEXT) wglSwapIntervalEXT(1); int (WINAPI *wglGetSwapIntervalEXT)(void) = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT"); if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); //Seems necessary on some cards - + int result = InitGL(); if(result != 0){ Shutdown(); return ERROR_GRAPHICS_INIT_GLSCENE | result; } - + ResizeViewport(Window::Width, Window::Height); return 0; } diff --git a/Client/Graphics/Viewport.cpp b/Client/Graphics/Viewport.cpp index ae15159..c39c9b0 100644 --- a/Client/Graphics/Viewport.cpp +++ b/Client/Graphics/Viewport.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Graphics/Viewport.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 diff --git a/Client/Scene/LoginScreen/LoginScreen.cpp b/Client/Scene/LoginScreen/LoginScreen.cpp index e94f4d7..9bb020b 100644 --- a/Client/Scene/LoginScreen/LoginScreen.cpp +++ b/Client/Scene/LoginScreen/LoginScreen.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Scene/LoginScreen/LoginScreen.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -43,9 +46,9 @@ LoginScreen::LoginScreen() : Scene(0){ glMatrixMode(GL_TEXTURE); glGenTextures(TEX_COUNT, texture); - + FT_Set_Char_Size(Graphics::FontFace, 0, 22*64, 0, 0); - + for(int i=TEX_EAGAMES; i<=TEX_SETUP; i++){ Image_t * Image = File::ReadImageFile(images[i]); if(!Image){ @@ -74,12 +77,12 @@ LoginScreen::LoginScreen() : Scene(0){ MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR); EXIT_SCENE(); } - + if(i == TEX_MAXIS){ Graphics::DrawText(Image, L"Maxis\x2122 is an Electronic Arts\x2122 brand.", 0, 600-146, 800, 146, Graphics::ALIGN_CENTER_CENTER, 0, RGB(0xef, 0xe3, 0x8c)); } - + glBindTexture(GL_TEXTURE_2D, texture[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -89,7 +92,7 @@ LoginScreen::LoginScreen() : Scene(0){ free(Image->Data); free(Image); } - + image[IMG_COPYRIGHT] = Graphics::StringImage(L"(c) 2002, 2003 Electronic Arts Inc. All rights reserved.", 0, RGB(0xef, 0xe3, 0x8c)); if(image[IMG_COPYRIGHT] == NULL){ @@ -118,7 +121,7 @@ LoginScreen::LoginScreen() : Scene(0){ GL_UNSIGNED_BYTE, image[IMG_STATUS+i]->Data); free(image[IMG_STATUS+i]->Data); } - + for(int i=0; i + Niotso - The New Implementation of The Sims Online + Scene/LoginScreen/LoginScreen.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -47,7 +50,7 @@ class LoginScreen : public Scene { LoginScreen(); ~LoginScreen(); void Render(); - + private: int Run(float TimeDelta); }; \ No newline at end of file diff --git a/Client/Scene/Scene.hpp b/Client/Scene/Scene.hpp index 7b37b61..97133b5 100644 --- a/Client/Scene/Scene.hpp +++ b/Client/Scene/Scene.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Scene/Scene.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -34,7 +37,7 @@ class Scene { if(TickPeriod == 0){ return Run(TimeDelta); } - + bool Redraw = false; RealTimeDelta += TimeDelta; while(RealTimeDelta >= 0){ @@ -46,7 +49,7 @@ class Scene { } return (Redraw) ? 1 : -1; } - + virtual void Render() = 0; virtual ~Scene() {}; }; diff --git a/Client/System/System.cpp b/Client/System/System.cpp index a19515f..f677a12 100644 --- a/Client/System/System.cpp +++ b/Client/System/System.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + System/System.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -24,17 +27,17 @@ HANDLE Process; HANDLE ProcessHeap; LARGE_INTEGER ClockFreq; volatile float FramePeriod; -UserInput_t UserInput = {0}; +UserInput_t UserInput = UserInput_t(); volatile UserInput_t UserInput_v; bool SceneFailed = false; int Initialize(){ QueryPerformanceFrequency(&ClockFreq); - + DEVMODE dm; EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); System::FramePeriod = 1.0f/dm.dmDisplayFrequency; - + if(FT_Init_FreeType(&Graphics::FreeTypeLibrary)){ MessageBox(Window::hWnd, "Failed to initialize FreeType.", NULL, MB_OK | MB_ICONERROR); Graphics::FreeTypeLibrary = NULL; diff --git a/Client/System/System.hpp b/Client/System/System.hpp index a3fd53f..82dcd6c 100644 --- a/Client/System/System.hpp +++ b/Client/System/System.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + System/System.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 @@ -24,7 +27,7 @@ namespace System { extern HANDLE ProcessHeap; extern LARGE_INTEGER ClockFreq; extern volatile float FramePeriod; - + struct UserInput_t { bool Keys[256]; bool MouseDown; @@ -34,7 +37,7 @@ namespace System { extern volatile UserInput_t UserInput_v; extern bool SceneFailed; - + //Constants enum { SHUTDOWN = 0 diff --git a/Client/TODO b/Client/TODO index 462081a..bc030d2 100644 --- a/Client/TODO +++ b/Client/TODO @@ -12,7 +12,7 @@ Development Phase: Planning Technical Preview 1 Schedule: (Not very subject to change) 1. Implement cst and uis parsers [40%] - 2. Replicate functionality up until the login dialog [0%] + 2. Replicate functionality up until the login dialog [90%] 3. Implement the OpenGL-based windowing system 4. Replicate character selection and creation features and the city selection dialog 5. Implement the code needed to allow the game to read all necessary files from the TSOClient folder \ No newline at end of file diff --git a/Client/Window/Window.cpp b/Client/Window/Window.cpp index 8758d65..ff355b2 100644 --- a/Client/Window/Window.cpp +++ b/Client/Window/Window.cpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Window/Window.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 diff --git a/Client/Window/Window.hpp b/Client/Window/Window.hpp index 63104ca..08fd040 100644 --- a/Client/Window/Window.hpp +++ b/Client/Window/Window.hpp @@ -1,5 +1,8 @@ /* - Niotso - Copyright (C) 2012 Fatbag + Niotso - The New Implementation of The Sims Online + Window/Window.hpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 diff --git a/Libraries/FileHandler/AUTHORS b/Libraries/FileHandler/AUTHORS new file mode 100644 index 0000000..0306b6d --- /dev/null +++ b/Libraries/FileHandler/AUTHORS @@ -0,0 +1,2 @@ +Fatbag +Ahmed El-Mahdawy \ No newline at end of file diff --git a/Libraries/FileHandler/Audio.cpp b/Libraries/FileHandler/Audio.cpp index 9f8fb00..ff56ac2 100644 --- a/Libraries/FileHandler/Audio.cpp +++ b/Libraries/FileHandler/Audio.cpp @@ -1,5 +1,7 @@ /* - FileHandler - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + Audio.cpp - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -51,7 +53,7 @@ static uint8_t* (* const SoundFunction[])(Sound_t*, const uint8_t*, size_t) = { Sound_t * ReadSoundFile(const char * Filename){ uint8_t * InData = File::ReadFile(Filename); if(InData == NULL) return NULL; - + if(File::FileSize < 4){ free(InData); File::Error = FERR_INVALIDDATA; @@ -87,13 +89,13 @@ static uint8_t * ReadWAV(Sound_t * Sound, const uint8_t * InData, size_t FileSiz if(!wav_read_header(&WAVHeader, InData, FileSize)){ return NULL; } - + uint8_t * OutData = (uint8_t*) malloc(WAVHeader.DataSize); if(OutData == NULL){ return NULL; } memcpy(OutData, InData+44, WAVHeader.DataSize); - + Sound->Channels = WAVHeader.nChannels; Sound->SamplingRate = WAVHeader.nSamplesPerSec; Sound->BitDepth = WAVHeader.wBitsPerSample; @@ -108,7 +110,7 @@ static uint8_t * ReadXA(Sound_t * Sound, const uint8_t * InData, size_t FileSize if(!xa_read_header(&XAHeader, InData, FileSize)){ return NULL; } - + uint8_t * OutData = (uint8_t*) malloc(XAHeader.dwOutSize); if(OutData == NULL){ return NULL; @@ -117,7 +119,7 @@ static uint8_t * ReadXA(Sound_t * Sound, const uint8_t * InData, size_t FileSize free(OutData); return NULL; } - + Sound->Channels = XAHeader.nChannels; Sound->SamplingRate = XAHeader.nSamplesPerSec; Sound->BitDepth = XAHeader.wBitsPerSample; @@ -131,12 +133,12 @@ static uint8_t * ReadUTK(Sound_t * Sound, const uint8_t * InData, size_t FileSiz if(!utk_read_header(&UTKHeader, InData, FileSize)){ return NULL; } - + uint8_t * OutData = (uint8_t*) malloc(UTKHeader.dwOutSize); if(OutData == NULL){ return NULL; } - + static bool generated = false; if(!generated){ UTKGenerateTables(); @@ -147,7 +149,7 @@ static uint8_t * ReadUTK(Sound_t * Sound, const uint8_t * InData, size_t FileSiz free(OutData); return NULL; } - + Sound->Channels = 1; Sound->SamplingRate = UTKHeader.nSamplesPerSec; Sound->BitDepth = UTKHeader.wBitsPerSample; @@ -161,7 +163,7 @@ static uint8_t * ReadMP3(Sound_t * Sound, const uint8_t * InData, size_t FileSiz mpg123_exit(); return NULL; } - + long rate; int channels, encoding; unsigned samples; @@ -190,12 +192,12 @@ static uint8_t * ReadMP3(Sound_t * Sound, const uint8_t * InData, size_t FileSiz mpg123_close(mh); mpg123_delete(mh); mpg123_exit(); - + if(decoded != OutSize){ free(OutData); return NULL; } - + Sound->Channels = channels; Sound->SamplingRate = rate; Sound->BitDepth = 16; diff --git a/Libraries/FileHandler/CMakeLists.txt b/Libraries/FileHandler/CMakeLists.txt index 39a0c4b..86ab6d0 100644 --- a/Libraries/FileHandler/CMakeLists.txt +++ b/Libraries/FileHandler/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 2.6) project(FileHandler) +add_subdirectory(far) add_subdirectory(iff) add_subdirectory(libexpat) -add_subdirectory(libfar) add_subdirectory(libjpeg-turbo) add_subdirectory(libmpg123) add_subdirectory(libpng) diff --git a/Libraries/FileHandler/COPYING b/Libraries/FileHandler/COPYING new file mode 100644 index 0000000..5101ae2 --- /dev/null +++ b/Libraries/FileHandler/COPYING @@ -0,0 +1,15 @@ +FileHandler - General-purpose file handling library for Niotso +Version 0.0.0 +Copyright (c) 2012 Niotso Project + +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. \ No newline at end of file diff --git a/Libraries/FileHandler/File.cpp b/Libraries/FileHandler/File.cpp index dffdada..1abad14 100644 --- a/Libraries/FileHandler/File.cpp +++ b/Libraries/FileHandler/File.cpp @@ -1,5 +1,7 @@ /* - FileHandler - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + File.cpp - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/FileHandler.hpp b/Libraries/FileHandler/FileHandler.hpp index eca79e9..2f7caf2 100644 --- a/Libraries/FileHandler/FileHandler.hpp +++ b/Libraries/FileHandler/FileHandler.hpp @@ -1,5 +1,7 @@ /* - FileHandler - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + FileHandler.hpp - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/Image.cpp b/Libraries/FileHandler/Image.cpp index 89429a2..25ac169 100644 --- a/Libraries/FileHandler/Image.cpp +++ b/Libraries/FileHandler/Image.cpp @@ -1,5 +1,7 @@ /* - FileHandler - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + Image.cpp - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -42,7 +44,7 @@ static uint8_t * ReadTGACUR(Image_t * Image, const uint8_t * InData, size_t File //In many cases we're going to see these bytes, exactly, at the beginning in both formats: //00 00 02 00 01 00 //So screw it. Try parsing the file first as a TGA, then as a CUR. - + uint8_t * Result = ReadTGA(Image, InData, FileSize); return Result ? Result : ReadCUR(Image, InData, FileSize); } @@ -63,7 +65,7 @@ static uint8_t* (* const ImageFunction[])(Image_t*, const uint8_t*, size_t) = { Image_t * ReadImageFile(const char * Filename){ uint8_t * InData = File::ReadFile(Filename); if(InData == NULL) return NULL; - + if(File::FileSize < 4){ free(InData); File::Error = FERR_INVALIDDATA; @@ -99,7 +101,7 @@ static uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSiz if(!bmp_read_header(&BMPHeader, InData, FileSize)){ return NULL; } - + uint8_t * OutData = (uint8_t*) malloc(BMPHeader.DecompressedSize); if(OutData == NULL){ return NULL; @@ -108,7 +110,7 @@ static uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSiz free(OutData); return NULL; } - + Image->Width = BMPHeader.biWidth; Image->Height = BMPHeader.biHeight; Image->Format = FIMG_BGR24; @@ -179,7 +181,7 @@ static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t lengt } static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize){ pngdata_t pngdata; - + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) return 0; png_infop info_ptr = png_create_info_struct(png_ptr); @@ -191,7 +193,7 @@ static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSiz png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return NULL; } - + pngdata.buffer = InData; pngdata.size = FileSize; png_set_read_fn(png_ptr, &pngdata, user_read_data); @@ -199,7 +201,7 @@ static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSiz png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_GRAY_TO_RGB | PNG_TRANSFORM_BGR, NULL); - + //png_get_IHDR does not work in high-level mode. unsigned width = png_get_image_width(png_ptr, info_ptr); unsigned height = png_get_image_height(png_ptr, info_ptr); @@ -208,11 +210,11 @@ static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSiz png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return NULL; } - + uint8_t **Scanlines = png_get_rows(png_ptr, info_ptr); for(unsigned i=0; iWidth = width; Image->Height = height; diff --git a/Libraries/FileHandler/README b/Libraries/FileHandler/README new file mode 100644 index 0000000..caff585 --- /dev/null +++ b/Libraries/FileHandler/README @@ -0,0 +1,32 @@ +*************************************************************************** +* ** FileHandler - General-purpose file handling library for Niotso ** * +* ** Copyright (c) 2011-2012 Niotso Project + FileHandler - General-purpose file handling library for Niotso + read_bmp.c - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -49,7 +51,7 @@ int bmp_read_header(bmpheader_t * BMPHeader, const uint8_t * Buffer, size_t File BMPHeader->biYPelsPerMeter = read_uint32(Buffer+42); BMPHeader->biClrUsed = read_uint32(Buffer+46); BMPHeader->biClrImportant = read_uint32(Buffer+50); - + BMPHeader->CompressedSize = FileSize - BMPHeader->bfOffBits; BMPHeader->DecompressedSize = BMPHeader->biWidth * BMPHeader->biHeight * 3; @@ -70,7 +72,7 @@ int bmp_read_header(bmpheader_t * BMPHeader, const uint8_t * Buffer, size_t File (BMPHeader->biBitCount == 8 && BMPHeader->CompressedSize < BMPHeader->DecompressedSize/3 + BMPHeader->biHeight*(BMPHeader->biWidth%4) /* Account for padding in 8-bit BMPs */))) ) return 0; - + return 1; } @@ -79,7 +81,7 @@ int bmp_read_data(bmpheader_t * BMPHeader, const uint8_t *__restrict InBuffer, u memcpy(OutBuffer, InBuffer+BMPHeader->bfOffBits, BMPHeader->DecompressedSize); return 1; } - + if(BMPHeader->biBitCount == 8){ const uint8_t *__restrict Palette = InBuffer + 54; InBuffer += BMPHeader->bfOffBits; @@ -98,7 +100,7 @@ int bmp_read_data(bmpheader_t * BMPHeader, const uint8_t *__restrict InBuffer, u } return 1; } - + if(BMPHeader->biCompression == BI_RLE8){ const uint8_t *__restrict const srcend = InBuffer+BMPHeader->CompressedSize; uint8_t *__restrict const destend = OutBuffer+BMPHeader->DecompressedSize; @@ -107,12 +109,12 @@ int bmp_read_data(bmpheader_t * BMPHeader, const uint8_t *__restrict InBuffer, u unsigned i; const unsigned command = *InBuffer++; const unsigned value = *InBuffer++; - + if(command == 0){ if(value == 0) continue; /* End of scanline reminder */ if(value == 1) return (InBuffer == srcend && OutBuffer == destend); /* End of bitmap reminder */ if(value == 2) return 0; /* Delta, used for ICO/CUR masks; wrong kind of bitmap */ - + /* Absolute copy */ if(value > (unsigned)(srcend-InBuffer) || value*3 > (unsigned)(destend-OutBuffer)) break; for(i=0; i + FileHandler - General-purpose file handling library for Niotso + read_bmp.h - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -34,7 +36,7 @@ typedef struct uint32_t biYPelsPerMeter; uint32_t biClrUsed; uint32_t biClrImportant; - + size_t CompressedSize; size_t DecompressedSize; } bmpheader_t; diff --git a/Libraries/FileHandler/cst/cst.c b/Libraries/FileHandler/cst/cst.c index ba31280..c8afdb9 100644 --- a/Libraries/FileHandler/cst/cst.c +++ b/Libraries/FileHandler/cst/cst.c @@ -1,5 +1,7 @@ /* - cst.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + cst.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/cst/cst.h b/Libraries/FileHandler/cst/cst.h index 2305f92..f53a052 100644 --- a/Libraries/FileHandler/cst/cst.h +++ b/Libraries/FileHandler/cst/cst.h @@ -1,5 +1,7 @@ /* - cst.h - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + cst.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/cur/read_cur.c b/Libraries/FileHandler/cur/read_cur.c index 2f759d9..1690842 100644 --- a/Libraries/FileHandler/cur/read_cur.c +++ b/Libraries/FileHandler/cur/read_cur.c @@ -1,16 +1,17 @@ /* - Niotso - Copyright (C) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_cur.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag - 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. + 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. - 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 . + 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. */ \ No newline at end of file diff --git a/Libraries/FileHandler/cur/read_cur.h b/Libraries/FileHandler/cur/read_cur.h index 2f759d9..b022066 100644 --- a/Libraries/FileHandler/cur/read_cur.h +++ b/Libraries/FileHandler/cur/read_cur.h @@ -1,16 +1,17 @@ /* - Niotso - Copyright (C) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_cur.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag - 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. + 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. - 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 . + 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. */ \ No newline at end of file diff --git a/Libraries/FileHandler/far/CMakeLists.txt b/Libraries/FileHandler/far/CMakeLists.txt new file mode 100644 index 0000000..93dc44b --- /dev/null +++ b/Libraries/FileHandler/far/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.6) +project(far) + +set(FAR_SOURCES + libfar.c + refpack_dec.c +) + +add_library(far_static STATIC ${FAR_SOURCES}) +set_target_properties(far_static PROPERTIES + OUTPUT_NAME "far" + CLEAN_DIRECT_OUTPUT 1) + +#### Shared library (uncomment to build) +#add_library(far_shared SHARED ${FAR_SOURCES}) +#set_target_properties(far_shared PROPERTIES +# OUTPUT_NAME "far" +# PREFIX "" +# CLEAN_DIRECT_OUTPUT 1) + +add_executable(farextract farextract.c) +target_link_libraries(farextract far_static) \ No newline at end of file diff --git a/Libraries/FileHandler/far/Makefile b/Libraries/FileHandler/far/Makefile new file mode 100644 index 0000000..4fff97b --- /dev/null +++ b/Libraries/FileHandler/far/Makefile @@ -0,0 +1,42 @@ +# macros -------------------------------------------------------------------- +CC = gcc +LD = gcc +CFLAGS = -m32 -Wall -Wextra -Wabi -Os -march=i686 -fomit-frame-pointer -ffast-math -funsafe-loop-optimizations -fmerge-all-constants -g0 -fno-exceptions +LDFLAGS = -m32 -s -fwhole-program + +AR = ar rcs +WINDRES = windres -F pe-i386 + +LIBRARY_OBJS = obj/libfar.o obj/qfsdecompress.o +RESOURCE_OBJ = obj/resource.o +FAREXTRACT_OBJ = obj/farextract.o + +# These will rebuild the entire library upon edit. +DEPS = Makefile \ + config.h \ + include/libfar.h + +# dependencies -------------------------------------------------------------- +all: libfar.a libfar-10.dll farextract.exe + +$(LIBRARY_OBJS): $(DEPS) + +libfar.a: $(LIBRARY_OBJS) + $(AR) $@ $(LIBRARY_OBJS) + +libfar-10.dll: $(LIBRARY_OBJS) $(RESOURCE_OBJ) + $(CC) $(LDFLAGS) -shared -o $@ $(LIBRARY_OBJS) $(RESOURCE_OBJ) + +farextract.exe: libfar.a $(FAREXTRACT_OBJ) + $(CC) $(LDFLAGS) -o $@ $(FAREXTRACT_OBJ) libfar.a + +# make rules ---------------------------------------------------------------- +obj/%.o: %.c + $(CC) -c -ansi -pedantic $(CFLAGS) -o $@ $< + +obj/%.o: %.rc + $(WINDRES) -i $< -o $@ + +# maintenance --------------------------------------------------------------- +clean: + del /Q /S obj libfar.a libfar-10.dll farextract.exe \ No newline at end of file diff --git a/Libraries/FileHandler/far/config.h b/Libraries/FileHandler/far/config.h new file mode 100644 index 0000000..c98611b --- /dev/null +++ b/Libraries/FileHandler/far/config.h @@ -0,0 +1,24 @@ +/* config.h - libfar build configuration */ + +/* Define if you have the header file. */ +#define HAVE_STDINT_H + +/* compile-in support */ +#define LIBFAR_ARCHIVEREAD +#define LIBFAR_ARCHIVEWRITE +#define LIBFAR_REFPACK_DECOMPRESS +#define LIBFAR_REFPACK_COMPRESS +#define LIBFAR_SUPPORT_FAR +#define LIBFAR_SUPPORT_DBPF +#define LIBFAR_SUPPORT_PERSIST +#define LIBFAR_DEBUGSUPPORT +#define LIBFAR_FILEIO +#define LIBFAR_EMBEDDEDFUNCTIONS +/* end of compile-in support */ + +/* preferences -- on non-numerical definitions, define to 1 for "yes", 0 for "no"; */ +#define LIBFAR_DEFAULT_1A 0 +#define LIBFAR_DEFAULT_DBPF_COMPRESSED 0 +#define LIBFAR_DEFAULT_MAX_FILE_NAME_LENGTH 255 +#define LIBFAR_DEFAULT_REFPACK_HNSV 0xFB +/* end of default preferences */ diff --git a/Libraries/FileHandler/far/farextract.c b/Libraries/FileHandler/far/farextract.c new file mode 100644 index 0000000..9864f63 --- /dev/null +++ b/Libraries/FileHandler/far/farextract.c @@ -0,0 +1,287 @@ +/* + FileHandler - General-purpose file handling library for Niotso + farextract.c - Copyright (c) 2011 Niotso Project + Author(s): Fatbag + + 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 "config.h" + +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +#ifdef HAVE_STDINT_H + #include +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed short int16_t; + typedef unsigned short uint16_t; + typedef signed long int32_t; + typedef unsigned long uint32_t; + typedef unsigned int uintptr_t; +#endif + +#include "libfar.h" + +enum { + profile_ts1 = 1, + profile_tso, + profile_sc4, + profile_ts2, + profile_spore, + profile_ts3 +}; + +int main(int argc, char *argv[]){ + int profile = 0, overwrite = 0; + char infile[256] = "", outdirectory[256] = ""; + + HANDLE ProcessHeap = GetProcessHeap(); + HANDLE hFile; + DWORD ArchiveSize; + DWORD bytestransferred = 0; + uint8_t * ArchiveData; + int ArchiveType; + + unsigned BeginningTime, EndingTime; + int i; + + /**** + ** Check the arguments + */ + + if(argc == 1 || (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))){ + printf("Usage: farextract [OPTIONS] [FILE] [OUTDIRECTORY]\n" + "Extract the contents of a FAR, DBPF, or Persist file.\n" + "With no FILE, or when FILE is -, read from standard input.\n" + "\n" + "Profile options:\n" + " -ts1, -tso, -sc4, Select presets suitable for The Sims 1,\n" + " -ts2, -spore, -ts3 The Sims Online, SimCity 4, Spore, or The Sims 3\n" + "\n"); + printf("Miscellaneous options:\n" + " -f, --force Force overwriting of files without confirmation\n" + " -h, --help Show this help and exit\n" + "\n" + "Report bugs to .\n" + "farextract and libfar are maintained by the Niotso project.\n" + "Home page: "); + return 0; + } + + for(i=1; !infile[0] && i != argc-1; i++){ + /* Match for options */ + if(!profile){ + if(!strcmp(argv[i], "-ts1")){ profile = profile_ts1; continue; } + if(!strcmp(argv[i], "-tso")){ profile = profile_tso; continue; } + if(!strcmp(argv[i], "-sc4")){ profile = profile_sc4; continue; } + if(!strcmp(argv[i], "-ts2")){ profile = profile_ts2; continue; } + if(!strcmp(argv[i], "-spore")){ profile = profile_spore; continue; } + if(!strcmp(argv[i], "-ts3")){ profile = profile_ts3; continue; } + } + if(!overwrite && (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--force"))){ + overwrite = 1; + continue; + } + /* Not an option */ + if(!strcmp(argv[i], "-")){ + printf("%sReading from standard input is not yet implemented.", "farextract: error: "); + return -1; + } + strcpy(infile, argv[i]); + continue; + } + /* We're left with the out directory */ + if(!infile[0]){ + printf("%sReading from standard input is not yet implemented.", "farextract: error: "); + return -1; + } + strcpy(outdirectory, argv[i]); + + /**** + ** Handle profile settings + */ + if(!profile) profile = profile_tso; + libfar_set_option(LIBFAR_CONFIG_DEFAULT_TO_1A, (profile == profile_ts1)); + libfar_set_option(LIBFAR_CONFIG_DBPF_COMPRESSED, (profile >= profile_sc4)); + libfar_set_option(LIBFAR_CONFIG_REFPACK_HNSV, 0xFB); + + /**** + ** Attempt to open the file and read in the entire contents to memory + */ + + 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.", "farextract: error: "); + return -1; + } + printf("%sThe input file could not be opened for reading.", "farextract: error: "); + return -1; + } + ArchiveSize = GetFileSize(hFile, NULL); + if(ArchiveSize < LIBFAR_ARCHIVE_MINIMUM_SIZE){ + printf("%sNot a valid archive.", "farextract: error: "); + return -1; + } + ArchiveData = HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, ArchiveSize); + if(ArchiveData == NULL){ + printf("%sMemory for this archive could not be allocated.", "farextract: error: "); + return -1; + } + if(!ReadFile(hFile, ArchiveData, ArchiveSize, &bytestransferred, NULL) || bytestransferred != ArchiveSize){ + printf("%sThe input file could not be read.", "farextract: error: "); + return -1; + } + CloseHandle(hFile); + + /**** + ** Identify the type of archive + */ + + ArchiveType = far_identify(ArchiveData, ArchiveSize); + if(ArchiveType == FAR_TYPE_INVALID){ + printf("%sNot a valid archive.", "farextract: error: "); + return -1; + } + + if(ArchiveType != FAR_TYPE_PERSIST){ + FAREntryNode * EntryNode; + unsigned file = 0, filescount; + + /**** + ** Load header information + */ + + FARFile * FARFileInfo = far_create_archive(ArchiveType); + if(FARFileInfo == NULL){ + printf("%sMemory for this archive could not be allocated.", "farextract: error: "); + return -1; + } + if(!far_read_header(FARFileInfo, ArchiveData, ArchiveSize)){ + printf("%sNot a valid archive.", "farextract: error: "); + return -1; + } + + filescount = FARFileInfo->Files; + printf("This archive contains %u files.\n\nExtracting\n", filescount); + BeginningTime = GetTickCount(); + + /**** + ** Load entry information + */ + + if(!far_enumerate_entries(FARFileInfo, ArchiveData+FARFileInfo->IndexOffset, + ArchiveSize-FARFileInfo->IndexOffset, ArchiveSize)){ + printf("%sEntry data is corrupt.", "farextract: error: "); + return -1; + } + + /**** + ** Extract each entry + */ + for(EntryNode = FARFileInfo->FirstEntry; EntryNode; EntryNode = EntryNode->NextEntry){ + char destination[256]; + + file++; + if(EntryNode->Entry.Filename) + sprintf(destination, "%s/%s", outdirectory, EntryNode->Entry.Filename); + else + sprintf(destination, "%s/%08x-%08x-%08x.dat", outdirectory, + EntryNode->Entry.TypeID, EntryNode->Entry.GroupID, EntryNode->Entry.FileID); + + if(!far_read_entry_data(FARFileInfo, &(EntryNode->Entry), ArchiveData)){ + printf(" (%u/%u) Skipped (%s): %s\n", file, filescount, + "entry data is corrupt", EntryNode->Entry.Filename); + continue; + } + /* Decompression, if any, was successful */ + + hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if(hFile == INVALID_HANDLE_VALUE){ + printf(" (%u/%u) Skipped (%s): %s\n", file, filescount, + (!overwrite && GetLastError() == ERROR_FILE_EXISTS) ? "file exists" : "could not open", + EntryNode->Entry.Filename); + if(EntryNode->Entry.DecompressedData != EntryNode->Entry.CompressedData) + libfar_free(EntryNode->Entry.DecompressedData); + continue; + } + + if(EntryNode->Entry.Filename) + printf(" (%u/%u) %s (%u bytes)\n", file, filescount, + EntryNode->Entry.Filename, EntryNode->Entry.DecompressedSize); + else + printf(" (%u/%u) %08x-%08x-%08x (%u bytes)\n", file, filescount, + EntryNode->Entry.TypeID, EntryNode->Entry.GroupID, EntryNode->Entry.FileID, + EntryNode->Entry.DecompressedSize); + + WriteFile(hFile, EntryNode->Entry.DecompressedData, + EntryNode->Entry.DecompressedSize, &bytestransferred, NULL); + CloseHandle(hFile); + + if(EntryNode->Entry.DecompressedData != EntryNode->Entry.CompressedData) + libfar_free(EntryNode->Entry.DecompressedData); + } + printf("\nFinished extracting %u of %u files in %.2f seconds.", file, filescount, + ((float) (GetTickCount() - BeginningTime))/1000); + }else{ + /* Persist file */ + PersistFile * PersistInfo; + char destination[256]; + sprintf(destination, "%s/%s.out", outdirectory, infile); + + /**** + ** Load header information + */ + + PersistInfo = far_create_persist(); + if(PersistInfo == NULL){ + printf("%sMemory for this archive could not be allocated.", "farextract: error: "); + return -1; + } + if(!far_read_persist_header(PersistInfo, ArchiveData, ArchiveSize)){ + printf("%sNot a valid archive.", "farextract: error: "); + return -1; + } + + /**** + ** Extract the data + */ + printf("Extracting\n"); + BeginningTime = GetTickCount(); + if(!far_read_persist_data(PersistInfo, ArchiveData+18)){ + printf("%sNot a valid archive.", "farextract: error: "); + return -1; + } + EndingTime = GetTickCount(); + + hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if(hFile == INVALID_HANDLE_VALUE){ + printf((!overwrite && GetLastError() == ERROR_FILE_EXISTS) ? + "%sFile exists." : "%sCould not open.", "farextract: error: "); + return -1; + } + WriteFile(hFile, PersistInfo->DecompressedData, + PersistInfo->DecompressedSize, &bytestransferred, NULL); + CloseHandle(hFile); + printf("Extracted %u bytes in %.2f seconds.\n", PersistInfo->DecompressedSize, + ((float) (EndingTime - BeginningTime))/1000); + } + return 0; +} \ No newline at end of file diff --git a/Libraries/FileHandler/far/libfar.c b/Libraries/FileHandler/far/libfar.c new file mode 100644 index 0000000..3eea46a --- /dev/null +++ b/Libraries/FileHandler/far/libfar.c @@ -0,0 +1,469 @@ +/* + FileHandler - General-purpose file handling library for Niotso + libfar.c - Copyright (c) 2011 Niotso Project + Author(s): Fatbag + + 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 "config.h" + +#include +#include +#include + +#ifdef HAVE_STDINT_H + #include +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed short int16_t; + typedef unsigned short uint16_t; + typedef signed long int32_t; + typedef unsigned long uint32_t; + typedef unsigned int uintptr_t; +#endif + +#include "libfar.h" + +#if defined(LIBFAR_SUPPORT_PERSIST) + #define LIBFAR_MINSIZE_ANY MINSIZE_PERSIST +#elif defined(LIBFAR_SUPPORT_FAR) + #define LIBFAR_MINSIZE_ANY MINSIZE_FAR +#else + #define LIBFAR_MINSIZE_ANY MINSIZE_DBPF +#endif + +#ifndef read_int32 + #define read_int32(x) (int)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3))) + #define read_int24(x) (int)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2))) + #define read_int16(x) (int)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1))) + #define read_int8(x) (int)(((x)[0]<<(8*0))) + #define read_uint32(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3))) + #define read_uint24(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2))) + #define read_uint16(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1))) + #define read_uint8(x) (unsigned)(((x)[0]<<(8*0))) +#endif + +#ifndef max + #define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#ifndef min + #define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +/* These options can be changed during runtime */ +static int libfarOptions[] = { + LIBFAR_DEFAULT_1A, + LIBFAR_DEFAULT_DBPF_COMPRESSED, + LIBFAR_DEFAULT_MAX_FILE_NAME_LENGTH, + LIBFAR_DEFAULT_REFPACK_HNSV +}; + +void libfar_set_option(int Option, int Value){ + libfarOptions[Option] = Value; +} +int libfar_get_option(int Option){ + return libfarOptions[Option]; +} + +int far_identify(const uint8_t * Buffer, unsigned FileSize) +{ + if(!FileSize) FileSize = ~0; + else if(FileSize < LIBFAR_MINSIZE_ANY) + return FAR_TYPE_INVALID; + + #ifdef LIBFAR_SUPPORT_FAR + if(FileSize >= MINSIZE_FAR) + if(!memcmp(Buffer, Header_FAR, 8)) + return FAR_TYPE_FAR; + #endif + + #ifdef LIBFAR_SUPPORT_DBPF + if(FileSize >= MINSIZE_DBPF) + if(!memcmp(Buffer, Header_DBPF, 4)) + return FAR_TYPE_DBPF; + #endif + + #ifdef LIBFAR_SUPPORT_PERSIST + if(FileSize >= MINSIZE_PERSIST) + if(Buffer[0] == 0x01) + return FAR_TYPE_PERSIST; + #endif + + return FAR_TYPE_INVALID; +} + +FARFile * far_create_archive(int Type) +{ + FARFile *ptr = malloc(sizeof(FARFile)); + if(ptr == NULL) return NULL; + + memset(ptr, 0, sizeof(FARFile)); + ptr->Type = Type; + + return ptr; +} + +PersistFile * far_create_persist() +{ + PersistFile *ptr = malloc(sizeof(PersistFile)); + if(ptr == NULL) return NULL; + + memset(ptr, 0, sizeof(PersistFile)); + return ptr; +} + +FAREntryNode * far_add_entry(FARFile * FARFileInfo, int Position) +{ + FAREntryNode *ptr = malloc(sizeof(FAREntryNode)), *node; + if(ptr == NULL) return NULL; + memset(ptr, 0, sizeof(FAREntryNode)); + if(FARFileInfo == NULL) return ptr; + + if(Position >= 0){ + node = FARFileInfo->FirstEntry; + + if(node == NULL){ + FARFileInfo->FirstEntry = ptr; + FARFileInfo->LastEntry = ptr; + }else{ + /* Find the node we will take the place of */ + while(Position-- && node->NextEntry != NULL) + node = node->NextEntry; + + if(node->PrevEntry == NULL) + FARFileInfo->FirstEntry = ptr; + + /* Shift this node and all nodes after it above us */ + ptr->PrevEntry = node->PrevEntry; + ptr->NextEntry = node; + node->PrevEntry = ptr; + } + }else{ + node = FARFileInfo->LastEntry; + + if(node == NULL){ + FARFileInfo->FirstEntry = ptr; + FARFileInfo->LastEntry = ptr; + }else{ + /* Find the node we will take the place of */ + while(++Position && node->PrevEntry != NULL) + node = node->PrevEntry; + + if(node->NextEntry == NULL) + FARFileInfo->LastEntry = ptr; + + /* Shift this node and all nodes before it below us */ + ptr->PrevEntry = node; + ptr->NextEntry = node->NextEntry; + node->NextEntry = ptr; + } + } + + FARFileInfo->Files++; + return ptr; +} + +int far_read_header(FARFile * FARFileInfo, const uint8_t * Buffer, unsigned FileSize) +{ + if(!FileSize) FileSize = ~0; + else if(FileSize < LIBFAR_MINSIZE_ANY) + return 0; + + #ifdef LIBFAR_SUPPORT_FAR + if(FARFileInfo->Type == FAR_TYPE_FAR){ + FARFileInfo->MajorVersion = read_uint32(Buffer+8); + FARFileInfo->IndexOffset = read_uint32(Buffer+12); + + if(FARFileInfo->MajorVersion != 1 && FARFileInfo->MajorVersion != 3) + return 0; + + if(FARFileInfo->MajorVersion == 1) + FARFileInfo->Revision = !libfarOptions[LIBFAR_CONFIG_DEFAULT_TO_1A]; + + if(FARFileInfo->IndexOffset > FileSize-4) + return 0; + + FARFileInfo->Files = read_uint32(Buffer + FARFileInfo->IndexOffset); + + if(FARFileInfo->Files > (FileSize-FARFileInfo->IndexOffset) / ( + (FARFileInfo->MajorVersion == 1) ? ( + (FARFileInfo->Revision == 0) ? MINSIZE_ENTRY_FAR_1A : MINSIZE_ENTRY_FAR_1B + ) : MINSIZE_ENTRY_FAR_3) + ) return 0; + + return 1; + } + #endif + + #ifdef LIBFAR_SUPPORT_DBPF + if(FARFileInfo->Type == FAR_TYPE_DBPF){ + int i; + + FARFileInfo->MajorVersion = read_uint32(Buffer+4); + FARFileInfo->MinorVersion = read_uint32(Buffer+8); + FARFileInfo->DateCreated = read_uint32(Buffer+24); + FARFileInfo->DateModified = read_uint32(Buffer+28); + FARFileInfo->IndexMajorVersion = read_uint32(Buffer+32); + FARFileInfo->Files = read_uint32(Buffer+36); + FARFileInfo->IndexOffset = read_uint32(Buffer+40); + FARFileInfo->IndexSize = read_uint32(Buffer+44); + FARFileInfo->TrashCount = read_uint32(Buffer+48); + FARFileInfo->TrashOffset = read_uint32(Buffer+52); + FARFileInfo->TrashSize = read_uint32(Buffer+56); + FARFileInfo->IndexMinorVersion = read_uint32(Buffer+60); + + if(FARFileInfo->MajorVersion != 1) return 0; + if(FARFileInfo->MinorVersion != 0) return 0; + if(FARFileInfo->IndexMajorVersion != 7) return 0; + if(FARFileInfo->IndexMinorVersion != 0) return 0; + + for(i=12; i<24; i++) + if(Buffer[i] != 0x00) return 0; + + if(FARFileInfo->Files){ + if(FARFileInfo->Files > MAX_ENTRIES_DBPF) return 0; + if(FARFileInfo->IndexSize != FARFileInfo->Files*SIZEOF_ENTRY_DBPF) return 0; + if(FARFileInfo->IndexOffset > FileSize) return 0; + if(FARFileInfo->IndexSize > FileSize - FARFileInfo->IndexOffset) return 0; + } + if(FARFileInfo->TrashCount){ + if(FARFileInfo->TrashCount > MAX_ENTRIES_DBPF) return 0; + if(FARFileInfo->TrashSize != FARFileInfo->TrashCount*SIZEOF_ENTRY_DBPF) return 0; + if(FARFileInfo->TrashOffset > FileSize) return 0; + if(FARFileInfo->TrashSize > FileSize - FARFileInfo->TrashOffset) return 0; + } + + return 1; + } + #endif + + return 0; +} + +int far_read_entry(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, + const uint8_t * Buffer, unsigned MaxEntrySize, unsigned ArchiveSize) +{ + int MajorVersion = FARFileInfo->MajorVersion, Revision = FARFileInfo->Revision; + if(MaxEntrySize == 0) MaxEntrySize = ~0; + if(ArchiveSize == 0) ArchiveSize = ~0; + + #ifdef LIBFAR_SUPPORT_FAR + if(FARFileInfo->Type == FAR_TYPE_FAR){ + unsigned MinEntrySize = + (MajorVersion == 1) ? ( + (Revision == 0) ? MINSIZE_ENTRY_FAR_1A : MINSIZE_ENTRY_FAR_1B + ) : MINSIZE_ENTRY_FAR_3; + + if(MaxEntrySize < MinEntrySize) + return 0; + + if(MajorVersion == 1){ + FAREntryInfo->DecompressedSize = read_uint32(Buffer+0); + FAREntryInfo->CompressedSize = read_uint32(Buffer+4); + FAREntryInfo->DataOffset = read_uint32(Buffer+8); + if(Revision == 0) + FAREntryInfo->FilenameLength = read_uint32(Buffer+12); + else + FAREntryInfo->FilenameLength = read_uint16(Buffer+12); + }else if(MajorVersion == 3){ + FAREntryInfo->DecompressedSize = read_uint32(Buffer+0); + FAREntryInfo->CompressedSize = read_uint24(Buffer+4); + FAREntryInfo->DataType = read_uint8(Buffer+7); + FAREntryInfo->DataOffset = read_uint32(Buffer+8); + FAREntryInfo->HasFilename = read_uint16(Buffer+12); + FAREntryInfo->FilenameLength = read_uint16(Buffer+14); + FAREntryInfo->TypeID = read_uint32(Buffer+16); + FAREntryInfo->FileID = read_uint32(Buffer+20); + } + + if(FAREntryInfo->FilenameLength > MaxEntrySize - MinEntrySize) return 0; + if(FAREntryInfo->FilenameLength > (unsigned)libfarOptions[LIBFAR_CONFIG_MAX_FILE_NAME_LENGTH]) return 0; + + if(FAREntryInfo->CompressedSize > FAREntryInfo->DecompressedSize) return 0; + if(FAREntryInfo->DecompressedSize != 0){ + if(FAREntryInfo->DataOffset > ArchiveSize) return 0; + if(FAREntryInfo->CompressedSize > ArchiveSize - FAREntryInfo->DataOffset) return 0; + }else if(MajorVersion == 3 && FAREntryInfo->DataType != 0) return 0; + + FAREntryInfo->Filename = malloc(FAREntryInfo->FilenameLength + 1); + if(FAREntryInfo->Filename == NULL) return 0; + if(FAREntryInfo->FilenameLength != 0) + memcpy(FAREntryInfo->Filename, Buffer+MinEntrySize, FAREntryInfo->FilenameLength); + FAREntryInfo->Filename[FAREntryInfo->FilenameLength] = '\0'; + return 1; + } + #endif + + #ifdef LIBFAR_SUPPORT_DBPF + if(FARFileInfo->Type == FAR_TYPE_DBPF){ + if(MaxEntrySize < SIZEOF_ENTRY_DBPF) return 0; + + FAREntryInfo->TypeID = read_uint32(Buffer+0); + FAREntryInfo->GroupID = read_uint32(Buffer+4); + FAREntryInfo->FileID = read_uint32(Buffer+8); + FAREntryInfo->DataOffset = read_uint32(Buffer+12); + FAREntryInfo->CompressedSize = read_uint32(Buffer+16); + FAREntryInfo->DecompressedSize = FAREntryInfo->CompressedSize; + + if(FAREntryInfo->CompressedSize != 0){ + if(FAREntryInfo->CompressedSize > ArchiveSize - FAREntryInfo->DataOffset) return 0; + if(FAREntryInfo->DataOffset > ArchiveSize) return 0; + if(FAREntryInfo->CompressedSize > ArchiveSize - FAREntryInfo->DataOffset) return 0; + } + + return 1; + } + #endif + + return 0; +} + +int far_read_persist_header(PersistFile * PersistData, const uint8_t * Buffer, unsigned FileSize) +{ + RefPackParameters * Parameters; + PersistData->BodyType = read_uint8(Buffer); + PersistData->DecompressedSize = read_uint32(Buffer+1); + PersistData->CompressedSize = read_uint32(Buffer+5); + PersistData->StreamBodySize = read_uint32(Buffer+9); + PersistData->Compressor = read_uint8(Buffer+13); + + if(PersistData->BodyType != 1) + return 0; + if(PersistData->CompressedSize < FileSize-9) + return 0; + + if(PersistData->CompressedSize != PersistData->StreamBodySize) + return 0; + + PersistData->Parameters = malloc(sizeof(RefPackParameters)); + if(PersistData->Parameters == NULL) + return 0; + + Parameters = (RefPackParameters *) PersistData->Parameters; + Parameters->hnsv = read_uint8(Buffer+14); + Parameters->DecompressedSize = (Buffer[15]<<16) | (Buffer[16]<<8) | Buffer[17]; /* Big endian */ + + if((PersistData->DecompressedSize&0x00FFFFFF) != Parameters->DecompressedSize){ + free(PersistData->Parameters); return 0; + } + return 1; +} + +int far_read_entry_data(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, uint8_t * Buffer) +{ + int Compressed = (FARFileInfo->Type == FAR_TYPE_FAR) ? ( + (FARFileInfo->MajorVersion == 1) ? ( + FAREntryInfo->DecompressedSize != FAREntryInfo->CompressedSize + ) : FAREntryInfo->DataType == 0x80) : libfarOptions[LIBFAR_CONFIG_DBPF_COMPRESSED]; + + FAREntryInfo->CompressedData = Buffer+FAREntryInfo->DataOffset; + + if(!Compressed) + FAREntryInfo->DecompressedData = FAREntryInfo->CompressedData; + else{ + PersistFile * PersistInfo = &(FAREntryInfo->PersistData); + if(far_identify(FAREntryInfo->CompressedData, FAREntryInfo->CompressedSize) != FAR_TYPE_PERSIST) + return 0; + + if(!far_read_persist_header(PersistInfo, FAREntryInfo->CompressedData, FAREntryInfo->CompressedSize)) + return 0; + + /* Verify that the Persist data agrees with the entry data */ + if(PersistInfo->DecompressedSize != FAREntryInfo->DecompressedSize){ + free(PersistInfo->Parameters); return 0; + }if(PersistInfo->CompressedSize != FAREntryInfo->CompressedSize - 9){ + free(PersistInfo->Parameters); return 0; + }if(PersistInfo->Compressor != 0x10){ + free(PersistInfo->Parameters); return 0; + } + + PersistInfo->DecompressedData = FAREntryInfo->DecompressedData; + + if(!far_read_persist_data(PersistInfo, FAREntryInfo->CompressedData+18)){ + free(PersistInfo->Parameters); return 0; + } + FAREntryInfo->DecompressedData = PersistInfo->DecompressedData; + } + + return 1; +} + +int far_read_persist_data(PersistFile * PersistData, uint8_t * CompressedData) +{ + if(CompressedData != NULL) PersistData->CompressedData = CompressedData; + + PersistData->DecompressedData = malloc(PersistData->DecompressedSize); + if(PersistData->DecompressedData == NULL) + return 0; + + if(!RefPackDecompress(PersistData->CompressedData, PersistData->CompressedSize-9, + PersistData->DecompressedData, PersistData->DecompressedSize, + libfarOptions[LIBFAR_CONFIG_REFPACK_HNSV])){ + free(PersistData->DecompressedData); + return 0; + } + return 1; +} + +int far_enumerate_entries(FARFile * FARFileInfo, const uint8_t * Index, unsigned IndexSize, unsigned ArchiveSize) +{ + unsigned Files = FARFileInfo->Files; + int ArchiveType = FARFileInfo->Type; + unsigned MinEntrySize = (ArchiveType == FAR_TYPE_FAR) ? ( + (FARFileInfo->MajorVersion == 1) ? ( + (FARFileInfo->Revision == 0) ? MINSIZE_ENTRY_FAR_1A : MINSIZE_ENTRY_FAR_1B + ) : MINSIZE_ENTRY_FAR_3) : SIZEOF_ENTRY_DBPF; + unsigned EntriesAdded = 0; + FARFileInfo->Files = 0; + + if(FARFileInfo->Type == FAR_TYPE_FAR) + Index += 4; + + while(EntriesAdded < Files){ + FAREntryNode * node = far_add_entry(FARFileInfo, -1); + if(node == NULL) + return 0; + if(!far_read_entry(FARFileInfo, &(node->Entry), Index, IndexSize, ArchiveSize)){ + free(node); + return 0; + } + + EntriesAdded++; + Index += MinEntrySize; + IndexSize -= MinEntrySize; + if(ArchiveType != FAR_TYPE_DBPF){ + Index += node->Entry.FilenameLength; + IndexSize -= node->Entry.FilenameLength; + } + } + + return (EntriesAdded == FARFileInfo->Files); +} + +int far_enumerate_entry_data(const FARFile * FARFileInfo, uint8_t * Buffer) +{ + FAREntryNode * node = FARFileInfo->FirstEntry; + while(node){ + if(!far_read_entry_data(FARFileInfo, &(node->Entry), Buffer)) + return 0; + node = node->NextEntry; + } + return 1; +} + +void libfar_free(void * ptr) +{ + free(ptr); +} \ No newline at end of file diff --git a/Libraries/FileHandler/far/libfar.h b/Libraries/FileHandler/far/libfar.h new file mode 100644 index 0000000..2159add --- /dev/null +++ b/Libraries/FileHandler/far/libfar.h @@ -0,0 +1,176 @@ +/* + FileHandler - General-purpose file handling library for Niotso + libfar.h - Copyright (c) 2011 Niotso Project + Author(s): Fatbag + + 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. +*/ + +/**** +** Constants +*/ + +/* libfarOptions array members */ +#define LIBFAR_CONFIG_DEFAULT_TO_1A 0 +#define LIBFAR_CONFIG_DBPF_COMPRESSED 1 +#define LIBFAR_CONFIG_MAX_FILE_NAME_LENGTH 2 +#define LIBFAR_CONFIG_REFPACK_HNSV 3 + +/* Archive types */ +#define FAR_TYPE_INVALID 0 +#define FAR_TYPE_FAR 1 +#define FAR_TYPE_DBPF 2 +#define FAR_TYPE_PERSIST 3 + +/* Numerical constants */ +#define LIBFAR_ARCHIVE_MINIMUM_SIZE 14 +#define MINSIZE_FAR 20 +#define MINSIZE_DBPF 64 +#define MINSIZE_ENTRY_FAR_1A 16 +#define MINSIZE_ENTRY_FAR_1B 14 +#define MINSIZE_ENTRY_FAR_3 24 +#define SIZEOF_ENTRY_DBPF 20 +#define MAX_ENTRIES_FAR_1A 268435455 +#define MAX_ENTRIES_FAR_1B 306783377 +#define MAX_ENTRIES_FAR_3 178956970 +#define MAX_ENTRIES_DBPF 214748364 +#define MINSIZE_PERSIST 18 +#define MAXSIZE_REFPACK_UNCOMPRESSED 16777215 +#define MAXSIZE_REFPACK_COMPRESSED 16777215 + +/* Header bytes */ +static const uint8_t Header_FAR[] = {'F','A','R','!','b','y','A','Z'}; +static const uint8_t Header_DBPF[] = {'D','B','P','F'}; + +/**** +** Data structures +*/ + +typedef struct PersistFile_s +{ + uint8_t BodyType; + uint32_t DecompressedSize; + uint32_t CompressedSize; + uint32_t StreamBodySize; + uint8_t Compressor; + uint8_t * Parameters; + uint8_t * CompressedData; + uint8_t * DecompressedData; +} PersistFile; + +typedef struct RefPackParameters_s +{ + uint8_t hnsv; + uint32_t DecompressedSize; +} RefPackParameters; + +typedef struct FAREntry_s +{ + uint32_t DecompressedSize; + uint32_t CompressedSize; + uint8_t DataType; + uint32_t DataOffset; + uint16_t HasFilename; + uint32_t FilenameLength; + uint32_t TypeID; + uint32_t GroupID; + uint32_t FileID; + char * Filename; + PersistFile PersistData; + uint8_t * CompressedData; + uint8_t * DecompressedData; +} FAREntry; + +typedef struct FAREntryNode_s +{ + FAREntry Entry; + struct FAREntryNode_s * PrevEntry; + struct FAREntryNode_s * NextEntry; +} FAREntryNode; + +typedef struct FARFile_s +{ + int32_t Type; + + /* Header */ + uint32_t MajorVersion; + uint32_t MinorVersion; + uint32_t Revision; + uint32_t IndexOffset; + /* DBPF */ + uint32_t DateCreated; + uint32_t DateModified; + uint32_t IndexMajorVersion; + uint32_t IndexSize; + uint32_t TrashCount; + uint32_t TrashOffset; + uint32_t TrashSize; + uint32_t IndexMinorVersion; + + /* Regular index */ + uint32_t Files; + FAREntryNode * FirstEntry; + FAREntryNode * LastEntry; + struct { /* DIR index for DBPF */ + FAREntryNode * FirstEntry; + FAREntryNode * LastEntry; + } Dir; + struct { /* Trash index for DBPF */ + FAREntryNode * FirstEntry; + FAREntryNode * LastEntry; + } Trash; +} FARFile; + +/**** +** Exported functions +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +void libfar_set_option(int Option, int Value); +int libfar_get_option(int Option); + +int far_identify(const uint8_t * Buffer, unsigned FileSize); + +FARFile * far_create_archive(int Type); +PersistFile * far_create_persist(); + +FAREntryNode * far_add_entry(FARFile * FARFileInfo, int Position); + +int far_read_header(FARFile * FARFileInfo, const uint8_t * Buffer, unsigned FileSize); +int far_read_entry(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, + const uint8_t * Buffer, unsigned MaxEntrySize, unsigned ArchiveSize); +int far_read_persist_header(PersistFile * PersistData, const uint8_t * Buffer, unsigned FileSize); +int far_read_entry_data(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, uint8_t * Buffer); +int far_read_persist_data(PersistFile * PersistData, uint8_t * CompressedData); + +int far_enumerate_entries(FARFile * FARFileInfo, const uint8_t * Index, unsigned IndexSize, unsigned ArchiveSize); +int far_enumerate_entry_data(const FARFile * FARFileInfo, uint8_t * Buffer); + +FAREntryNode * far_search_id(); +FAREntryNode * far_search_name(); +FAREntryNode * far_search_multi(); + +void far_delete_entry(FARFile * FARFileInfo, int Position); +void far_delete_archive(FARFile * FARFileInfo); +void far_delete_persist(FARFile * FARFileInfo); +void libfar_free(void * ptr); + +int RefPackDecompress(const uint8_t * CompressedData, size_t CompressedSize, + uint8_t * DecompressedData, size_t DecompressedSize, unsigned HNSV); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/Libraries/FileHandler/far/libfar.svg b/Libraries/FileHandler/far/libfar.svg new file mode 100644 index 0000000..1cfb395 --- /dev/null +++ b/Libraries/FileHandler/far/libfar.svg @@ -0,0 +1,200 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Libraries/FileHandler/far/refpack_dec.c b/Libraries/FileHandler/far/refpack_dec.c new file mode 100644 index 0000000..a906bb4 --- /dev/null +++ b/Libraries/FileHandler/far/refpack_dec.c @@ -0,0 +1,167 @@ +/* + FileHandler - General-purpose file handling library for Niotso + refpack_dec.c - Copyright (c) 2011 Niotso Project + Author(s): Fatbag + + 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 +typedef unsigned char uint8_t; + +#ifndef __restrict + #define __restrict +#endif + +int RefPackDecompress(const uint8_t *__restrict CompressedData, size_t CompressedSize, + uint8_t *__restrict DecompressedData, size_t DecompressedSize, unsigned HNSV){ + unsigned datawritten = 0; + int stopflag = 0, StopFlagData; + + if(HNSV == 0) HNSV = 0xFB; /* EA default */ + if (HNSV >= 0xFF) StopFlagData = 0x1F; + else if(HNSV >= 0xFE) StopFlagData = 0x00; + else if(HNSV >= 0xFD) StopFlagData = 0x01; + else if(HNSV >= 0xFB) StopFlagData = 0x03; + else if(HNSV >= 0xF7) StopFlagData = 0x07; + else StopFlagData = 0x0F; + + while(CompressedSize > 0 && !stopflag){ + unsigned ProceedingDataLength, ReferencedDataLength, ReferencedDataOffset; + unsigned currentbyte = *(CompressedData++); + CompressedSize--; + + /**** + ** Fetch the opcode + */ + + /* The first byte determines the size of the entire opcode. */ + + if(currentbyte <= 0x7F){ /* 2 bytes */ + if(CompressedSize < 1) return 0; + CompressedSize -= 1; + + /* First byte */ + ProceedingDataLength = currentbyte & 0x03; + ReferencedDataLength = ((currentbyte & 0x1C) >> 2) + 3; + ReferencedDataOffset = (currentbyte & 0x60) << 3; + + /* Second byte */ + currentbyte = *(CompressedData++); + ReferencedDataOffset += currentbyte; + }else if(currentbyte <= 0xBF){ /* 3 bytes */ + if(CompressedSize < 2) return 0; + CompressedSize -= 2; + + /* First byte */ + ReferencedDataLength = (currentbyte & 0x3F) + 4; + + /* Second byte */ + currentbyte = *(CompressedData++); + ProceedingDataLength = (currentbyte & 0xC0) >> 6; + ReferencedDataOffset = (currentbyte & 0x3F) << 8; + + /* Third byte */ + currentbyte = *(CompressedData++); + ReferencedDataOffset += currentbyte; + }else if(currentbyte <= 0xDF){ /* 4 bytes */ + if(CompressedSize < 3) return 0; + CompressedSize -= 3; + + /* First byte */ + ProceedingDataLength = currentbyte & 0x03; + ReferencedDataLength = ((currentbyte & 0x0C) << 6) + 5; + ReferencedDataOffset = (currentbyte & 0x10) << 12; + + /* Second byte */ + currentbyte = *(CompressedData++); + ReferencedDataOffset += currentbyte << 8; + + /* Third byte */ + currentbyte = *(CompressedData++); + ReferencedDataOffset += currentbyte; + + /* Fourth byte */ + currentbyte = *(CompressedData++); + ReferencedDataLength += currentbyte; + }else{ /* 1 byte: Two different opcode types fall into this category */ + if(currentbyte <= HNSV){ + ProceedingDataLength = ((currentbyte & 0x1F) + 1) << 2; + }else{ + ProceedingDataLength = currentbyte & StopFlagData; + stopflag++; + } + ReferencedDataLength = 0; + } + + /**** + ** Copy proceeding data + */ + + if(ProceedingDataLength != 0){ + if(ProceedingDataLength > CompressedSize || ProceedingDataLength > DecompressedSize) + return 0; + + memcpy(DecompressedData, CompressedData, ProceedingDataLength); + DecompressedSize -= ProceedingDataLength; + CompressedSize -= ProceedingDataLength; + datawritten += ProceedingDataLength; + DecompressedData += ProceedingDataLength; + CompressedData += ProceedingDataLength; + } + + /**** + ** Copy referenced data + */ + + if(ReferencedDataLength != 0){ + /* It is possible that the offset specified does not provide for a large enough buffer to copy all at once from. + This event would be caused when the referenced data offset is set smaller than the referenced data length. + When this occurs, the decoder is to repeatedly copy/paste the referenced data until the length is satisfied. + We will do this in a way so that we call memcpy ceil(log2(N)) times instead of N times. */ + + ReferencedDataOffset++; + if(ReferencedDataLength > DecompressedSize || ReferencedDataOffset > datawritten) + return 0; + + DecompressedSize -= ReferencedDataLength; + datawritten += ReferencedDataLength; + + if(ReferencedDataOffset == 1){ + memset(DecompressedData, *(DecompressedData-1), ReferencedDataLength); + DecompressedData += ReferencedDataLength; + }else{ + unsigned copylength = + (ReferencedDataOffset < ReferencedDataLength) ? ReferencedDataOffset : ReferencedDataLength; + uint8_t *__restrict copysource = DecompressedData; + + memcpy(DecompressedData, DecompressedData-ReferencedDataOffset, copylength); + DecompressedData += copylength; + ReferencedDataLength -= copylength; + + while(ReferencedDataLength){ + if(copylength > ReferencedDataLength) + copylength = ReferencedDataLength; + + memcpy(DecompressedData, copysource, copylength); + DecompressedData += copylength; + ReferencedDataLength -= copylength; + + if(!(copylength&0x80000000)) copylength <<= 1; + } + } + } + } + + return (!stopflag || CompressedSize || DecompressedSize) ? 0 : 1; +} \ No newline at end of file diff --git a/Libraries/FileHandler/hit/evt.c b/Libraries/FileHandler/hit/evt.c new file mode 100644 index 0000000..30c2af4 --- /dev/null +++ b/Libraries/FileHandler/hit/evt.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + evt.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/hit/hit.c b/Libraries/FileHandler/hit/hit.c new file mode 100644 index 0000000..f6605b8 --- /dev/null +++ b/Libraries/FileHandler/hit/hit.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + hit.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/hit/hot.c b/Libraries/FileHandler/hit/hot.c new file mode 100644 index 0000000..e64b182 --- /dev/null +++ b/Libraries/FileHandler/hit/hot.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + hot.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/hit/hsm.c b/Libraries/FileHandler/hit/hsm.c new file mode 100644 index 0000000..1603dc4 --- /dev/null +++ b/Libraries/FileHandler/hit/hsm.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + hsm.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/iff/CMakeLists.txt b/Libraries/FileHandler/iff/CMakeLists.txt index 515dbee..290b800 100644 --- a/Libraries/FileHandler/iff/CMakeLists.txt +++ b/Libraries/FileHandler/iff/CMakeLists.txt @@ -2,10 +2,12 @@ cmake_minimum_required(VERSION 2.6) project(iff) set(IFF_SOURCES + cats.c iff.c bcon.c rsmp.c str.c + string.c trcn.c ) @@ -17,7 +19,7 @@ set_target_properties(iff_static PROPERTIES #### Shared library (uncomment to build) #add_library(iff_shared SHARED ${IFF_SOURCES}) -#set_target_properties(libiff_shared PROPERTIES +#set_target_properties(iff_shared PROPERTIES # OUTPUT_NAME "iff" # PREFIX "" # CLEAN_DIRECT_OUTPUT 1) diff --git a/Libraries/FileHandler/iff/bcon.c b/Libraries/FileHandler/iff/bcon.c index fce2bdc..d4d7807 100644 --- a/Libraries/FileHandler/iff/bcon.c +++ b/Libraries/FileHandler/iff/bcon.c @@ -1,5 +1,8 @@ /* - bcon.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + bcon.c - Copyright (c) 2012 Niotso Project + Author(s): Ahmed El-Mahdawy + Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -33,14 +36,12 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){ BCONData->Flags = read_uint8le(Buffer + 1); if(BCONData->ConstantCount == 0) return 1; - if(BCONData->ConstantCount * 2 /* bytes */ > Size - 2){ + if(BCONData->ConstantCount * 2 /* bytes */ > Size - 2) return 0; - } - + BCONData->Constants = malloc(BCONData->ConstantCount * sizeof(uint16_t)); - if(BCONData->Constants == NULL){ + if(BCONData->Constants == NULL) return 0; - } Buffer += 2; for(i=0; iConstantCount; i++, Buffer += 2) diff --git a/Libraries/FileHandler/iff/bhav.c b/Libraries/FileHandler/iff/bhav.c new file mode 100644 index 0000000..b3a8988 --- /dev/null +++ b/Libraries/FileHandler/iff/bhav.c @@ -0,0 +1,18 @@ +/* + FileHandler - General-purpose file handling library for Niotso + bhav.c - Copyright (c) 2012 Niotso Project + Author(s): Ahmed El-Mahdawy + Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/iff/cats.c b/Libraries/FileHandler/iff/cats.c new file mode 100644 index 0000000..50786e0 --- /dev/null +++ b/Libraries/FileHandler/iff/cats.c @@ -0,0 +1,55 @@ +/* + FileHandler - General-purpose file handling library for Niotso + cats.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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 "iff.h" + +int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){ + IFFStringPair * StringData; + unsigned Size = ChunkInfo->Size - 76; + int s; + + ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair)); + if(ChunkInfo->FormattedData == NULL) + return 0; + StringData = (IFFStringPair*) ChunkInfo->FormattedData; + + for(s=0; s<2; s++){ + unsigned length; + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; + + if(length != 0){ + char ** string = (s==0) ? &StringData->Key : &StringData->Value; + *string = malloc(length+1); + if(*string == NULL) return 0; + strcpy(*string, (char*) Buffer); + + Buffer += length; + Size -= length; + } + Buffer++; Size--; + } + + return 1; +} + +void iff_free_cats(void * FormattedData){ + IFFStringPair * StringData = (IFFStringPair*) FormattedData; + free(StringData->Key); + free(StringData->Value); +} \ No newline at end of file diff --git a/Tools/misc/CMakeLists.txt b/Libraries/FileHandler/iff/fcns.c similarity index 100% rename from Tools/misc/CMakeLists.txt rename to Libraries/FileHandler/iff/fcns.c diff --git a/Libraries/FileHandler/iff/glob.c b/Libraries/FileHandler/iff/glob.c new file mode 100644 index 0000000..e69de29 diff --git a/Libraries/FileHandler/iff/iff.c b/Libraries/FileHandler/iff/iff.c index 07d9afb..a32739f 100644 --- a/Libraries/FileHandler/iff/iff.c +++ b/Libraries/FileHandler/iff/iff.c @@ -1,5 +1,8 @@ /* - iff.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + iff.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + Ahmed El-Mahdawy Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -26,24 +29,31 @@ int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize); int iff_free_rsmp(void * FormattedData); - -/* The order of these chunks must remain the same throughout this block: */ iff_register(bcon); iff_register(str); +iff_register(cats); +iff_register(c_string); iff_register(trcn); +/* The ordering of these chunk types must match throughout this block: */ const char chunktypes[] = - "STR#" "CTSS" "FAMs" "TTAs" + "STR#" "CTSS" "FAMs" "TTAs" "CST\0" + "CATS" + "FWAV" "BCON" "TRCN" ; int (* const iff_parse_function[])(IFFChunk*, const uint8_t*) = { - iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str, + iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str, + iff_parse_cats, + iff_parse_c_string, iff_parse_bcon, iff_parse_trcn }; void (* const iff_free_function[])(void*) = { - iff_free_str, iff_free_str, iff_free_str, iff_free_str, + iff_free_str, iff_free_str, iff_free_str, iff_free_str, iff_free_str, + iff_free_cats, + NULL, iff_free_bcon, iff_free_trcn }; @@ -58,7 +68,7 @@ IFFFile * iff_create() { IFFFile *ptr = calloc(1, sizeof(IFFFile)); if(ptr == NULL) return NULL; - + ptr->Chunks = malloc(sizeof(IFFChunk)); if(ptr->Chunks == NULL){ free(ptr); @@ -94,13 +104,12 @@ IFFChunk * iff_add_chunk(IFFFile * IFFFileInfo) if(IFFFileInfo->SizeAllocated > SIZE_MAX/2) return NULL; ptr = realloc(IFFFileInfo->Chunks, IFFFileInfo->SizeAllocated<<1); if(ptr == NULL) return NULL; - + IFFFileInfo->Chunks = ptr; IFFFileInfo->SizeAllocated<<=1; } - IFFFileInfo->ChunkCount++; - return IFFFileInfo->Chunks + IFFFileInfo->ChunkCount-1; + return &IFFFileInfo->Chunks[IFFFileInfo->ChunkCount++]; } int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize) @@ -126,6 +135,7 @@ int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChu return 0; memcpy(ChunkInfo->Data, Buffer+76, ChunkInfo->Size - 76); } + ChunkInfo->FormattedData = NULL; return 1; } @@ -150,7 +160,7 @@ int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){ for(i=0; chunktypes[i*4] != '\0'; i++){ if(!memcmp(ChunkInfo->Type, chunktypes+i*4, 4)){ if(iff_parse_function[i](ChunkInfo, Buffer)) return 1; - iff_free_chunk(ChunkInfo->FormattedData); + iff_free_chunk(ChunkInfo); return 0; } } @@ -159,13 +169,14 @@ int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){ void iff_free_chunk(IFFChunk * ChunkInfo){ unsigned i; - if(ChunkInfo == NULL || ChunkInfo->FormattedData) return; + if(ChunkInfo == NULL || ChunkInfo->FormattedData == NULL) return; for(i=0; chunktypes[i*4] != '\0'; i++){ if(!memcmp(ChunkInfo->Type, chunktypes+i*4, 4)){ if(iff_free_function[i]) iff_free_function[i](ChunkInfo->FormattedData); free(ChunkInfo->FormattedData); + ChunkInfo->FormattedData = NULL; return; } } diff --git a/Libraries/FileHandler/iff/iff.h b/Libraries/FileHandler/iff/iff.h index 7ed7bb5..32e86ec 100644 --- a/Libraries/FileHandler/iff/iff.h +++ b/Libraries/FileHandler/iff/iff.h @@ -1,5 +1,8 @@ /* - iff.h - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + iff.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + Ahmed El-Mahdawy Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -120,29 +123,29 @@ typedef struct IFF_STR_s { int16_t Format; IFFLanguageSet LanguageSets[20]; -} IFF_STR; +} IFFString; /* TRCN chunk */ -typedef struct IFFRangePair_s +typedef struct IFFRangeEntry_s { uint32_t IsUnused; - uint32_t Unknown; - char * Key; - char * Value; + uint32_t DefaultValue; + char * Name; + char * Comment; uint8_t Enforced; uint16_t RangeMin; uint16_t RangeMax; -} IFFRangePair; +} IFFRangeEntry; -typedef struct IFF_TRCN_s +typedef struct IFFRangeSet_s { uint32_t Reserved; uint32_t Version; char MagicNumber[5]; - uint32_t EntryCount; - IFFRangePair * Entries; -} IFF_TRCN; + uint32_t RangeCount; + IFFRangeEntry * Ranges; +} IFFRangeSet; #ifdef __cplusplus extern "C" { diff --git a/Libraries/FileHandler/iff/iffexport.c b/Libraries/FileHandler/iff/iffexport.c index 0ba77d4..78cdb3a 100644 --- a/Libraries/FileHandler/iff/iffexport.c +++ b/Libraries/FileHandler/iff/iffexport.c @@ -1,5 +1,7 @@ /* - iffexport.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + iffexport.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -133,7 +135,8 @@ int main(int argc, char *argv[]){ while((c = strchr(c, filter[i])) != NULL) *c = '.'; } - sprintf(destination, "%s/%s.%s", OutDirectory, name, (!memcmp(ChunkData->Type, "BMP_", 4)) ? "bmp" : "dat"); + sprintf(destination, "%s/%s.%s", OutDirectory, name, + (!memcmp(ChunkData->Type, "BMP_", 4) || !memcmp(ChunkData->Type, "FBMP", 4)) ? "bmp" : "dat"); hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); diff --git a/Libraries/FileHandler/iff/rsmp.c b/Libraries/FileHandler/iff/rsmp.c index 23fd8f0..02e0e44 100644 --- a/Libraries/FileHandler/iff/rsmp.c +++ b/Libraries/FileHandler/iff/rsmp.c @@ -1,5 +1,7 @@ /* - rsmp.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + rsmp.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/iff/str.c b/Libraries/FileHandler/iff/str.c index 94740ff..6d50f73 100644 --- a/Libraries/FileHandler/iff/str.c +++ b/Libraries/FileHandler/iff/str.c @@ -1,5 +1,8 @@ /* - str.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + str.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + Ahmed El-Mahdawy Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -17,23 +20,23 @@ #include "iff.h" int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ - IFF_STR * StringData; + IFFString * StringData; unsigned Size = ChunkInfo->Size - 76; if(Size < 2) return 0; - ChunkInfo->FormattedData = calloc(1, sizeof(IFF_STR)); + ChunkInfo->FormattedData = calloc(1, sizeof(IFFString)); if(ChunkInfo->FormattedData == NULL) return 0; - - StringData = (IFF_STR*) ChunkInfo->FormattedData; + + StringData = (IFFString*) ChunkInfo->FormattedData; StringData->Format = read_int16le(Buffer); if((Size-=2) < 2) /* TSO allows this; as seen in the animations chunk in personglobals.iff */ return 1; Buffer += 2; - + switch(StringData->Format){ - + case 0: { /* 00 00 */ unsigned i; IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0]; @@ -69,23 +72,22 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ case -1: { /* FF FF */ unsigned i; IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0]; - + LanguageSet->PairCount = read_uint16le(Buffer); Buffer += 2; Size -= 2; if(LanguageSet->PairCount == 0) return 1; - + LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair)); if(LanguageSet->Pairs == NULL) return 0; - + for(i=0; iPairCount; i++){ unsigned length; - if(Size == 0) return 0; - for(length=0; Size-length && Buffer[length]; length++); - if(Buffer[length] != 0x00) return 0; - + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; + if(length != 0){ LanguageSet->Pairs[i].Key = malloc(length+1); if(LanguageSet->Pairs[i].Key == NULL) return 0; @@ -101,25 +103,24 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ case -2: { /* FE FF */ unsigned i; IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0]; - + LanguageSet->PairCount = read_uint16le(Buffer); Buffer += 2; Size -= 2; if(LanguageSet->PairCount == 0) return 1; - + LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair)); if(LanguageSet->Pairs == NULL) return 0; - + for(i=0; iPairCount; i++){ int s; for(s=0; s<2; s++){ unsigned length; - if(Size == 0) return 0; - for(length=0; Size-length && Buffer[length]; length++); - if(Buffer[length] != 0x00) return 0; - + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; + if(length != 0){ char ** string = (s==0) ? &LanguageSet->Pairs[i].Key : &LanguageSet->Pairs[i].Value; *string = malloc(length+1); @@ -144,7 +145,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(TotalPairCount == 0) return 1; - + /* ** Scan through the chunk to count up the number of strings in each LanguageSet, ** and then allocate exactly that much and fill in the data on the second pass @@ -158,30 +159,29 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(lang >= 20) return 0; LanguageSet[lang].PairCount++; Buffer++; Size--; - + for(s=0; s<2; s++){ /* Includes the string length check too */ unsigned length; - if(Size == 0) return 0; - for(length=0; Size-length && Buffer[length]; length++); - if(Buffer[length] != 0x00) return 0; + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; Buffer += length+1; Size -= length+1; } } - + for(i=0; i<20; i++){ LanguageSet[i].Pairs = calloc(LanguageSet[i].PairCount, sizeof(IFFStringPair)); if(LanguageSet[i].Pairs == NULL) return 0; } - + /* 2nd pass */ Buffer = Start; for(i=0; i 20) return 0; - + for(lang=0; langLanguageSets[lang]; - + if(Size < 2) return 0; LanguageSet->PairCount = read_uint16le(Buffer); Buffer += 2; Size -= 2; @@ -216,12 +216,12 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair)); if(LanguageSet->Pairs == NULL) return 0; - + for(i=0; iPairCount; i++){ unsigned s; if(Size == 0) return 0; Buffer++; Size--; /* Skip over the "Language set index" */ - + for(s=0; s<2; s++){ unsigned length; if(Size == 0) return 0; @@ -248,7 +248,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ } } } return 1; - + } return 0; @@ -261,9 +261,9 @@ void iff_free_str(void * FormattedData){ ** - If the Pairs pointer is nonzero, there must be PairCount initialized pairs in Pairs */ - IFF_STR * StringData = (IFF_STR*) FormattedData; + IFFString * StringData = (IFFString*) FormattedData; unsigned ls; - + for(ls=0; ls<20; ls++){ IFFLanguageSet * LanguageSet = &StringData->LanguageSets[ls]; unsigned p; diff --git a/Libraries/FileHandler/iff/string.c b/Libraries/FileHandler/iff/string.c new file mode 100644 index 0000000..38a83e2 --- /dev/null +++ b/Libraries/FileHandler/iff/string.c @@ -0,0 +1,38 @@ +/* + FileHandler - General-purpose file handling library for Niotso + string.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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 "iff.h" + +int iff_parse_c_string(IFFChunk * ChunkInfo, const uint8_t * Buffer){ + char ** string = (char**) &ChunkInfo->FormattedData; + unsigned Size = ChunkInfo->Size - 76; + unsigned length; + + if(Size == 0) + return 0; + + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; + + if(length > 0){ + *string = malloc(length+1); + if(*string == NULL) return 0; + strcpy(*string, (char*) Buffer); + } + return 1; +} \ No newline at end of file diff --git a/Libraries/FileHandler/iff/tprp.c b/Libraries/FileHandler/iff/tprp.c new file mode 100644 index 0000000..e69de29 diff --git a/Libraries/FileHandler/iff/trcn.c b/Libraries/FileHandler/iff/trcn.c index 16f545a..7f71fc7 100644 --- a/Libraries/FileHandler/iff/trcn.c +++ b/Libraries/FileHandler/iff/trcn.c @@ -1,5 +1,8 @@ /* - trcn.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + trcn.c - Copyright (c) 2012 Niotso Project + Author(s): Ahmed El-Mahdawy + Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -17,39 +20,105 @@ #include "iff.h" int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){ - return 0; /* - IFF_TRCN * TRCNData; + IFFRangeSet *RangeSet; unsigned Size = ChunkInfo->Size - 76; unsigned i; - + if(Size < 16) return 0; - ChunkInfo->FormattedData = malloc(sizeof(IFF_TRCN)); + ChunkInfo->FormattedData = malloc(sizeof(IFFRangeSet)); if(ChunkInfo->FormattedData == NULL) return 0; - - TRCNData = (IFF_TRCN*) ChunkInfo->FormattedData; - TRCNData->Reserved = read_uint32le(Buffer+0); - TRCNData->Version = read_uint32le(Buffer+4); - memcpy(TRCNData->MagicNumber, Buffer+8, 4); - TRCNData->MagicNumber[4] = 0x00; - TRCNData->EntryCount = read_uint32le(Buffer+12); - - if(TRCNData->Reserved != 0 || TRCNData->Version > 2 || strcmp(TRCNData->MagicNumber, "NCRT")){ - free(TRCNData); + + RangeSet = (IFFRangeSet*) ChunkInfo->FormattedData; + RangeSet->Ranges = NULL; + RangeSet->Reserved = read_uint32le(Buffer); + RangeSet->Version = read_uint32le(Buffer+4); + memcpy(RangeSet->MagicNumber, Buffer+8, 4); + RangeSet->MagicNumber[4] = 0x00; + RangeSet->RangeCount = read_uint32le(Buffer+12); + if(RangeSet->Version > 2) return 0; - } - ChunkInfo->FormattedData = malloc(TRCNData->EntryCount * sizeof(IFFRangePair)); - if(ChunkInfo->FormattedData == NULL){ - free(TRCNData); + if(RangeSet->RangeCount == 0) + return 1; + + RangeSet->Ranges = calloc(RangeSet->RangeCount, sizeof(IFFRangeEntry)); + if(RangeSet->Ranges == NULL) return 0; + + Buffer += 16; Size -= 16; + for(i=0; iRangeCount; i++){ + unsigned s; + IFFRangeEntry * Range = &RangeSet->Ranges[i]; + if(Size < 10) + return 0; + + Range->IsUnused = read_uint32le(Buffer); + Range->DefaultValue = read_uint32le(Buffer+4); + Buffer += 8; Size -= 8; + + for(s=0; s<2; s++){ + char ** string = (s==0) ? &Range->Name : &Range->Comment; + unsigned length; + if(Size == 0) return 0; + + if(RangeSet->Version < 2){ + /* C string */ + for(length=0; length != Size && Buffer[length]; length++); + if(length == Size) return 0; + + if(length != 0){ + *string = malloc(length+1); + if(*string == NULL) return 0; + strcpy(*string, (char*) Buffer); + } + + Buffer += length+1; + Size -= length+1; + + /* Skip past the 0xA3 character; + ** see global.iff chunk 546 for why you can't do modulo-2 to detect this */ + if(Size && *Buffer == 0xA3){ + Buffer++; Size--; + } + }else{ + /* Pascal string */ + length = read_uint8le(Buffer); + Buffer++; Size--; + + if(length != 0){ + *string = malloc(length+1); + if(*string == NULL) return 0; + memcpy(*string, Buffer, length); + (*string)[length] = 0x00; + } + + Buffer += length; + Size -= length; + } + } + + if(RangeSet->Version != 0){ + if(Size < 5) return 0; + Range->Enforced = read_uint8le(Buffer); + Range->RangeMin = read_uint16le(Buffer+1); + Range->RangeMax = read_uint16le(Buffer+3); + Buffer += 5; Size -= 5; + } } - - Buffer += 16; - for(i=0; iEntryCount; i++){ - } */ + + return 1; } void iff_free_trcn(void * FormattedData){ - /*IFF_TRCN *TRCNData = (IFF_TRCN*) FormattedData;*/ + IFFRangeSet *RangeSet = (IFFRangeSet*) FormattedData; + if(RangeSet->Ranges){ + unsigned i; + for(i=0; iRangeCount; i++){ + IFFRangeEntry *Entry = &RangeSet->Ranges[i]; + free(Entry->Name); + free(Entry->Comment); + } + } + free(RangeSet->Ranges); } \ No newline at end of file diff --git a/Libraries/FileHandler/iff/ttab.c b/Libraries/FileHandler/iff/ttab.c new file mode 100644 index 0000000..e69de29 diff --git a/Libraries/FileHandler/ini/read_ini.c b/Libraries/FileHandler/ini/read_ini.c index e69de29..da8eed1 100644 --- a/Libraries/FileHandler/ini/read_ini.c +++ b/Libraries/FileHandler/ini/read_ini.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + read_ini.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/tga/read_tga.c b/Libraries/FileHandler/tga/read_tga.c index e69de29..01fb27d 100644 --- a/Libraries/FileHandler/tga/read_tga.c +++ b/Libraries/FileHandler/tga/read_tga.c @@ -0,0 +1,17 @@ +/* + FileHandler - General-purpose file handling library for Niotso + read_tga.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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. +*/ \ No newline at end of file diff --git a/Libraries/FileHandler/tga/read_tga.h b/Libraries/FileHandler/tga/read_tga.h deleted file mode 100644 index e79bb09900949211d7915fa22cdd1dd816d9cf63..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7291 zcma)B2|SeD_a9sKHEV>XkY$WL#=a}E?;^|$M$8N|_BB~r>|2t(sEAS|vJ2TF^xCo~ z2_ajS^q(Ow`Pc9B-uaAqp7WgZz31F}pX+|l(bpy-W&{Ap001JLScpxN7!@A?0Kk87 zB7iHx6^`{m!|l*$7X;J}i$Ed4o=BK5$_|6T2&2$&Bn$=haD^kW!dSRBR{u9Joc+J; z1nx=|g>*nTdbsbxV8p-}tR2<^V{hjU-m@bkBinTXZ$$XZ67R@SJ3A;8?gGcbpxnVw z4|jKb@7}I1L;!tlQoPgu8vorL)<3{HxS;H?@O@|YM+A?z-~JQ?8in>i;|9RvR}g=) zw1dR$PDZ65(p+2*-d`5Lj0`H0H=W z^<;lGXv0m^AO!$Gi8F?xkl0^yk!#w591@|cS{Ec{`W)pjSE7_NNJGI$LU=}Af+ki_ z)lkYnSm3OJQZ$rc;MA{IKRMyYOZbm%VHYnR$x5N@6Mm?QM?^-Ym-o5Yxc z%VYVK7J;b+6%Hw;YU8H*2m;gY3eh}7omK0YDLtV*!bamfWz0hTY)+k7_U*?} z_448ukGSV5kloh0i8c*0tE-Y!&-v}r&=(7Ql<2AWA1I_;?P+0LGgk(kxSQGhiND2E z&Pd+!1ngZwe(Jn0R@0@AsC$gM`<~zFV7)fK^G&zc<3C=yI_HqZYqmIYF+6kY6%_0w zDwW)vp%o^1MFT9JgQ+$Y$o)d@b}bz1$ii~jj>GZuS8MMFcXA=uCcVa4-O?D%CP42v zkQ65gy9!Y~z29xf#FbL&q|$7`dj-dTHj|L&Uw3 zi}k&ev^r*m7B^L#6YHh#-yx>0J+Aur1JR1?ao^VIUPR=#>O!OVi0{}w{SG;Lx63lz zkyg0{dCvKfC+|+zwhPBtl+U4V_QQ|ys?H;+^iS&$WT)JnlKc7{COpwUU3}Ke=^k-v za@f$IyqZY$g5!nn1fzv@j5P?eZ8xWl@J#SSgHKzOmn4!KZ(NBXy&{kSjlQgB{bs-L#KeP^afN@oHZcl5mqNK%TR-z@@tM z$Ha*EKH;0RdS3`hZSvZF;y0DUD}8TMA;i6Rj!%0PxVZEgyh#CoWBdRB?lk~lus$wu z41PNrw$zRplA^0#H)Ew3WCsn+2J}arJ4?Yx9b2N5kVa&g<08etADhUvv3fE-N3A8k z@bv&^nkoQO?GqsGe`9O2f3zJTBf~}hQYiO%f!B|hTVwch4r;P`Fa_61Y zl0{=~Mv8>phvcb6E8S_yWhx3$dCJoq-^$a#7N^Yw^3hE(vfTWf>ju}1EYALNZ0?Gn zyS{3YUQl7Facr@9sD>p8hsn!Ix<|^523m$W=`CnTMmWt~`ml(m2gQL}kKg>GMwNF= z(BIIce2D7n_2ImTRHs{wV z%p@*rV@v`x*f*VKmhDU;t9${0t8gqV88M&@bqk=IjhGCn)` zLw)UD5TFAxw;h5J4ssozvlVep`NzBDR3sTi7*lT5i8v!B<=KU&S-w@3jDskEwk)Ch z^8h zm3&xDpAx$tRlAX_akU}2#z5HCo=iPEdu607(TZbPo^UJvEY_SPVab}<&66w!lpPYr zR;Qp5+wMmE>g=Gqa*fJo>Gxd&Jr;|)5%lRQc7rsfzJ&8nExO}XIQ{ZpyvfjJNW1W4 zM25LvVlB@N z20u&rTzVmMbQ^XlR#-!NS}E5@*duc#!n)4m1K$8+Jb+rq?7ei1ck8%XmKuTV`FdBi z_`oo&2hS^8Pw`Ml(XND%IRKw~gUJg+YzdkkKQgCWHQ?rnFuXL~c_V0*eY|k58XVVVJ(eF~Pl36L z;Cs5%zA($|x^_PLoJ~-mrl|ampXXh{)1eWKTfHc0-F#hX?LOh|Q0qiT1qQpt{EBskK zW_5iHb-izlRXJ7};U=9jDYHC8!Y3^%6R^%E^1az+Es+iv-;e-z&PcC)3INlJ=nuCU zoQu%unIKZAubm$FxSZPDjPYLs`LQuSdeJ48@DPo{nC zP5avQ9(jdU?b(>JmxC*n>lGLZD;ZG_SuO3E_$m%V<6MXxI<+9P{ zLeZCvn>4!XC+E~h6PoYPTr6$5>e?ebiS_75#rT*IYAeF{ZQ-+dY{(-oX&>_Goz&K~n;wIJ16GK+h z6#MrUaZ2InD_3emiUX?eBL&R0IwKQA-SG)BGKe))N_ zJh|lhix3t^Ur0HB{z6lN&w3yZ!&tUX(m3J)OG|uE6H^@eIGlW#vEHAM%Y@L_Chqv# zq@7`tn}|Eb0dI!JOSm@~Tu9S%R?dphvQ|e|$;`6QxOU2S%=$-YYMFmv;hv}Iy3-fg zOOGv|sahYJ)>{U76h9ojQqj*J)hqOQFj=e>Xt$H4$+c5iX0x7WwbRS>sg5^Ff4SIf zncUhp^ox`NO=ahEL>GZ`fPz@OeAMb_O*`*oSjTJf7oo@(zSZC+T1R)GbU+w|oAN1^ zOU!pEc|=T7f*<%>&S{ozgvJ=({cQ?(t@|S-mQ(MOerj)T376QLjP&%>-*Q+l-n#L zMIjaUUl7l-@GPHR5nnx~NBzFgYw$`gcf+%120ntMrMb^zR07*=VthfPVqBg-*(R5R zen0d}8=9x@5CH)A?=GQ%W9{(&o#hm9f4Dv2?id`Ukq3$jivYRdNGJ-1Ksw3;O^h`_ z(m+K83OSU60|E+%?6VvYjt<#z<4lnl$lfD)pocpWvdf1cNIO?J27-k`4ih8DVQt86 zM|%=)7X zD#-0ZL*3!KWDf+xF)IZegbYYT0wgMBEGh~S7lVk12}?=Hf&ZYoXAXxUu(0LXs7)L`?y{x zci2%G)Cs2z#j)Lk2Vey`7!>lCiINf)!^OD&d@nc;49*+|cR(QFu)PTI>t7yt9_fJM z76sz)cEkFgYGVIQP5i&9N#NCfEm8=+^Mkv8XJS|Ud%hvG@7g_o+}Zs*j?3Z+x3QCl zt3A>V;er8U_b-LfNXJ>KMa=Y6{Di%&?bzxHnw+rPij9?(O}an$@srk1Wo)b|Ykn2d z;l}Mgeu&e2*9bbVQu{0ZRQ%CBgY8nSoM^b~6_pU!D)u;2Mw{2$-Q6@U1~uB65T2LZ z)*F4S@BT>)03_o$ zJQbdWz_IujXP1YRT3BHQA#{O?HNZ(P!t#;_b_|g4M9vcotlS-G)#QEz>2EA!&X9gz zcjQs!or-60k&o-|9x2(HFZ;IIrw-J$Q9?w2LL76?b4q)$bg55L zmsc*tH_{+ESb~YVsf!^%Whl33`UxsTrv)O`;bHxZ7(1-yp`%<>_I|XeNEW`45H|L0 zgExgO;h%!{8~%Zi8fkUO!VGI`Ym?!j)o!w>P(50cq$hy|6!e#w2B^zLbq9P3JuNzZ z((0OORFil3beT8X%?D2U=5qghgeJNX)zR{$SaP11J86}LX1VVn$*Z*=)zf^1v`kOw z^XfLEEb>;uwU0|U_q}%|kIKU0%H)d+NsQQs4j*45OMVtOn20ZO%XUoWML^wyIzLWO9y2EvJX z^Lbt2vWQj{5bZ5*z7Y`x?bxg`OpkQe#LGZFqH^ z2YBW~Y1T|4KvjBSYUkdu>a3ZJj5fFIgr!7kbvvYX=rc8B3tQPcSe|{RhBU=kbl<(+ znVYoid1+8c?4jpSps8&4W;AC=@EfHMrYmD)JzjGDl!99}Phy?d3BO#ASnt|a&P&OT z-i~uP(d3rNFJ+(D(U7Rl+;X9LLxJEvTQCpR(;FFZ7%ubhLeJy;wePpDU0+pAj#RFi z)FE)S&bbtWXm2m7E`8fbcy%-RzQcfHAmpoYPKcD*U@UuAHgRI!>45NC{nv8xN#56= zG06fs3Y{FeG#36bIG9U%g#9HU@+04fX=q36{g9nCW4?gokY~Q(w$C~|&BOVOztK$l zCXf?^#hA+|3aKt8HVWDdnmLiZ;LrSOTmC2v@!fymWBenyzI+!fB7}3!nr%>{w1ufv zK;*c?v1P{9#AMKYoA7#Vtd`uv^qHMHqxSKrXoCnbBn5A#B*`$)`qquJ$BX1QFMQX( zAfel^Q;j}T=@HjRWGi~1IO+2gcL)zb!H%Me87YWPLH8~;z^cnlo44X)97{EQ-Xn7b zXZ^DFr{5aOK#hwQXw@}B#pR)-3>WfVh0i4>->k<{ZVbI|jOCG17*y6AediOADn8H& zgNa>+vr;G|C043lLvTq3>2)kU=wXnfUKK1PhpUxRFD2yU=7W-p$~Uh=1&wY-xA2yd zXl%*8)={@IPq?hb5qz7mpiA;g8X1GBB}a-t@>{H?XZc9l-8S?jGgnuMxw9Ba+072W z$)8v~%lt9rJJ+5Oyj=kJqaT?p`1W(M(<&14-Rocu3)T1gNA8$pNSIH~^6YsE!S}(m zypOZ_CX%Mtm3TEqwC=xpwIoS7Bh20)xVdp7ams&;^$l0v?8N-mJQY`J_9;{Iz%CnW zOFqjl&3vQ`L|Ful70f5@2_@WOkG5(uNX$SkkN zZCC22UVxUj7BFjYgLI~c~)iA7|YrFE%UUhL!{uAVID7!*&a8K zQO(t+-So}j?eX`G6CR>9s73$)*x^z*Ot_8nqPnp%=)A55*wqe+aDZcW6U(JZ+Q$Z%I;{~<+qlj}QbI>iDnx`GU#m~BDIAc@WvRbz|Y#xBL-$~l!G&P;4?2mQ!2lV+Q z2}wIw7ojwId<}+ctEBX&!4+@pQ?2u(Mpk{bmN?jjN#gH^%CfbM;@>jf|hG)ia4@s+(SxSn;+ zhJi7Jl*{lD1MxyG@=VxNJ2F=&z7F>xF*b5@~I^G*E zma%ds#!z2~EcIo{__0!Bzmt9oD;E453W`lDTyj}&`I^>yjKn%z?xh{_d*uz1oNZkj zqgM=y87-@P_$=Dt!PeI%AY=smz3_mWi$iU{3~|)zkO}~woIhw6ahFF^?uY9Qd%gdy z;&6Zy_6MB5)F1wrbNFM$LHmHaJnGy*_2Kt{Ij{m836TM}ZjYiIu15SF2VajkXczv3 z^ILV|??}JL75WFHgKEWpMXC4$%0czw?0mmO4Jo8%Z?jTZO$ieutlyMF&4_}*+- diff --git a/Libraries/FileHandler/uis/uis.c b/Libraries/FileHandler/uis/uis.c index 7e88e4d..818b0fa 100644 --- a/Libraries/FileHandler/uis/uis.c +++ b/Libraries/FileHandler/uis/uis.c @@ -1,5 +1,7 @@ /* - uis.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + uis.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/uis/uis.h b/Libraries/FileHandler/uis/uis.h index c686335..345bcb1 100644 --- a/Libraries/FileHandler/uis/uis.h +++ b/Libraries/FileHandler/uis/uis.h @@ -1,5 +1,7 @@ /* - uis.h - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + uis.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/utk/CMakeLists.txt b/Libraries/FileHandler/utk/CMakeLists.txt index 4cef8ba..041261d 100644 --- a/Libraries/FileHandler/utk/CMakeLists.txt +++ b/Libraries/FileHandler/utk/CMakeLists.txt @@ -5,5 +5,5 @@ set(UTK_SOURCES read_utk.c utkdecode.c ) - + add_executable(utkdecode ${UTK_SOURCES}) \ No newline at end of file diff --git a/Libraries/FileHandler/utk/read_utk.c b/Libraries/FileHandler/utk/read_utk.c index f3aa953..f73ec00 100644 --- a/Libraries/FileHandler/utk/read_utk.c +++ b/Libraries/FileHandler/utk/read_utk.c @@ -1,5 +1,7 @@ /* - read_utk.c - Copyright (c) 2011-2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_utk.c - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/utk/read_utk.h b/Libraries/FileHandler/utk/read_utk.h index bf8be51..149a092 100644 --- a/Libraries/FileHandler/utk/read_utk.h +++ b/Libraries/FileHandler/utk/read_utk.h @@ -1,5 +1,7 @@ /* - read_utk.h - Copyright (c) 2011-2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_utk.h - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/utk/utkdecode.c b/Libraries/FileHandler/utk/utkdecode.c index 20768d3..6df3657 100644 --- a/Libraries/FileHandler/utk/utkdecode.c +++ b/Libraries/FileHandler/utk/utkdecode.c @@ -1,5 +1,7 @@ /* - utkdecode.c - Copyright (c) 2011-2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + utkdecode.c - Copyright (c) 2011-2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -108,7 +110,7 @@ int main(int argc, char *argv[]){ } UTKGenerateTables(); - + BeginningTime = GetTickCount(); if(!utk_decode(UTKData+32, WaveData+44, UTKHeader.Frames)){ printf("%sMemory for this file could not be allocated.", "utkdecode: error: "); diff --git a/Libraries/FileHandler/wav/read_wav.c b/Libraries/FileHandler/wav/read_wav.c index ea4ad27..b89a523 100644 --- a/Libraries/FileHandler/wav/read_wav.c +++ b/Libraries/FileHandler/wav/read_wav.c @@ -1,5 +1,7 @@ /* - read_wav.c - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_wav.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -44,16 +46,16 @@ int wav_read_header(wavheader_t * WAVHeader, const uint8_t * Buffer, size_t File WAVHeader->wBitsPerSample = read_uint16(Buffer+34); WAVHeader->DataID = read_uint32(Buffer+36); WAVHeader->DataSize = read_uint32(Buffer+40); - + if(WAVHeader->sID != 0x46464952 || WAVHeader->Size != FileSize-8 || WAVHeader->DataType != 0x45564157 || WAVHeader->FmtID != 0x20746D66 || WAVHeader->FmtSize != 16 || WAVHeader->wFormatTag != WAVE_FORMAT_PCM || - WAVHeader->nChannels < 1 || WAVHeader->nChannels > 2 || WAVHeader->nSamplesPerSec == 0 || + WAVHeader->nChannels < 1 || WAVHeader->nChannels > 2 || WAVHeader->nSamplesPerSec == 0 || (WAVHeader->nSamplesPerSec%8000 != 0 && WAVHeader->nSamplesPerSec%11025 != 0) || WAVHeader->nSamplesPerSec > 48000 || WAVHeader->nAvgBytesPerSec != WAVHeader->nSamplesPerSec * WAVHeader->nBlockAlign || WAVHeader->nBlockAlign != WAVHeader->nChannels * WAVHeader->wBitsPerSample >> 3 || (WAVHeader->wBitsPerSample != 8 && WAVHeader->wBitsPerSample != 16) || WAVHeader->DataID != 0x61746164 || WAVHeader->DataSize != FileSize - 44 || WAVHeader->DataSize % WAVHeader->nBlockAlign != 0 ) return 0; - + return 1; } \ No newline at end of file diff --git a/Libraries/FileHandler/wav/read_wav.h b/Libraries/FileHandler/wav/read_wav.h index cbaddf6..ebdcb8e 100644 --- a/Libraries/FileHandler/wav/read_wav.h +++ b/Libraries/FileHandler/wav/read_wav.h @@ -1,5 +1,7 @@ /* - read_wav.h - Copyright (c) 2012 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_wav.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/FileHandler/xa/read_xa.c b/Libraries/FileHandler/xa/read_xa.c index 7568109..b113351 100644 --- a/Libraries/FileHandler/xa/read_xa.c +++ b/Libraries/FileHandler/xa/read_xa.c @@ -1,5 +1,7 @@ /* - read_xa.c - Copyright (c) 2011 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_xa.c - Copyright (c) 2011 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -49,8 +51,8 @@ unsigned xa_compressed_size(unsigned Frames, unsigned Channels) unsigned SingleChannelData = (((Frames+1)>>1) + (Frames+27)/28); - if(Frames > 0xFFFFFFFFu-27) return 0; - if(0xFFFFFFFFu/SingleChannelData < Channels) return 0; + if(Frames > UINT_MAX-27) return 0; + if(UINT_MAX/SingleChannelData < Channels) return 0; return Channels*SingleChannelData; } @@ -86,7 +88,7 @@ int xa_read_header(xaheader_t * XAHeader, const uint8_t * Buffer, size_t FileSiz return 1; } -__inline int16_t Clip16(int sample) +static __inline int16_t Clip16(int sample) { if(sample>=32767) return 32767; else if(sample<=-32768) return -32768; @@ -99,7 +101,7 @@ typedef struct { int c1, c2; /* predictor coefficients */ } channel_t; -const int XATable[] = +static const int16_t XATable[] = { 0, 240, 460, 392, 0, 0, -208, -220, @@ -110,11 +112,11 @@ const int XATable[] = int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, unsigned Frames, unsigned Channels) { - channel_t * Channel = malloc(Channels * sizeof(channel_t)); - if(!Channel) return 0; - memset(Channel, 0x00, Channels * sizeof(channel_t)); + channel_t Channel[8]; + memset(Channel, 0x00, sizeof(Channel)); + if(Frames == 0) return 1; - while(Frames){ + while(1){ unsigned i; for(i=0; i=0; n-=4){ + int NewValue = byte >> n; NewValue = (NewValue << 28) >> Channel[j].divisor; NewValue = (NewValue + Channel[j].CurSample*Channel[j].c1 + Channel[j].PrevSample*Channel[j].c2 + 128) >> 8; Channel[j].PrevSample = Channel[j].CurSample; Channel[j].CurSample = Clip16(NewValue); } - *(OutBuffer++) = (Channel[j].PrevSample&0x00FFu)>>(8*0); - *(OutBuffer++) = (Channel[j].PrevSample&0xFF00u)>>(8*1); + *(OutBuffer++) = Channel[j].PrevSample>>(8*0); + *(OutBuffer++) = Channel[j].PrevSample>>(8*1); } - if(!--Frames) break; + if(!--Frames) return 1; for(j=0; j>(8*0); - *(OutBuffer++) = (Channel[j].CurSample&0xFF00u)>>(8*1); + *(OutBuffer++) = Channel[j].CurSample>>(8*0); + *(OutBuffer++) = Channel[j].CurSample>>(8*1); } - if(!--Frames) break; + if(!--Frames) return 1; } } - - free(Channel); - return 1; } \ No newline at end of file diff --git a/Libraries/FileHandler/xa/read_xa.h b/Libraries/FileHandler/xa/read_xa.h index c529479..b74cda2 100644 --- a/Libraries/FileHandler/xa/read_xa.h +++ b/Libraries/FileHandler/xa/read_xa.h @@ -1,5 +1,7 @@ /* - read_xa.h - Copyright (c) 2011 Fatbag + FileHandler - General-purpose file handling library for Niotso + read_xa.h - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/COPYING b/Libraries/libvitaboy/COPYING index 0b7b942..c2bc33e 100644 --- a/Libraries/libvitaboy/COPYING +++ b/Libraries/libvitaboy/COPYING @@ -1,4 +1,6 @@ -libfar - Copyright (c) 2011-2012 Fatbag +libvitaboy - Open source OpenGL TSO character animation library +Version 1.0.1 +Copyright (c) 2012 Niotso Project Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/Renderer.cpp b/Libraries/libvitaboy/Renderer.cpp index 0b14c3f..21206d1 100644 --- a/Libraries/libvitaboy/Renderer.cpp +++ b/Libraries/libvitaboy/Renderer.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + Renderer.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/anim.cpp b/Libraries/libvitaboy/anim.cpp index 5c01cb2..576608f 100644 --- a/Libraries/libvitaboy/anim.cpp +++ b/Libraries/libvitaboy/anim.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + anim.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/apr.cpp b/Libraries/libvitaboy/apr.cpp index 4795e6a..2671be8 100644 --- a/Libraries/libvitaboy/apr.cpp +++ b/Libraries/libvitaboy/apr.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + apr.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/bnd.cpp b/Libraries/libvitaboy/bnd.cpp index 137c001..757901f 100644 --- a/Libraries/libvitaboy/bnd.cpp +++ b/Libraries/libvitaboy/bnd.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + bnd.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/col.cpp b/Libraries/libvitaboy/col.cpp index f9d40c0..323f1ef 100644 --- a/Libraries/libvitaboy/col.cpp +++ b/Libraries/libvitaboy/col.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + col.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/libvitaboy.cpp b/Libraries/libvitaboy/libvitaboy.cpp index c729cc1..60edbdb 100644 --- a/Libraries/libvitaboy/libvitaboy.cpp +++ b/Libraries/libvitaboy/libvitaboy.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + libvitaboy.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/libvitaboy.hpp b/Libraries/libvitaboy/libvitaboy.hpp index 4dc46b1..9f47f74 100644 --- a/Libraries/libvitaboy/libvitaboy.hpp +++ b/Libraries/libvitaboy/libvitaboy.hpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + libvitaboy.hpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -21,7 +23,6 @@ #include #include #include -#include #include class VBFile_t { @@ -84,7 +85,7 @@ class VBFile_t { inline char* readstring(){ //Read a Pascal string with 1 length byte unsigned length = readint8(); - char *string = (char*) malloc((length+1) * sizeof(char)); + char *string = (char*) malloc(length+1); readbytes(string, length); string[length] = '\0'; return string; @@ -93,7 +94,7 @@ class VBFile_t { inline char* readstring2(){ //Read a Pascal string with 2 length bytes unsigned length = readint16(); - char *string = (char*) malloc((length+1) * sizeof(char)); + char *string = (char*) malloc(length+1); readbytes(string, length); string[length] = '\0'; return string; @@ -288,7 +289,7 @@ struct Vertex_t { Coord_t Coord; TextureCoord_t TextureCoord; NormalCoord_t NormalCoord; - + unsigned BoneIndex; BlendData_t BlendData; }; diff --git a/Libraries/libvitaboy/mesh.cpp b/Libraries/libvitaboy/mesh.cpp index 8c20e88..8067510 100644 --- a/Libraries/libvitaboy/mesh.cpp +++ b/Libraries/libvitaboy/mesh.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + mesh.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -87,7 +89,7 @@ void ReadMesh(Mesh_t& Mesh){ Mesh.TransformedVertexData[i].BlendData.OtherVertex = BlendData[i-Mesh.RealVertexCount].OtherVertex; } } - + free(TextureVertexData); free(BlendData); } \ No newline at end of file diff --git a/Libraries/libvitaboy/oft.cpp b/Libraries/libvitaboy/oft.cpp index 1adc25b..5093e6e 100644 --- a/Libraries/libvitaboy/oft.cpp +++ b/Libraries/libvitaboy/oft.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + oft.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/po.cpp b/Libraries/libvitaboy/po.cpp index 5381456..47af4e3 100644 --- a/Libraries/libvitaboy/po.cpp +++ b/Libraries/libvitaboy/po.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + po.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/skel.cpp b/Libraries/libvitaboy/skel.cpp index beade7f..2d3c7ab 100644 --- a/Libraries/libvitaboy/skel.cpp +++ b/Libraries/libvitaboy/skel.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + skel.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Libraries/libvitaboy/vbparse.cpp b/Libraries/libvitaboy/vbparse.cpp index b1661db..d35cccf 100644 --- a/Libraries/libvitaboy/vbparse.cpp +++ b/Libraries/libvitaboy/vbparse.cpp @@ -1,5 +1,7 @@ /* - libvitaboy - Copyright (c) 2012 Fatbag + libvitaboy - Open source OpenGL TSO character animation library + vbparse.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Server/NiotsoServer.cpp b/Server/Server.cpp similarity index 79% rename from Server/NiotsoServer.cpp rename to Server/Server.cpp index 47d0e44..028bfe5 100644 --- a/Server/NiotsoServer.cpp +++ b/Server/Server.cpp @@ -1,5 +1,8 @@ /* - Niotso Server - Copyright (C) 2012 Fatbag + Niotso Server - Niotso daemon based on PostgreSQL + Server.cpp + Copyright (c) 2012 Niotso Project + Author(s): Fatbag 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 diff --git a/Tools/CMakeLists.txt b/Tools/CMakeLists.txt index 52d6fc0..2681bdf 100644 --- a/Tools/CMakeLists.txt +++ b/Tools/CMakeLists.txt @@ -1,3 +1,3 @@ add_subdirectory(FARDive) -add_subdirectory(iff2html) -add_subdirectory(misc) \ No newline at end of file +add_subdirectory(hitutils) +add_subdirectory(iff2html) \ No newline at end of file diff --git a/Tools/TSOSimulatorClient/TSOSimulatorClient.cpp b/Tools/TSOSimulatorClient/TSOSimulatorClient.cpp index 6bda85e..d2ff4aa 100644 --- a/Tools/TSOSimulatorClient/TSOSimulatorClient.cpp +++ b/Tools/TSOSimulatorClient/TSOSimulatorClient.cpp @@ -1,5 +1,7 @@ /* - TSOSimulatorClient.cpp - Copyright (c) 2012 Fatbag + TSOSimulatorClient - TSOSimulatorClientD.dll injector + iff2html.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Tools/hitutils/CMakeLists.txt b/Tools/hitutils/CMakeLists.txt new file mode 100644 index 0000000..e093aba --- /dev/null +++ b/Tools/hitutils/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.6) +project(hitutils) + +set(HITDUMP_SOURCES + hitdump.cpp +) + +set(HITASM_SOURCES + hitasm.cpp +) + +set(HITLD_SOURCES + hitld.cpp +) + +add_executable(hitdump ${HITDUMP_SOURCES}) +add_executable(hitasm ${HITASM_SOURCES}) +add_executable(hitld ${HITLD_SOURCES}) \ No newline at end of file diff --git a/Tools/hitutils/hitasm.cpp b/Tools/hitutils/hitasm.cpp new file mode 100644 index 0000000..0aab3ae --- /dev/null +++ b/Tools/hitutils/hitasm.cpp @@ -0,0 +1,32 @@ +/* + hitutils - The Sims HIT (dis)assembler and linker + hitasm.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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 + +int main(){ + printf("Usage: hitasm [-f] [-o outfile.o] infile.txt\n" + "Compile a HIT source file to an intermediary object file\n" + "which can be linked using hitld.\n" + "\n" + "Use -f to force overwriting without confirmation.\n" + "\n" + "Report bugs to .\n" + "hitutils is maintained by the Niotso project.\n" + "Home page: \n"); + return 0; +} \ No newline at end of file diff --git a/Tools/hitutils/hitdump.cpp b/Tools/hitutils/hitdump.cpp new file mode 100644 index 0000000..306be50 --- /dev/null +++ b/Tools/hitutils/hitdump.cpp @@ -0,0 +1,35 @@ +/* + hitutils - The Sims HIT (dis)assembler and linker + hitdump.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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 + +int main(){ + printf("Usage: hitdump [-f] [-o outfile.txt] [-hsm outfile.hsm]\n" + " [-hot outfile.hot] infile.hit\n" + "Disassemble a HIT binary.\n" + "\n" + "The HSM and HOT files associated with the HIT file are required\n" + "as inputs; their paths default to same base name as the input\n" + "file but can be changed with the above options.\n" + "Use -f to force overwriting without confirmation.\n" + "\n" + "Report bugs to .\n" + "hitutils is maintained by the Niotso project.\n" + "Home page: \n"); + return 0; +} \ No newline at end of file diff --git a/Tools/hitutils/hitld.cpp b/Tools/hitutils/hitld.cpp new file mode 100644 index 0000000..fc48086 --- /dev/null +++ b/Tools/hitutils/hitld.cpp @@ -0,0 +1,35 @@ +/* + hitutils - The Sims HIT (dis)assembler and linker + hitld.cpp - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + 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 + +int main(){ + printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n" + " outfile.hit INFILES\n" + "Link object files produced by hitasm into a HIT binary.\n" + "\n" + "The HSM and HOT files associated with the HIT file are required\n" + "for modification; their paths are normally defined by one of the\n" + "linked objects but can be forced using the above options.\n" + "Use -f to force overwriting without confirmation.\n" + "\n" + "Report bugs to .\n" + "hitutils is maintained by the Niotso project.\n" + "Home page: \n"); + return 0; +} \ No newline at end of file diff --git a/Tools/iff2html/iff2html.c b/Tools/iff2html/iff2html.c index d625f3d..abf72b0 100644 --- a/Tools/iff2html/iff2html.c +++ b/Tools/iff2html/iff2html.c @@ -1,5 +1,8 @@ /* - iff2html.c - Copyright (c) 2012 Fatbag + iff2html - iff web page description generator + iff2html.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + Ahmed El-Mahdawy Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -140,7 +143,7 @@ int main(int argc, char *argv[]){ printf("%sChunk data is corrupt.", "iff2html: error: "); return -1; } - + /* Calculate the MD5, and then we can free the IFF data because we're done with it */ MD5Init(&md5c); MD5Update(&md5c, IFFData, FileSize); @@ -269,7 +272,6 @@ int main(int argc, char *argv[]){ fprintf(hFile, "\n"); for(i=1, ChunkData = IFFFileInfo->Chunks; i <= IFFFileInfo->ChunkCount; i++, ChunkData++){ - IFF_STR * StringData = (IFF_STR*) ChunkData->FormattedData; fprintf(hFile, "

%u [%s] (%.4X)%s%s (Jump)

\n", i, ChunkData->ChunkID, i, ChunkData->Type, ChunkData->ChunkID, (ChunkData->Label[0] != 0x00) ? " – " : "", ChunkData->Label, @@ -281,11 +283,13 @@ int main(int argc, char *argv[]){ }else if(!strcmp(ChunkData->Type, "STR#") || !strcmp(ChunkData->Type, "CTSS") || !strcmp(ChunkData->Type, "FAMs") || - !strcmp(ChunkData->Type, "TTAs") ){ + !strcmp(ChunkData->Type, "TTAs") || + !strcmp(ChunkData->Type, "CST") ){ /**** ** STR# parsing */ + IFFString * StringData = ChunkData->FormattedData; fprintf(hFile, "\n"); fprintf(hFile, "
Format:"); switch(StringData->Format){ @@ -346,23 +350,71 @@ int main(int argc, char *argv[]){ fprintf(hFile, "
\n"); } + }else if(!strcmp(ChunkData->Type, "CATS")){ + /**** + ** CATS parsing + */ + + IFFStringPair * Pair = ChunkData->FormattedData; + + fprintf(hFile, "\n"); + fprintf(hFile, "\n"); + fprintf(hFile, "\n", + (Pair->Key) != NULL ? Pair->Key : "", + (Pair->Value) != NULL ? Pair->Value : ""); + fprintf(hFile, "
KeyValue
%s%s
\n"); + }else if(!strcmp(ChunkData->Type, "FWAV")){ + /**** + ** Regular string + */ + + fprintf(hFile, "\n"); + fprintf(hFile, "\n"); + fprintf(hFile, "\n", ChunkData->FormattedData ? (char*) ChunkData->FormattedData : ""); + fprintf(hFile, "
String
%s
\n"); }else if(!strcmp(ChunkData->Type, "BCON")){ /**** ** BCON parsing */ - - IFF_BCON * BCONData = (IFF_BCON*) ChunkData->FormattedData; + + IFF_BCON * BCONData = ChunkData->FormattedData; fprintf(hFile, "\n"); fprintf(hFile, "\n", BCONData->Flags, BCONData->Flags); fprintf(hFile, "
Flags:%02X (%d)
\n"); if(BCONData->ConstantCount > 0){ - unsigned ConstantIndex; + unsigned i; fprintf(hFile, "
\n"); fprintf(hFile, "\n"); fprintf(hFile, "\n"); - for(ConstantIndex=0; ConstantIndexConstantCount; ConstantIndex++) - fprintf(hFile, "\n", ConstantIndex+1, BCONData->Constants[ConstantIndex]); + for(i=0; iConstantCount; i++) + fprintf(hFile, "\n", i+1, BCONData->Constants[i]); + fprintf(hFile, "
Constant Value
%u%u
%u%u
\n"); + } + }else if(!strcmp(ChunkData->Type, "TRCN")){ + /**** + ** TRCN parsing + */ + + IFFRangeSet * RangeSet = ChunkData->FormattedData; + fprintf(hFile, "\n"); + fprintf(hFile, "\n", RangeSet->Version); + fprintf(hFile, "
Version:%u
\n"); + if(RangeSet->RangeCount > 0){ + unsigned i; + IFFRangeEntry * Range; + + fprintf(hFile, "
\n"); + fprintf(hFile, "\n"); + fprintf(hFile, "" + "\n"); + for(i=0, Range=RangeSet->Ranges; iRangeCount; i++, Range++) + fprintf(hFile, "\n", + Range->IsUnused ? "No" : "Yes", Range->DefaultValue, + Range->Name ? Range->Name : "", + Range->Comment ? Range->Comment : "", + Range->Enforced ? "Yes" : "No", + Range->RangeMin, Range->RangeMax); fprintf(hFile, "
Used yetDefault valueNameCommentRange is enforcedMinimumMaximum
%s%u%s%s%s%u%u
\n"); } } @@ -377,7 +429,7 @@ int main(int argc, char *argv[]){ fprintf(hFile, "\n"); fprintf(hFile, ""); fclose(hFile); - + printf("Wrote contents to '%s'.\n", OutFile); return 0; } \ No newline at end of file diff --git a/Tools/iff2html/iff2html.html b/Tools/iff2html/iff2html.html deleted file mode 100644 index c083e4e..0000000 --- a/Tools/iff2html/iff2html.html +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - -behavior.iff (iff2html) - - - -

behavior.iff

-
-
9809b96803833f2891ddd31e474795a9 (md5), 42.4kB (43,446 bytes)
-
Dumped by iff2html.
- - - -

1 [STR#] (00DD) – neighbor data labels (Jump)

-
- - -
Format:FC FF (−4)

- - - - - - - - - - - - - -
LanguageString pairs
English (US)1person instance id4
2belongs in house4
3person age4
4relationship raw score4
5relationship score4
6friend count4
7house number4
8has telephone4
9has baby4
10family friend count4
-
- -

2 [STR#] (00EA) – build mode types (Jump)

-
- - -
Format:FC FF (−4)

- - - - - - - - - - - -
LanguageString pairs
English (US)1none4
2door4
3window4
4stair4
5plant4
6fireplace4
7column4
8pool equipment4
-
- - - - \ No newline at end of file diff --git a/Tools/iff2html/md5.c b/Tools/iff2html/md5.c index ade8389..328fd57 100644 --- a/Tools/iff2html/md5.c +++ b/Tools/iff2html/md5.c @@ -107,7 +107,7 @@ void MD5Update(ctx, buf, len) } /* - * Final wrapup - pad to 64-byte boundary with the bit pattern + * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ void MD5Final(digest, ctx) diff --git a/Tools/iff2html/md5.h b/Tools/iff2html/md5.h index 4c048cf..98d6343 100644 --- a/Tools/iff2html/md5.h +++ b/Tools/iff2html/md5.h @@ -9,7 +9,7 @@ the byteReverse function in md5.c must be invoked. However, byteReverse is coded in such a way that it is an identity function when run on a little-endian machine, so calling it - on such a platform causes no harm apart from wasting time. + on such a platform causes no harm apart from wasting time. If the platform is known to be little-endian, we speed things up by undefining HIGHFIRST, which defines byteReverse as a null macro. Doing things in this manner diff --git a/Tools/tsoscan/tsoscan.txt b/Tools/tsoscan/tsoscan.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tools/zbuffer/Instructions.txt b/Tools/zbuffer/Instructions.txt index 77b87c7..4e8e6ea 100644 --- a/Tools/zbuffer/Instructions.txt +++ b/Tools/zbuffer/Instructions.txt @@ -5,4 +5,7 @@ Add these files: * Chair-Liv-Deco_large_front_z.png * tower_large_ne_a.png * tower_large_ne_p.png -* tower_large_ne_z.png \ No newline at end of file +* tower_large_ne_z.png + +Then open index.html in a web browser which supports the HTML5 canvas, +and use the arrow keys. \ No newline at end of file