diff --git a/Utils/MkActor/MkActor.cpp b/Utils/MkActor/MkActor.cpp new file mode 100644 index 000000000..d70f6e4ef --- /dev/null +++ b/Utils/MkActor/MkActor.cpp @@ -0,0 +1,649 @@ +/*************************/ +/*** Actor Sprite Tool ***/ +/*************************/ + +#include "stdio.h" +#include +#include +#include +#include +#include +#include + +#include "MkActor.h" + +#include + +using namespace std; + +//*************************************************************************** +vector ActorList; +int TPBase=-1,TPWidth=-1,TPHeight=-1; +GString TPOutStr; + +GString RootPath; +GString SpritePath; +GString OutPath; +GString IncludePath; + +//*************************************************************************** + +char * CycleCommands(char *String,int Num) +{ +char Text[2048],*TextPtr; +int Count; + + if (String[0]=='-' || String[0]=='/') + { + GString TpStr; + switch (String[1]) + { + // Switches + case 'o': + OutPath = CheckFileString(String); + OutPath.Upper(); + OutPath.Append('\\'); + break; + case 'i': + IncludePath = CheckFileString(String); + IncludePath.Upper(); + IncludePath.Append('\\'); + break; + case 'd': + DebugOn =true; + break; + case 's': + SpritePath=CheckFileString(String); + SpritePath.Upper(); + SpritePath.Append('\\'); + break; + case 'r': + RootPath=CheckFileString(String); + RootPath.Upper(); + RootPath.Append('\\'); + break; + case 't': + TpStr= CheckFileString(String); + TextPtr=Text; + strcpy(TextPtr,TpStr); + Count=ZeroAndCountCommas(TextPtr); + if (Count!=2) GObject::Error(ERR_FATAL,"Problem with option %s\n",String); + TPBase=atol(TextPtr); + TextPtr+=strlen(TextPtr)+1; + TPWidth=atol(TextPtr); + TextPtr+=strlen(TextPtr)+1; + TPHeight=atol(TextPtr); + break; + default: + GObject::Error(ERR_FATAL,"Unknown switch %s",String); + break; + } + } + else + { + GString Name=String; + Name.Upper(); + ActorList.push_back(CMkActor(Name,RootPath,SpritePath)); + } + + return(String); +} + +//*************************************************************************** + +void Usage(char *ErrStr) +{ + printf("\nMkActor (usese scripts): by Dave\n"); + printf("Usage: MkActor [ .. ] [ switches.. ]\n"); + printf("Switches:\n"); + printf(" -o:[FILE] Set output Dir\n"); + printf(" -p:nn Root Dir\n"); + printf(" -s:nn Sprite Dir\n"); + printf(" -t:p,w,h Set TPage No,Width,Height\n"); + printf(" -d: Enable Debug output\n"); + GObject::Error(ERR_FATAL,ErrStr); +} + +//*************************************************************************** +int main (int argc, char *argv[]) +{ +int i,ListSize; + + CommandLine(argc,argv,CycleCommands); + if (OutPath.Empty()) Usage("No Output File Set\n"); + + ListSize=ActorList.size(); + for (i=0; i &List) +{ +char *Script,*Ptr; +int Size; + + File=fopen(Filename,"rb"); + if (!File) return; + fseek(File,0,SEEK_END); + Size=ftell(File); + fseek(File,0,SEEK_SET); + Script=(char*)malloc(Size+1); + ASSERT(Script); + // Load It + fread(Script,Size,1,File); + fclose(File); + +// Extract Names + Ptr=Script; + Script[Size]=0; + while (*Ptr) + { + GString Str; + + while (*Ptr=='\n' || *Ptr=='\r'|| *Ptr==' ') *Ptr++; // Skip gaff + if (*Ptr) + { + if (*Ptr=='#') + { // Skip commented lines + while (*Ptr!='\n' && *Ptr) Ptr++; + } + else + { // Read data + while (*Ptr!=' ' && *Ptr!='\n' && *Ptr!='\r' && *Ptr) + { + Str.Append(*Ptr++); + } + List.push_back(Str); + } + } + } + + free(Script); +} + +//*************************************************************************** +void CMkActor::BuildFrameList() +{ +int i,ListSize=InAnimList.size(); +char AnimName[256]; + AnimList.resize(ListSize); + for (i=0; i&Bmp.Psx[nfAreaBytes]) printf("!"); + if ((x&1)) + { + *PixAddr&=0x0f; + *PixAddr|=ScrNib<<4; + } + else + { + *PixAddr&=0xf0; + *PixAddr|=ScrNib; + } + } + } +} + +//*************************************************************************** +int CMkActor::LoadBmp(GString &Name,bool VRamFlag) +{ +GString Filename=SpriteDir+Name; + +int Idx,i,ListSize; +int W,H,Size; +sBmp NewBmp; +Frame &Bmp=NewBmp.Bmp; + + NewBmp.Filename=Filename; + NewBmp.RGB=0; + NewBmp.Pak=0; + NewBmp.Psx=0; + NewBmp.VRamFlag=VRamFlag; + Bmp.LoadBMP(Filename); + W=Bmp.GetWidth(); + H=Bmp.GetHeight(); + Size=W*H; + NewBmp.RGB=(u8*)malloc(Size*3); + ASSERT(NewBmp.RGB); + Bmp.MakeRGB(NewBmp.RGB); + +#if _DEBUG && 0 + { +u8 *TGA=(u8*)malloc(Size*3); + ASSERT(TGA); + Bmp.FlipY(); + Bmp.MakeRGB(TGA); + Bmp.FlipY(); + + char OutName[256]; + sprintf(OutName,"\\x\\%s.tga",Name); + SaveTGA(OutName,W,H,TGA,true); + free(TGA); + } +#endif + +// Gen Chksum +u8 *RGB=NewBmp.RGB; + NewBmp.ChkR=NewBmp.ChkG=NewBmp.ChkB=0; + for (i=0; i OutPal; + + PsxPalette=PCPalette; + PsxPalette.SetPlusColZero(true); + + Count=PsxPalette.GetNumOfCols(); + FileHdr.ColorCount=Count; + PsxPalette.MakePSXPal(OutPal); + for (i=0; i Out; + +// Write Dummy Hdrs + FileHdr.AnimCount=ListSize; + Out.resize(ListSize); + for (i=0; i Out; + +// Write Dummy Hdrs + FileHdr.FrameCount=ListSize; + Out.resize(ListSize); + for (i=0; i +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=MkActor - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "MkActor.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "MkActor.mak" CFG="MkActor - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "MkActor - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "MkActor - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "MkActor - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\texgrab" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib texgrab.lib maths.lib davelib.lib /nologo /subsystem:console /machine:I386 /out:"..\..\tools\data\bin\MkActor.exe" /libpath:"..\libs\psxlib\release" /libpath:"..\libs\ginlib\release" /libpath:"..\libs\glib\release" /libpath:"..\libs\davelib\release" /libpath:"..\libs\texgrab\release" /libpath:"..\libs\maths\release" + +!ELSEIF "$(CFG)" == "MkActor - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\texgrab" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib texgrab.lib maths.lib davelib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libs\psxlib\debug" /libpath:"..\libs\ginlib\debug" /libpath:"..\libs\glib\debug" /libpath:"..\libs\davelib\debug" /libpath:"..\libs\texgrab\debug" /libpath:"..\libs\maths\debug" + +!ENDIF + +# Begin Target + +# Name "MkActor - Win32 Release" +# Name "MkActor - Win32 Debug" +# Begin Source File + +SOURCE=.\MkActor.cpp +# End Source File +# Begin Source File + +SOURCE=.\MkActor.h +# End Source File +# End Target +# End Project diff --git a/Utils/MkActor/MkActor.h b/Utils/MkActor/MkActor.h new file mode 100644 index 000000000..603d39665 --- /dev/null +++ b/Utils/MkActor/MkActor.h @@ -0,0 +1,81 @@ +/*************************/ +/*** Actor Sprite Tool ***/ +/*************************/ + +#include +#include + +//*************************************************************************** +struct sFrame +{ + GString Filename; + int FrameIdx; +}; + +//*************************************************************************** +struct sAnim +{ + GString Name; + vector Frames; + bool VRamFlag; +}; + +//*************************************************************************** +struct sBmp +{ + GString Filename; + Frame Bmp; + int ChkR,ChkG,ChkB; + u8 *RGB; + u8 *Psx; + u8 *Pak; + int PsxSize; + int PakSize; + bool VRamFlag; +}; + +//*************************************************************************** +class CMkActor +{ +public: + CMkActor(GString &ActorName,GString &ActorPath,GString &SpritePath); +// ~CMkActor(); + +static void SetTPData(const char *Name,int TPBase,int TPW,int TPH); + + void Load(); + void Process(); + void Write(); + void CleanUp(); + +private: + void ReadScript(const char *Filename,vector &List); + void BuildFrameList(); + void FindFrames(sAnim &ThisAnim); + + void LoadFrameList(); + void LoadFrame(sFrame &ThisFrame,bool VRamFlag); + int LoadBmp(GString &Name,bool VRamFlag); + bool IsImageSame(sBmp &Bmp0,sBmp &Bmp1); + void MakePsxGfx(sBmp &Bmp); + void ProcessFrames(); + + int WritePalette(); + int WriteAnimList(); + int WriteFrameList(); + + void WriteInclude(); + GString Name,ActorDir,SpriteDir; + GString OutFile,IncFile; + + FILE *File; + sSpriteAnimBank FileHdr; + + vector InAnimList; + vector AnimList; + vector BmpList; + CTexGrab TexGrab; + int DupCount; +}; + +//***************************************************************************