int main(int argc, char **argv)
{
	if(argc!=4)
	{
		printf("usage; %s infile outstring outcode\n",argv[0]);
		return 0;
	}
	
	infile = fopen(argv[1],"rb");
	if(!infile)
	{
		printf("Could not open %s\n",argv[1]);
		return -1;
	}
	
	fread(&scrhead,1,sizeof(scrhead),infile);
	
	strings = (Entry*)calloc(scrhead.strindex.size,sizeof(Entry));
	labels = (int*)calloc(scrhead.labels.size+1,sizeof(int));
	markers = (int*)calloc(scrhead.markers.size+1,sizeof(int));
	unk12 = (int*)calloc(scrhead.unk12.size+1,sizeof(int));
	unk13 = (int*)calloc(scrhead.unk13.size+1,sizeof(int));
	
	fseek(infile,scrhead.strindex.offset,SEEK_SET);
	fread(strings,1,scrhead.strindex.size*8,infile);
	
	setlocale(LC_ALL, "Japanese");

	ParseTable(labels,scrhead.labels.offset,scrhead.labels.size);
	ParseTable(markers,scrhead.markers.offset,scrhead.markers.size);
	ParseTable(unk12,scrhead.unk12.offset,scrhead.unk12.size);
	ParseTable(unk13,scrhead.unk13.offset,scrhead.unk13.size);
	
	DumpStrings(argv[2]);
	DumpBytecode(argv[3],argv[1],argv[2]);
	
	fclose(infile);

	return 0;
}
Example #2
0
bool AIConfMgr::Init(CSVDocument* poCSVDoc)
{
	int nRows = (int)poCSVDoc->numRows();
	int nCols = (int)poCSVDoc->numColumns();
	assert(nCols >= 2);

	CSVDocument oDoc;
	for (int i = 2; i < nRows; i++)
	{
		AIConf oConf;
		oConf.uID = (uint16_t)poCSVDoc->getValue(i, "nID");
		std::string sActRandom = (const char*)poCSVDoc->getValue(i, "tActRandom");
		std::string sR1 = (const char*)poCSVDoc->getValue(i, "tR1");
		std::string sR2 = (const char*)poCSVDoc->getValue(i, "tR2");
		std::string sR3 = (const char*)poCSVDoc->getValue(i, "tR3");
		std::string sAtkTime = (const char*)poCSVDoc->getValue(i, "tAtkTime");
		std::string sDefTime = (const char*)poCSVDoc->getValue(i, "tDefTime");

		int nVal1;
		int nVal2;
		ParseTable(sActRandom, nVal1, nVal2);
		oConf.tActRandom[0] = (int16_t)nVal1;
		oConf.tActRandom[1] = (int16_t)nVal2;
		assert(oConf.tActRandom[0] + oConf.tActRandom[1] > 0);

		ParseTable(sR1, nVal1, nVal2);
		oConf.tR1[0] = (int16_t)nVal1;
		oConf.tR1[1] = (int16_t)nVal2;
		assert((oConf.tR1[0] == 0 && oConf.tR1[1] == 0) || oConf.tR1[1] >= gnUnitWidth);

		ParseTable(sR2, nVal1, nVal2);
		oConf.tR2[0] = (int16_t)nVal1;
		oConf.tR2[1] = (int16_t)nVal2;
		assert((oConf.tR2[0] == 0 && oConf.tR2[1] == 0) || oConf.tR2[1] >= gnUnitWidth);

		ParseTable(sR3, nVal1, nVal2);
		oConf.tR3[0] = (int16_t)nVal1;
		oConf.tR3[1] = (int16_t)nVal2;
		assert((oConf.tR3[0] == 0 && oConf.tR3[1] == 0) || (oConf.tR3[1] >= gnUnitWidth && oConf.tR3[1] >= gnUnitWidth));

		ParseTable(sAtkTime, nVal1, nVal2);
		oConf.tAtkTime[0] = (int16_t)nVal1;
		oConf.tAtkTime[1] = (int16_t)nVal2;

		ParseTable(sDefTime, nVal1, nVal2);
		oConf.tDefTime[0] = (int16_t)nVal1;
		oConf.tDefTime[1] = (int16_t)nVal2;

		oConf.nAtkCD = (int16_t)poCSVDoc->getValue(i, "nAtkCD");
		oConf.nSwitchWeaponRate = (int8_t)((int16_t)poCSVDoc->getValue(i, "nSwitchWeaponRate"));
		oConf.nDropBombRate = (int8_t)((int16_t)poCSVDoc->getValue(i, "nDropBombRate"));

		m_oConfMap[oConf.uID] = oConf;
	}
	return true;
}
Example #3
0
// initialize g_rgchLeadBytes
//
// use the Windows API IsDBCSLeadByte() or the Mac API ParseTable()
//
static VOID InitLeadByteTable()
{
#if MAC

    // as in Silver, the font must be switched first

    // preserve the old font in the current grafPort
    short fontSave = qd.thePort->txFont;

    // then set the grafPort font to 1 (Application Default) because
    // ParseTable uses qd.thePort->txFont to determine the currect script,
    // which in turn determines the lead byte table.  We want the application
    // default table.
    TextFont(1);

    // UNDONE: is it necessary to init this to 0?
    memset(g_rgchLeadBytes, 0, 256);

    ParseTable(g_rgchLeadBytes);

    // restore the old font
    TextFont(fontSave);
   
#else  // !MAC

    int c;

    memset(g_rgchLeadBytes, 0, 128);

    // start at 128 since there aren't any lead bytes before that
    for(c = 128; c < 256; c++) {
        g_rgchLeadBytes[c] = (char)IsDBCSLeadByte((char)c);
    }

#endif // !MAC
}
nsresult
nsMorkReader::Read(nsIFile *aFile)
{
    nsCOMPtr<nsIFileInputStream> stream =
        do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID);
    NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);

    nsresult rv = stream->Init(aFile, PR_RDONLY, 0, 0);
    NS_ENSURE_SUCCESS(rv, rv);

    mStream = do_QueryInterface(stream);
    NS_ASSERTION(mStream, "file input stream must impl nsILineInputStream");

    nsCLineString line;
    rv = ReadLine(line);
    if (!line.EqualsLiteral("// <!-- <mdb:mork:z v=\"1.4\"/> -->")) {
        return NS_ERROR_FAILURE; // unexpected file format
    }

    IndexMap columnMap;
    NS_ENSURE_TRUE(columnMap.Init(), NS_ERROR_OUT_OF_MEMORY);

    while (NS_SUCCEEDED(ReadLine(line))) {
        // Trim off leading spaces
        PRUint32 idx = 0, len = line.Length();
        while (idx < len && line[idx] == ' ') {
            ++idx;
        }
        if (idx >= len) {
            continue;
        }

        const nsCSubstring &l = Substring(line, idx);

        // Look at the line to figure out what section type this is
        if (StringBeginsWith(l, NS_LITERAL_CSTRING("< <(a=c)>"))) {
            // Column map.  We begin by creating a hash of column id to column name.
            StringMap columnNameMap;
            NS_ENSURE_TRUE(columnNameMap.Init(), NS_ERROR_OUT_OF_MEMORY);

            rv = ParseMap(l, &columnNameMap);
            NS_ENSURE_SUCCESS(rv, rv);

            // Now that we have the list of columns, we put them into a flat array.
            // Rows will have value arrays of the same size, with indexes that
            // correspond to the columns array.  As we insert each column into the
            // array, we also make an entry in columnMap so that we can look up the
            // index given the column id.
            mColumns.SetCapacity(columnNameMap.Count());

            AddColumnClosure closure(&mColumns, &columnMap);
            columnNameMap.EnumerateRead(AddColumn, &closure);
            if (NS_FAILED(closure.result)) {
                return closure.result;
            }
        } else if (StringBeginsWith(l, NS_LITERAL_CSTRING("<("))) {
            // Value map
            rv = ParseMap(l, &mValueMap);
            NS_ENSURE_SUCCESS(rv, rv);
        } else if (l[0] == '{' || l[0] == '[') {
            // Table / table row
            rv = ParseTable(l, columnMap);
            NS_ENSURE_SUCCESS(rv, rv);
        } else {
            // Don't know, hopefully don't care
        }
    }

    return NS_OK;
}