///////////////////////////////
#include <acknex.h>
//#include <default.c>
#include <d3d9.h>
#include <strio.c>
///////////////////////////////

typedef struct{
	int m_EncodeNum;
	int m_Identification;
	int m_FileSize;
	int m_DataNumber;
	int m_Parity;
}ACEOBJECT_HEADER;

typedef struct{
	int m_EncodeNum;
	int m_DataSize;
	int m_Parity;
	char m_FileName[12];
	
}ACEOBJECT_XFILE;


ACEOBJECT_HEADER test1;
ACEOBJECT_XFILE test2;

byte* file_buffer;
FILE* OBJECTFILE;
FILE* DATAFILE;


void IMPORT_ACE_OBJ_FILE(STRING* filename)
{
	STRING* aceobjfolder = str_create(str_folder);
	str_cat(aceobjfolder,"\\");
	str_cat(aceobjfolder,filename);
	//printf(_chr(aceobjfolder));
	
	
	OBJECTFILE = fopen(_chr(aceobjfolder),"r+b");
	if(OBJECTFILE == NULL){error("Fehler OBJ Read");}
	
	fread(test1, sizeof(ACEOBJECT_HEADER), 1, OBJECTFILE);
	fread(test2, sizeof(ACEOBJECT_XFILE),  1, OBJECTFILE);

	file_buffer = (byte*)sys_malloc(test2.m_DataSize * sizeof(byte)); 
	fread(file_buffer, sizeof(byte),test2.m_DataSize, OBJECTFILE);

	
	STRING* tempfile = str_create(ObjectsDir);
	STRING* fileID = str_create(test2.m_FileName);
	str_cat(tempfile, fileID);
	str_cat(tempfile, ".x");

	fclose(OBJECTFILE);
	DATAFILE = fopen(_chr(tempfile),"w+b");
	if(DATAFILE == NULL){error("Fehler DAT Write");}
	fwrite(file_buffer, sizeof(byte), test2.m_DataSize, DATAFILE);
	fclose(DATAFILE);
	
	
}
