Browse Source

Initial code commit.

Updated README.
master
atom0s 6 years ago
parent
commit
a01c269236
  1. 244
      FFXIEncryption.h
  2. BIN
      FFxiMapLib.rc
  3. 22
      FFxiMapLib.sln
  4. 106
      FFxiMapLib.vcxproj
  5. 38
      FFxiMapLib.vcxproj.filters
  6. 4
      FFxiMapLib.vcxproj.user
  7. 81
      Include/MapLib.h
  8. 282
      MapLib.cpp
  9. 81
      MapLib.h
  10. 6
      README.md
  11. 14
      resource.h

244
FFXIEncryption.h

@ -0,0 +1,244 @@ @@ -0,0 +1,244 @@
#pragma once
#ifndef _FFXIENCRYPTION_H_
#define _FFXIENCRYPTION_H_
#include <Windows.h>
#include <complex>
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#define RBUFP(p,pos) (((uint8*)(p)) + (pos))
#define RBUFB(p,pos) (*(uint8*)RBUFP((p),(pos)))
#define RBUFW(p,pos) (*(uint16*)RBUFP((p),(pos)))
#define RBUFL(p,pos) (*(uint32*)RBUFP((p),(pos)))
#define RBUFF(p,pos) (*(float*)RBUFP((p),(pos)))
#define WBUFP(p,pos) (((uint8*)(p)) + (pos))
#define WBUFB(p,pos) (*(uint8*)WBUFP((p),(pos)))
#define WBUFW(p,pos) (*(uint16*)WBUFP((p),(pos)))
#define WBUFL(p,pos) (*(uint32*)WBUFP((p),(pos)))
#define WBUFF(p,pos) (*(float*)WBUFP(
namespace FFXIEncryption
{
#pragma pack(push,1)
typedef struct
{
char id[16];
float fTransX,fTransY,fTransZ;
float fRotX,fRotY,fRotZ;
float fScaleX,fScaleY,fScaleZ;
float fa,fb,fc,fd;
long fe,ff,fg,fh,fi,fj,fk,fl;
} OBJINFO;
static BYTE key_table[0x100] =
{
0xE2, 0xE5, 0x06, 0xA9, 0xED, 0x26, 0xF4, 0x42, 0x15, 0xF4, 0x81, 0x7F, 0xDE, 0x9A, 0xDE, 0xD0,
0x1A, 0x98, 0x20, 0x91, 0x39, 0x49, 0x48, 0xA4, 0x0A, 0x9F, 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, 0xC7, 0x65, 0x18, 0xCE, 0xF2, 0xA3, 0x68, 0xFE, 0x35, 0x96, 0x95,
0xA6, 0xFA, 0x58, 0x63, 0x41, 0x59, 0xEA, 0xDD, 0x7F, 0xD3, 0x1B, 0xA8, 0x48, 0x44, 0xAB, 0x91,
0xFD, 0x13, 0xB1, 0x68, 0x01, 0xAC, 0x3A, 0x11, 0x78, 0x30, 0x33, 0xD8, 0x4E, 0x6A, 0x89, 0x05,
0x7B, 0x06, 0x8E, 0xB0, 0x86, 0xFD, 0x9F, 0xD7, 0x48, 0x54, 0x04, 0xAE, 0xF3, 0x06, 0x17, 0x36,
0x53, 0x3F, 0xA8, 0x11, 0x53, 0xCA, 0xA1, 0x95, 0xC2, 0xCD, 0xE6, 0x1F, 0x57, 0xB4, 0x7F, 0xAA,
0xF3, 0x6B, 0xF9, 0xA0, 0x27, 0xD0, 0x09, 0xEF, 0xF6, 0x68, 0x73, 0x60, 0xDC, 0x50, 0x2A, 0x25,
0x0F, 0x77, 0xB9, 0xB0, 0x04, 0x0B, 0xE1, 0xCC, 0x35, 0x31, 0x84, 0xE6, 0x22, 0xF9, 0xC2, 0xAB,
0x95, 0x91, 0x61, 0xD9, 0x2B, 0xB9, 0x72, 0x4E, 0x10, 0x76, 0x31, 0x66, 0x0A, 0x0B, 0x2E, 0x83,
};
class FFXIEncryption
{
private:
static BYTE Rotate(BYTE B, int ShiftSize)
{
return (BYTE)((B >> ShiftSize) | (B << (8 - ShiftSize)));
}
public:
static bool Rotate(char* Data, int Offset, int Size, BYTE ShiftSize)
{
if(ShiftSize < 1 || ShiftSize > 8)
return false;
for(int i = 0; i < Size; i++)
WBUFB(Data, Offset + i) = Rotate(RBUFB(Data, Offset + i), ShiftSize);
//*(BYTE*)(Data + Offset + i) = Rotate((BYTE)&Data[Offset + i], ShiftSize);
return true;
}
static int CountBits(BYTE B)
{
int Count = 0;
while(B != 0)
{
if((B & 0x01) != 0)
Count++;
B >>= 1;
}
return Count;
}
static BYTE GetTextShiftSize(char* Data, int Offset, int Size)
{
if(Size < 2)
return 0;
if(&Data[Offset] == 0 && &Data[Offset + 1] == 0)
return 0;
int BitCount = CountBits((BYTE)&Data[Offset + 1]) - CountBits((BYTE)&Data[Offset]);
switch(std::abs(BitCount) % 5)
{
case 0: return 1;
case 1: return 7;
case 2: return 2;
case 3: return 6;
case 4: return 3;
}
return 0;
}
static BYTE GetDataShiftSize(char* Data, int Offset, int Size)
{
if(Size < 13)
return 0;
int BitCount = CountBits(RBUFB(Data, Offset + 2)) - CountBits(RBUFB(Data, Offset + 11)) + CountBits(RBUFB(Data, Offset + 12));
switch(std::abs(BitCount) % 5)
{
case 0: return 7;
case 1: return 1;
case 2: return 6;
case 3: return 2;
case 4: return 5;
}
return 0;
}
static bool DecodeTextBlock(char* Data, int Offset, int Size)
{
return Rotate(Data, Offset, Size, GetTextShiftSize(Data, Offset, Size));
}
static bool DecodeDataBlock(char* Data, int Offset, int Size)
{
return Rotate(Data, Offset, Size, GetDataShiftSize(Data, Offset, Size));
}
static bool DecodeDataBlockMask(char* Data, int Size)
{
BYTE s3 = Data[2], s12 = Data[11], s13 = Data[12];
bool res = DecodeDataBlock(Data, 0, Size);
Data[2] = s3;
Data[11] = s12;
Data[12] = s13;
return res;
}
static void decode_ObjectMap(BYTE* p)
{
if (p[3] >= 0x1B) {
int decode_length = (p[0] << 0) | (p[1] << 8) | (p[2] << 16);
DWORD key = key_table[p[7] ^ 0xFF];
int key_counter = 0;
for (int pos = 8; pos < decode_length; ) {
int xor_length = ((key >> 4) & 7) + 16;
if ((key & 1) && (pos + xor_length < decode_length)) {
for (int i = 0; i < xor_length; i++) {
p[pos+i] ^= 0xFF;
}
}
key += ++key_counter;
pos += xor_length;
}
int node_count = (p[4] << 0) | (p[5] << 8) | (p[6] << 16);
OBJINFO *node = (OBJINFO *)(p+32);
for(int i = 0; i < node_count; i++) {
for(int i = 0; i < 16; i++) {
node->id[i] ^= 0x55;
}
node++;
}
}
}
static void decode_mmb(BYTE*p)
{
if(p[3] >= 5)
{
int decode_length = (p[0] << 0) | (p[1] << 8) | (p[2] << 16);
DWORD key = key_table[p[5] ^ 0xF0];
int key_counter = 0;
for(int pos = 8; pos < decode_length; pos++)
{
DWORD x = ((key & 0xFF) << 8) | (key & 0xFF);
key += ++key_counter;
p[pos] ^= (x >> (key & 7));
key += ++key_counter;
}
}
decode_mmb2(p);
}
static void decode_mmb2(BYTE *p)
{
if(p[6] == 0xFF && p[7] == 0xFF) {
int decode_length = (p[0] << 0) | (p[1] << 8) | (p[2] << 16);
DWORD key1 = p[5] ^ 0xF0;
DWORD key2 = key_table2[key1] ;
int key_counter = 0;
DWORD decode_count = ((decode_length - 8) & ~0xf) / 2;
DWORD *data1 = (DWORD *)(p + 8 + 0);
DWORD *data2 = (DWORD *)(p + 8 + decode_count);
for(DWORD pos = 0; pos < decode_count; pos += 8)
{
if(key2 & 1)
{
DWORD tmp;
tmp = data1[0];
data1[0] = data2[0];
data2[0] = tmp;
tmp = data1[1];
data1[1] = data2[1];
data2[1] = tmp;
}
key1 += 9;
key2 += key1;
data1 += 2;
data2 += 2;
}
}
}
};
};
#endif

