Exemple #1
0
void FileSystem::ParseArchives( const char *_dir, const char *_filter )
{
    LList<char *> *results = ListDirectory( _dir, _filter, false );
    for( int i = 0; i < results->Size(); ++i )
    {
        char fullFilename[512];
        snprintf( fullFilename, sizeof(fullFilename), "%s%s", _dir, results->GetData( i ) );
        fullFilename[ sizeof(fullFilename) - 1 ] = '\0';
        ParseArchive( fullFilename );
    }
    results->EmptyAndDelete();
    delete results;
}
void ParseScr(int file)
{
	int i = 0;
	
	if(parsed == 0)
		ParseArchive();
	
	if(amientry == NULL)
		return;
	
	for(i = 0; i < amicount; i++)
	{
		if(amientry[i].file == file)
		{
			FILE *infile = fopen("data.ami", "rb");
			ScrEntry *screntry = NULL;
			int x = 0, scrtype = 0, scrcount = 0;

			if(!infile)
				break;
			
			fseek(infile, amientry[i].offset+4, SEEK_SET);
			fread(&scrtype, 1, 4, infile);
			
			if((file != 0xffffffff && file != 0xfffffffe) && filetype != scrtype)
			{
				fclose(infile);
				break;
			}
			
			fread(&scrcount, 1, 4, infile);
			
			screntry = (ScrEntry*)calloc(scrcount+1, sizeof(ScrEntry));
			entry = (Entry*)realloc(entry, (entrycount+scrcount+1)*sizeof(Entry));
			
			fread(screntry, sizeof(ScrEntry), scrcount, infile);
			
			for(x = 0; x < scrcount; x++, entrycount++) // build string entries
			{   
				fseek(infile, amientry[i].offset+screntry[x].offset, SEEK_SET);
				
				entry[entrycount].str = (char*)calloc(screntry[x].len+1, sizeof(char));
				entry[entrycount].id = screntry[x].id;
				entry[entrycount].len = screntry[x].len;
				entry[entrycount].context = file;
				entry[entrycount].buffer = 0;
				
				fread(entry[entrycount].str, 1, entry[entrycount].len, infile);
				readFile = file;
			}
	
			free(screntry);
			fclose(infile);
			
			break;
		}
	}

	if(imgentry != NULL)
	{
		for(i=0; i<amicount; i++) // free any unused memory
		{
			if(imgentry[i].bg != NULL)
			{
				free(imgentry[i].bg);
				imgentry[i].bg = NULL;
			}
		}
	}
}
char *HookText(char *input, int id)
{		
	if(parsed == 0)
		ParseArchive();
	
#if LOGCHOICES == 1
	if(input[0] == '\x12')
	{
		int len = strlen(input);
		unsigned int hash = GenHash(input, HASHKEY, len);
		FILE *filelog = NULL;

		CreateDirectory("output", NULL);
		filelog = fopen("output\\log.dat", "ab");
		
		fseek(filelog, 0, SEEK_END);
		fwrite(&hash,1, 4, filelog);
		fwrite(&len,1, 4, filelog);
		fwrite(input,1, len, filelog);
		
		fclose(filelog);
	}
#endif
	
#if DUMPMEM == 1
	if(dump != NULL)
	{
		fclose(dump);
		fclose(scrlog);
		dump = NULL;
	}
#endif

#if SKIPTEXT == 1
	if(input[0] != '\x12')
	{
		return "\x05\x00";
	}
#endif
	
	if(entrycount == 0)
	{
		return input;
	}
	else
	{
		int i = 0, found = 0, len = strlen(input);
	
		for(i = 0; i < entrycount; i++)
		{   
			/*
			{
				FILE *txtlog = fopen("txtdbg2.txt","a+");
				fprintf(txtlog,"file[%08x] id[%08x] buffer[%08x] buffer2[%08x] %s\n",entry[i].context,entry[i].id,entry[i].buffer,entry[i].buffer2,entry[i].str);
				fclose(txtlog);
			}
			*/

			if(((id & 0x00ffffff) == entry[i].id &&
				((entry[i].buffer == 0 &&
				  entry[i].context == readFile) ||
				 (entry[i].buffer != 0 &&
				  entry[i].buffer == input))) ||
				(entry[i].id == GenHash(input, HASHKEY, len)))
			{
				// proof of concept code for loading a notepad at a certain part of a script
				// replace the context with the file and the id with the id where you want the txt to load at
#if GAME == MUVLUVALT
				OpenTextFile(0x55c43c48, 0x000023b4, "Coup d'etat Arc Ending Speech.txt");
				OpenTextFile(0x5f4cf75e, 0x00002008, "Early Sadogashima Arc Congratulatory Letter.txt");
				OpenTextFile(0x5fd145f8, 0x0000062d, "Yuuko's Voice-only Line Before Operation Cherry Blossom.txt");
#endif

				entry[i].buffer = input;
				found = 1;

				break;
			}
		}
		
		if(found == 0)
		{
#if DEBUGIDS
			{
				FILE *txtlog = fopen("txtdbg.txt","a+");
				fprintf(txtlog,"file[%08x] id[%08x] buffer[%08x] %s\n",readFile,id&0x00ffffff,(int)input,input);
				fclose(txtlog);
			}
#endif

			return input;
		}
		else
		{
			return entry[i].str;
		}
		
		found = 0;
	}

	return input;
}