예제 #1
0
void Text::draw(string text, Vector2 position, DXColor color)
{
	RECT R = {position.x, position.y, 0, 0};
	LPCWSTR str = toWCString(text);
	font->DrawText(0, str, -1, &R, DT_NOCLIP, color);
}
예제 #2
0
static bool extractFiles(NexasPackage* package, const wchar_t* targetDir) {
	IndexEntry* indexes = (IndexEntry*)baData(package->indexes);
	u32 count = package->header->entryCount;

	for (u32 i = 0; i < count; ++i) {
		wchar_t* wName = toWCString(indexes[i].name, L"japanese");
		writeLog(LOG_VERBOSE, L"Entry %u: %s, Offset: %u, ELen: %u, DLen: %u",
				i, wName, indexes[i].offset, indexes[i].encodedLen,
				indexes[i].decodedLen);
		if (fseek(package->file, indexes[i].offset, SEEK_SET) != 0) {
			writeLog(LOG_QUIET, L"ERROR: Entry %u: %s, Unable to locate data!",
													i, wName);
			cleanupForEntry(wName, NULL, NULL, NULL, false);
			return false;
		}

		ByteArray* encodedData = newByteArray(indexes[i].encodedLen);
		ByteArray* decodedData = encodedData;
		if (fread(baData(encodedData), 1, indexes[i].encodedLen, package->file) != indexes[i].encodedLen) {
			writeLog(LOG_QUIET, L"ERROR: Entry %u: %s, Unable to read data from package!",
							i, wName);
			cleanupForEntry(wName, NULL, encodedData, NULL, false);
			return false;
		}

		/**
		 * Now we support two PAC variants.
		 * The first is Variant 4, where contents are either uncompressed (like ogg files),
		 * or compressed using zlib (the deflate algorithm).
		 * We should do a test to determine if the particular file is compressed or not.
		 */
		if (package->header->variantTag == CONTENT_MAYBE_DEFLATE) {
			unsigned long decodedLen = indexes[i].decodedLen;
			if (decodedLen > indexes[i].encodedLen) {
				decodedData = newByteArray(decodedLen);
				if (uncompress(baData(decodedData), &decodedLen, baData(encodedData), indexes[i].encodedLen) != Z_OK) {
					writeLog(LOG_QUIET, L"ERROR: Entry %u: %s, Unable to extract data!", i, wName);
					cleanupForEntry(wName, NULL, encodedData, decodedData, false);
					return false;
				}
			}
		} else if (package->header->variantTag == CONTENT_LZSS) {
			decodedData = lzssDecode(baData(encodedData), indexes[i].encodedLen, indexes[i].decodedLen);
			if (decodedData == NULL) {
				writeLog(LOG_QUIET, L"ERROR: Entry %u: %s, Unable to extract data!", i, wName);
				cleanupForEntry(wName, NULL, encodedData, decodedData, false);
				return false;
			}
		}

		wchar_t* wPath = fsCombinePath(targetDir, wName);
		FILE* outFile = _wfopen(wPath, L"wb");
		if (outFile == NULL) {
			writeLog(LOG_QUIET,
					L"ERROR: Entry %u: %s, Unable to open output file!",
						i, wName);
			cleanupForEntry(wName, wPath, encodedData, decodedData, false);
			return false;
		}
		if (fwrite(baData(decodedData), 1, indexes[i].decodedLen, outFile)
				!= indexes[i].decodedLen) {
			writeLog(LOG_QUIET,
					L"ERROR: Entry %u: %s, Unable to write file content!",
						i, wName);
			cleanupForEntry(wName, wPath, encodedData, decodedData, false);
			fclose(outFile);
			return false;
		}
		fclose(outFile);
		writeLog(LOG_NORMAL, L"Unpacked: Entry %u: %s", i, wName);
		cleanupForEntry(wName, wPath, encodedData, decodedData, true);
	}

	return true;
}