BIN
FFxiMapLib.rc

Binary file not shown.

22
FFxiMapLib.sln

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FFxiMapLib", "FFxiMapLib.vcxproj", "{011ED2E1-2612-429A-9480-6C083750E24D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{011ED2E1-2612-429A-9480-6C083750E24D}.Debug|Win32.ActiveCfg = Debug|Win32
{011ED2E1-2612-429A-9480-6C083750E24D}.Debug|Win32.Build.0 = Debug|Win32
{011ED2E1-2612-429A-9480-6C083750E24D}.Release|Win32.ActiveCfg = Release|Win32
{011ED2E1-2612-429A-9480-6C083750E24D}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

106
FFxiMapLib.vcxproj

@ -0,0 +1,106 @@ @@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{011ED2E1-2612-429A-9480-6C083750E24D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>FFxiMapLib</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v100</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;MAPLIB_EXPORTS;_DEBUG;_WINDOWS;_USRDLL;FFXIMAPLIB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>copy /Y "$(ProjectDir)MapLib.h" "$(SolutionDir)Include\MapLib.h"</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>copy /Y "$(SolutionDir)$(Configuration)\FFxiMapLib.lib" "$(SolutionDir)Lib\FFxiMapLib.lib"
copy /Y "$(SolutionDir)$(Configuration)\FFxiMapLib.dll" "$(SolutionDir)Bin\FFxiMapLib.dll"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;MAPLIB_EXPORTS;NDEBUG;_WINDOWS;_USRDLL;FFXIMAPLIB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>copy /Y "$(SolutionDir)$(Configuration)\FFxiMapLib.lib" "$(SolutionDir)Lib\FFxiMapLib.lib"
copy /Y "$(SolutionDir)$(Configuration)\FFxiMapLib.dll" "$(SolutionDir)Bin\FFxiMapLib.dll"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>copy /Y "$(ProjectDir)MapLib.h" "$(SolutionDir)Include\MapLib.h"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="FFXIEncryption.h" />
<ClInclude Include="MapLib.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="MapLib.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="FFxiMapLib.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

38
FFxiMapLib.vcxproj.filters

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MapLib.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FFXIEncryption.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MapLib.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="FFxiMapLib.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

4
FFxiMapLib.vcxproj.user

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

81
Include/MapLib.h

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
#pragma once
#ifndef _MAPLIB_HEADER_
#define _MAPLIB_HEADER_
#ifndef CONST
#define CONST const
#endif
typedef unsigned int UINT;
#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(MAPLIB_STATIC)
# ifdef MAPLIB_EXPORTS
# define MAPLIBEXPORT __declspec(dllexport)
# else
# define MAPLIBEXPORT __declspec(dllimport)
# pragma comment(lib, "FFxiMapLib.lib")
# endif
# define MAPLIBPRIVATE
#else
# define MAPLIBEXPORT
# define MAPLIBPRIVATE
#endif
namespace FFxiMapLib
{
class ICallbackClass
{
public:
virtual bool HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData) = 0;
virtual bool HandleNewTexture(char* ID, char* pdata) = 0;
virtual void HandleProgress(const char* pStage, UINT Progress, UINT Total) = 0;
};
#pragma pack(push,1)
typedef struct
{
char id[16];
float fTransX,fTransY,fTransZ;
float fRotX,fRotY,fRotZ;
float fScaleX,fScaleY,fScaleZ;
float fa,fb,fc,fd;
long fe,ff,fg,fh,fi,fj,fk,fl;
} OBJINFO;
#pragma pack(pop)
class MAPLIBEXPORT MapLib
{
private:
ICallbackClass* m_CallBack;
UINT m_MapID;
char m_ffxiDir[1024];
char* m_pDatData;
UINT m_datSize;
OBJINFO* m_ObjectMap;
UINT m_ObjectMapCount;
private:
bool ParseDat();
bool ParseObject(char* pObject);
UINT GetFtableID(UINT Table, UINT ID);
public:
MapLib();
virtual ~MapLib();
bool SetGamePath(const char* Path);
bool LoadMap(UINT ZoneID);
bool LoadMap(const char* DatPath);
void FreeMap();
OBJINFO* GetObjectMap(UINT Index);
UINT GetObjectMapCount();
void AddCallback(ICallbackClass* T);
};
};
#endif

282
MapLib.cpp

@ -0,0 +1,282 @@ @@ -0,0 +1,282 @@
#include "MapLib.h"
#include "FFXIEncryption.h"
#include <Windows.h>
FFxiMapLib::MapLib::MapLib()
{
m_pDatData = NULL;
m_datSize = 0;
m_ObjectMapCount = 0;
m_ObjectMap = NULL;
m_CallBack = NULL;
}
FFxiMapLib::MapLib::~MapLib()
{
FreeMap();
}
void FFxiMapLib::MapLib::FreeMap()
{
m_datSize = 0;
if( m_pDatData )
{
delete []m_pDatData;
m_pDatData = NULL;
}
m_pDatData=NULL;
if( m_ObjectMap )
delete[] m_ObjectMap;
m_ObjectMapCount = 0;
m_ObjectMap = NULL;
}
void FFxiMapLib::MapLib::AddCallback(ICallbackClass* T)
{
m_CallBack = T;
}
FFxiMapLib::OBJINFO* FFxiMapLib::MapLib::GetObjectMap(UINT Index)
{
if( m_ObjectMap && Index <= m_ObjectMapCount )
return &m_ObjectMap[Index];
return NULL;
}
UINT FFxiMapLib::MapLib::GetObjectMapCount()
{
if( m_ObjectMap )
return m_ObjectMapCount;
return 0;
}
bool FFxiMapLib::MapLib::SetGamePath(const char* Path)
{
lstrcpyA(m_ffxiDir, Path);
//to do valadate path
return true;
}
UINT FFxiMapLib::MapLib::GetFtableID(UINT Table, UINT ID)
{
HANDLE hFile;
char fname[1024];
DWORD dwRead;
BYTE v;
WORD f;
if( ID >= 51439 ) return 0;
lstrcpyA(fname, m_ffxiDir);
switch (Table)
{
case 1: lstrcatA(fname,"VTABLE.DAT"); break;
case 2: lstrcatA(fname,"ROM2\\VTABLE2.DAT"); break;
case 3: lstrcatA(fname,"ROM3\\VTABLE3.DAT"); break;
case 4: lstrcatA(fname,"ROM4\\VTABLE4.DAT"); break;
case 5: lstrcatA(fname,"ROM5\\VTABLE5.DAT"); break;
case 6: lstrcatA(fname,"ROM6\\VTABLE6.DAT"); break;
case 7: lstrcatA(fname,"ROM7\\VTABLE7.DAT"); break;
case 8: lstrcatA(fname,"ROM8\\VTABLE8.DAT"); break;
case 9: lstrcatA(fname,"ROM9\\VTABLE9.DAT"); break;
default: return 0;
}
hFile = CreateFileA(fname,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL);
if (hFile == INVALID_HANDLE_VALUE) return 0;
SetFilePointer(hFile, ID, NULL, FILE_BEGIN);
ReadFile(hFile, &v, 1, &dwRead, NULL);
CloseHandle(hFile);
if (dwRead != 1 || v == 0) return 0;
lstrcpyA(fname, m_ffxiDir);
switch (Table)
{
case 1: lstrcatA(fname,"FTABLE.DAT"); break;
case 2: lstrcatA(fname,"ROM2\\FTABLE2.DAT"); break;
case 3: lstrcatA(fname,"ROM3\\FTABLE3.DAT"); break;
case 4: lstrcatA(fname,"ROM4\\FTABLE4.DAT"); break;
case 5: lstrcatA(fname,"ROM5\\FTABLE5.DAT"); break;
case 6: lstrcatA(fname,"ROM6\\FTABLE6.DAT"); break;
case 7: lstrcatA(fname,"ROM7\\FTABLE7.DAT"); break;
case 8: lstrcatA(fname,"ROM8\\FTABLE8.DAT"); break;
case 9: lstrcatA(fname,"ROM9\\FTABLE9.DAT"); break;
default: return 0;
}
hFile = CreateFileA(fname,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL);
if (hFile == INVALID_HANDLE_VALUE) return 0;
SetFilePointer(hFile, ID*2, NULL, FILE_BEGIN);
ReadFile(hFile, &f, 2, &dwRead, NULL);
CloseHandle(hFile);
if(dwRead != 2) return 0;
return (DWORD)MAKELONG(f,v);
}
bool FFxiMapLib::MapLib::LoadMap(UINT ZoneID)
{
m_MapID = ZoneID;
UINT DatID = m_MapID + 100;
FreeMap();
char DatPath[1024] = {0};
DWORD id;
DWORD no;
for (int i = 9; i > -1; i--)
{
id = GetFtableID(i,DatID);
if( id )
break;
}
if (id == 0) return false;
no = id & 0xffff;
switch (HIWORD(id))
{
case 1: wsprintfA(DatPath, "%sROM\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 2: wsprintfA(DatPath, "%sROM2\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 3: wsprintfA(DatPath, "%sROM3\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 4: wsprintfA(DatPath, "%sROM4\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 5: wsprintfA(DatPath, "%sROM5\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 6: wsprintfA(DatPath, "%sROM6\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 7: wsprintfA(DatPath, "%sROM7\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 8: wsprintfA(DatPath, "%sROM8\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
case 9: wsprintfA(DatPath, "%sROM9\\%d\\%d.dat", m_ffxiDir, no/0x80, no%0x80); break;
default: return false;
}
return LoadMap(DatPath);
}
bool FFxiMapLib::MapLib::LoadMap(const char* DatPath)
{
HANDLE hFile = CreateFileA(DatPath,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL);
if( hFile!=INVALID_HANDLE_VALUE )
{
DWORD dmy;
m_datSize = GetFileSize(hFile,NULL);
m_pDatData = new char[m_datSize];
ReadFile(hFile,m_pDatData,m_datSize,&dmy,NULL);
CloseHandle(hFile);
return ParseDat();
}
return false;
}
bool FFxiMapLib::MapLib::ParseDat()
{
OBJINFO* pobjects = NULL;
int type = 0;
for(unsigned int i=0; i<= this->m_datSize; )
{
unsigned int j=i;
LPSTR iname = &this->m_pDatData[i];
unsigned int next = (int)(((*(DWORD*)&this->m_pDatData[i+4])>>3)&0x007ffff0);
if( next<16 )
break;
if( next+i > this->m_datSize )
break;
type = (int)(((*(DWORD*)&this->m_pDatData[i+4]))&0x7f);
switch(type)
{
case 0x1c: //Object map
FFXIEncryption::FFXIEncryption::decode_ObjectMap((BYTE*)&this->m_pDatData[i+16]);
pobjects = (OBJINFO *)(this->m_pDatData+i+32+16);
this->m_ObjectMapCount = (*(int*)(this->m_pDatData+i+4+16) )&0xffffff;
//copy the map to our buffer
this->m_ObjectMap = new OBJINFO[this->m_ObjectMapCount];
memcpy(this->m_ObjectMap, pobjects, sizeof(OBJINFO)*this->m_ObjectMapCount);
break;
case 0x2e: //Map object
FFXIEncryption::FFXIEncryption::decode_mmb((BYTE*)&this->m_pDatData[i+16]);
//this->m_mMBlist[this->m_numMMB++] = this->m_pDatData+i+16;
if(! ParseObject(this->m_pDatData+i+16) )
return false;
break;
case 0x20: //Texture
break;
case 0x2F:
break;
default:
break;
}
i+=next;
if( j>=i )
break;
}
return true;
}
bool FFxiMapLib::MapLib::ParseObject(char* pObject)
{
//pointer to the objects start
char* ObjectStart = pObject;
//pointer to our current read position
char* Position = ObjectStart;
//skip object name
Position += 0x20;
int Flag = *(int*)Position;
if( Flag == 1 )
Position += 0x20;
if( Flag >= 2 && Flag <= 16)
Position += 0x40;
if( Flag > 16 )
Position += Flag * 4;
int StripCount;
while(Flag)
{
StripCount = *(int*)Position;
Position += 0x20;
for (int StripOffset = 0; StripOffset < StripCount; StripOffset++)
{
int IndexCount = 0;
int NewVertexCount = 0;
int VertexCount = (int)*(short*)(Position + 16);
if( VertexCount >= 0xFFFF || VertexCount <= 0 )
break;
IndexCount = (*(int*)(Position + 16 + 4 + VertexCount * 36));
if( IndexCount >= 0xFFFF || IndexCount <= 0 )
break;
int next = 16 + 4 + VertexCount * 36 + 4 + IndexCount * 2;
next = 4 * (( next + 3) / 4);
if( (this->m_pDatData + this->m_datSize) < (Position + next) )
break;
char* VertexBuffer = (Position + 16 + 4);
WORD* IndexBuffer = (WORD*)(Position + 16 + 4 + VertexCount * 36 + 4);
//add this object. copies the vectors
//unsigned int MapObjectIndex = ThisObject->AddVertexBuffer(IndexCount, VertexCount, IndexBuffer, VertexBuffer, pTexture);
m_CallBack->HandleNewObject(ObjectStart+16, IndexCount, VertexCount, IndexBuffer, VertexBuffer);
Position += next;
}//@for (int StripOffset = 0; StripOffset < StripCount; StripOffset++)
Flag--;
}//@while(Flag)
return true;
}

81
MapLib.h

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
#pragma once
#ifndef _MAPLIB_HEADER_
#define _MAPLIB_HEADER_
#ifndef CONST
#define CONST const
#endif
typedef unsigned int UINT;
#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(MAPLIB_STATIC)
# ifdef MAPLIB_EXPORTS
# define MAPLIBEXPORT __declspec(dllexport)
# else
# define MAPLIBEXPORT __declspec(dllimport)
# pragma comment(lib, "FFxiMapLib.lib")
# endif
# define MAPLIBPRIVATE
#else
# define MAPLIBEXPORT
# define MAPLIBPRIVATE
#endif
namespace FFxiMapLib
{
class ICallbackClass
{
public:
virtual bool HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData) = 0;
virtual bool HandleNewTexture(char* ID, char* pdata) = 0;
virtual void HandleProgress(const char* pStage, UINT Progress, UINT Total) = 0;
};
#pragma pack(push,1)
typedef struct
{
char id[16];
float fTransX,fTransY,fTransZ;
float fRotX,fRotY,fRotZ;
float fScaleX,fScaleY,fScaleZ;
float fa,fb,fc,fd;
long fe,ff,fg,fh,fi,fj,fk,fl;
} OBJINFO;
#pragma pack(pop)
class MAPLIBEXPORT MapLib
{
private:
ICallbackClass* m_CallBack;
UINT m_MapID;
char m_ffxiDir[1024];
char* m_pDatData;
UINT m_datSize;
OBJINFO* m_ObjectMap;
UINT m_ObjectMapCount;
private:
bool ParseDat();
bool ParseObject(char* pObject);
UINT GetFtableID(UINT Table, UINT ID);
public:
MapLib();
virtual ~MapLib();
bool SetGamePath(const char* Path);
bool LoadMap(UINT ZoneID);
bool LoadMap(const char* DatPath);
void FreeMap();
OBJINFO* GetObjectMap(UINT Index);
UINT GetObjectMapCount();
void AddCallback(ICallbackClass* T);
};
};
#endif

6
README.md

@ -1,3 +1,7 @@ @@ -1,3 +1,7 @@
# MapLib
Source code to the MapLib project by RZN.
Source code to the MapLib project by RZN.
This lib can open and dump the map DAT files for all areas before the Adoulin expansion.
Permission was granted by RZN to allow atom0s to share this source code on Dec. 28, 2018. The source code in this repository is (c) 2015-2018 to RZN.

14
resource.h

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by FFxiMapLib.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Loading…
Cancel
Save