Пример #1
0
static void doPatchGame(const char* patch_name, char* game_name, UINT8* base, int base_len)
{
	FILE* fp = NULL;
	if ((fp = fopen(patch_name, "rb")) == NULL) {
		return;
	}

	char s[1024];
	char* p = NULL;
	char* rom_name = NULL;
	char* ips_name = NULL;
	long ips_size = 0;

	// get ips size
	ips_size = getFileSize(fp);

	while (!feof(fp)) {
		if (fgets(s, sizeof s, fp) != NULL) {
			p = s;

			// skip UTF-8 sig
			if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0)
				p += strlen(UTF8_SIGNATURE);

			if (p[0] == '[')	// '['
				break;

			rom_name = strtok(p, " \t\r\n");
			if (!rom_name)
				continue;
			if (*rom_name == '#')
				continue;
			if (_stricmp(rom_name, game_name))
				continue;

			ips_name = strtok(NULL, " \t\r\n");
			if (!ips_name)
				continue;

			// skip CRC check
			strtok(NULL, "\r\n");

			char ips_path[MAX_PATH];

			if (strchr(ips_name, '\\')) {
				// ips in parent's folder
				sprintf(ips_path, "%s\\%s%s", WtoA(getMiscPath(PATH_IPS)), ips_name, IPS_EXT);
			} else {
				sprintf(ips_path, "%s%s\\%s%s", WtoA(getMiscPath(PATH_IPS)), BurnDrvGetTextA(DRV_NAME), ips_name, IPS_EXT);
			}

			applyIPSpatch(ips_path, ips_size, base, base_len);
		}
	}

	fclose(fp);
}
Пример #2
0
static void CreateStateName(int nSlot)
{
	// create dir if dir doesn't exist
	if (!directoryExists(getMiscPath(PATH_SAVESTATE))) {
		CreateDirectory(getMiscPath(PATH_SAVESTATE), NULL);
	}

	_stprintf(szChoice, _T("%s%s slot %02x.fs"), getMiscPath(PATH_SAVESTATE), BurnDrvGetText(DRV_NAME), nSlot);
}
Пример #3
0
void loadActivePatches()
{
	TCHAR szLine[MAX_PATH];
	int nActivePatches = 0;
	size_t nLen;
	FILE* fp = _tfopen(gameIpsConfigName(), _T("rt"));
	if (fp) {
		while (_fgetts(szLine, sizeof(szLine), fp)) {
			nLen = _tcslen(szLine);

			// Get rid of the linefeed at the end
			if (nLen != 0 && (szLine[nLen - 1] == '\r' || szLine[nLen - 1] == '\n')) {
				szLine[nLen - 1] = 0;
				nLen--;
			}

			if (!_tcsnicmp(szLine, _T("//"), 2)) continue;
			if (!_tcsicmp(szLine, _T(""))) continue;

			_stprintf(szActivePatches[nActivePatches], _T("%s%s\\%s"), getMiscPath(PATH_IPS), BurnDrvGetText(DRV_NAME), szLine);

			nActivePatches++;
			if (nActivePatches >= MAX_ACTIVE_PATCHES) {
				break;
			}
		}

		fclose(fp);
	}
}
Пример #4
0
int getPatchFilename(TCHAR* pszName, TCHAR* pszRet, const int& patch_index)
{
	WIN32_FIND_DATA wfd;
	HANDLE hSearch;
	TCHAR szFilePathName[MAX_PATH];

	_stprintf(szFilePathName, _T("%s%s\\"), getMiscPath(PATH_IPS), pszName);

	if (szFilePathName[_tcslen(szFilePathName) -1] != _T('\\')) {
		_tcscat(szFilePathName, _T("\\"));
	}
	_tcscat(szFilePathName, _T("*.dat"));

	hSearch = FindFirstFile(szFilePathName, &wfd);

	if (hSearch) {
		int Done = 0;
		int Count = 0;

		while (!Done) {
			if (Count == patch_index) {
				_tcscpy(pszRet, wfd.cFileName);
				pszRet[_tcslen(pszRet) - 4] = _T('\0');	// To trim the ext ".dat"
				break;
			}
			Count++;
			Done = !FindNextFile(hSearch, &wfd);
		}

		FindClose(hSearch);
		return 1;
	}
	return 0;
}
Пример #5
0
static int parseRelations()
{
	depTable.clear();
	confTable.clear();

	char assistName[MAX_PATH];
	sprintf(assistName, "%s\\%s\\%s", WtoA(getMiscPath(PATH_IPS)), BurnDrvGetTextA(DRV_NAME), "assistant.txt");

	//parse ips dat and update the treewidget
	FILE* fp = fopen(assistName, "rt");
	if (!fp) {
		return 1;
	}

	char s[1024];
	char* p = NULL;
	string line;
	size_t nLen = 0;
	size_t pos = string::npos;

	while (!feof(fp)) {
		if (fgets(s, sizeof s, fp) != NULL) {
			p = s;
			// skip UTF-8 sig
			if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0) {
				p += strlen(UTF8_SIGNATURE);
			}

			if (p[0] == '#') {
				continue; // skip comment
			}

			getLine(p);
			line = p;

			pos = line.find(">");
			if (pos != string::npos) {
				StringList depStrs = split2Str(line, ">");
				string parent = *(depStrs.begin());
				lowerString(parent);
				StringList children = stringSplit(depStrs.back(), ",");
				lowerTrimmed(children);
				depTable.insert(make_pair(parent, children));
			} else {
				StringList conflicts = stringSplit(line, ",");
				lowerTrimmed(conflicts);
				confTable.push_back(conflicts);
			}
		}
	}

	return 0;
}
Пример #6
0
// ==> IPS preview, added by regret, thanks MAME Plus! team
int getPatchPrevName(TCHAR* pszName, TCHAR* pszGameName, TCHAR* pszPatchName)
{
	_stprintf(pszName, _T("%s%s\\%s.png"), getMiscPath(PATH_IPS), pszGameName, pszPatchName);

	FILE* fp = _tfopen(pszName, _T("rb"));
	if (fp) {
		fclose(fp);
		_stprintf(pszName, _T("%s%s\\%s"), getMiscPath(PATH_IPS), pszGameName, pszPatchName);
		return 1;
	} else {
		// if not loaded, see parent's ips folder
		_stprintf(pszName, _T("%s%s\\%s.png"), getMiscPath(PATH_IPS), BurnDrvGetText(DRV_PARENT), pszPatchName);
		fp = _tfopen(pszName, _T("rb"));
		if (fp) {
			fclose(fp);
			_stprintf(pszName, _T("%s%s\\%s"), getMiscPath(PATH_IPS), BurnDrvGetText(DRV_PARENT), pszPatchName);
			return 1;
		}
	}
	return 0;
}
Пример #7
0
TCHAR* getPatchDesc(const TCHAR* pszGameName, const TCHAR* pszPatchName)
{
	FILE* fp = NULL;
	TCHAR szFilename[MAX_PATH];
	TCHAR* desc = NULL;

	_stprintf(szFilename, _T("%s\\%s\\%s.dat"), getMiscPath(PATH_IPS), pszGameName, pszPatchName);
	if ((fp = _tfopen(szFilename, _T("r"))) != NULL) {
		/* Get localized desc */
		desc = getPatchDescByLangcode(fp, nPatchLang);

		fclose(fp);
	}

	return desc;
}
Пример #8
0
int getPatchCount()
{
	TCHAR szFilePathName[MAX_PATH];

	_stprintf(szFilePathName, _T("%s%s\\"), getMiscPath(PATH_IPS), BurnDrvGetText(DRV_NAME));
	if (szFilePathName[_tcslen(szFilePathName) -1] != _T('\\')) {
		_tcscat(szFilePathName, _T("\\"));
	}
	_tcscat(szFilePathName, _T("*.dat"));

	unsigned int count = 0;
	WIN32_FIND_DATA wfd;

	HANDLE hSearch = FindFirstFile(szFilePathName, &wfd);
	if (hSearch != INVALID_HANDLE_VALUE) {
		do {
			count++;
		} while (FindNextFile(hSearch, &wfd));

		FindClose(hSearch);
	}
	return count;
}
Пример #9
0
static void fillListBox()
{
	WIN32_FIND_DATA wfd;
	HANDLE hSearch;
	FILE* fp = NULL;

	TCHAR szFilePath[MAX_PATH];
	TCHAR szFilePathSearch[MAX_PATH];
	TCHAR szFileName[MAX_PATH];
	TCHAR PatchName[MAX_PATH];

	int nHandlePos = 0;
	int nNumNodes = 0;

	nPatchIndex = 0;
	nNumPatches = 0;

	TVINSERTSTRUCT TvItem;
	memset(&TvItem, 0, sizeof(TvItem));
	TvItem.item.mask = TVIF_TEXT | TVIF_PARAM;
	TvItem.hInsertAfter = TVI_LAST;

	_stprintf(szFilePath, _T("%s%s\\"), getMiscPath(PATH_IPS), BurnDrvGetText(DRV_NAME));
	_stprintf(szFilePathSearch, _T("%s*.dat"), szFilePath);

	hSearch = FindFirstFile(szFilePathSearch, &wfd);

	if (hSearch != INVALID_HANDLE_VALUE) {
		int Done = 0;

		while (!Done) {
			memset(szFileName, '\0', MAX_PATH);
			_stprintf(szFileName, _T("%s%s"), szFilePath, wfd.cFileName);

			fp = _tfopen(szFileName, _T("r"));
			if (fp) {
				memset(PatchName, '\0', MAX_PATH);

				TCHAR* PatchDesc = getPatchDescByLangcode(fp, nPatchLang);
				// If not available - try English first
				if (PatchDesc == NULL) {
					PatchDesc = getPatchDescByLangcode(fp, 0);
					// Simplified Chinese is the reference language
					if (PatchDesc == NULL) {
						PatchDesc = getPatchDescByLangcode(fp, 1);
					}
				}
				if (PatchDesc == NULL) {
					fclose(fp);
					break;
				}

				for (unsigned int i = 0; i < _tcslen(PatchDesc); i++) {
					if (PatchDesc[i] == '\r' || PatchDesc[i] == '\n') {
						break;
					}
					PatchName[i] = PatchDesc[i];
				}

				// Check for categories
				int nNumTokens = 0;
				TCHAR szCategory[MAX_PATH];
				TCHAR tempText[MAX_PATH];
				TCHAR itemName[MAX_PATH] = _T("");
				TVITEM Tvi;
				size_t nPatchNameLength = _tcslen(PatchName);

				TCHAR* Tokens = _tcstok(PatchName, _T("/"));
				while (Tokens != NULL) {
					if (nNumTokens == 0) {
						bool bAddItem = true;

						// Check if item already exists
						nNumNodes = TreeView_GetCount(hIpsList);
						for (int i = 0; i < nNumNodes; i++) {
							memset(&Tvi, 0, sizeof(Tvi));
							Tvi.hItem = hItemHandles[i];
							Tvi.mask = TVIF_TEXT | TVIF_HANDLE;
							Tvi.pszText = tempText;
							Tvi.cchTextMax = MAX_PATH;
							TreeView_GetItem(hIpsList, &Tvi);

							if (!_tcsicmp(Tvi.pszText, Tokens)) {
								bAddItem = false; // item exists, don't add it
								break;
							}
						}

						// add category
						if (bAddItem) {
							TvItem.hParent = TVI_ROOT;
							TvItem.item.pszText = Tokens;
							hItemHandles[nHandlePos] = TreeView_InsertItem(hIpsList, &TvItem);

							nHandlePos++;
							if (nHandlePos >= MAX_NODES) {
								nHandlePos = MAX_NODES - 1;
							}
						}

						if (_tcslen(Tokens) == nPatchNameLength) {
							saveDatName(nPatchIndex, wfd.cFileName);
							hPatchHandlesIndex[nPatchIndex] = hItemHandles[nHandlePos - 1];
							_tcscpy(szPatchFileNames[nPatchIndex], szFileName);

							nPatchIndex++;
							if (nPatchIndex >= MAX_NODES) {
								nPatchIndex = MAX_NODES - 1;
							}
						}

						_tcscpy(szCategory, Tokens);
					} else {
						HTREEITEM hNode = TVI_ROOT;
						// See which category we should be in
						nNumNodes = TreeView_GetCount(hIpsList);
						for (int i = 0; i < nNumNodes; i++) {
							memset(&Tvi, 0, sizeof(Tvi));
							Tvi.hItem = hItemHandles[i];
							Tvi.mask = TVIF_TEXT | TVIF_HANDLE;
							Tvi.pszText = tempText;
							Tvi.cchTextMax = MAX_PATH;
							TreeView_GetItem(hIpsList, &Tvi);

							if (!_tcsicmp(Tvi.pszText, szCategory)) {
								hNode = Tvi.hItem;
								break;
							}
						}

						// add ips items
						saveDatName(nPatchIndex, wfd.cFileName);
						_stprintf(itemName, _T("%s [%s]"), Tokens, wfd.cFileName);
						TvItem.hParent = hNode;
						TvItem.item.pszText = itemName;
						hItemHandles[nHandlePos] = TreeView_InsertItem(hIpsList, &TvItem);

						hPatchHandlesIndex[nPatchIndex] = hItemHandles[nHandlePos];
						_tcscpy(szPatchFileNames[nPatchIndex], szFileName);

						nHandlePos++;
						if (nHandlePos >= MAX_NODES) {
							nHandlePos = MAX_NODES - 1;
						}
						nPatchIndex++;
						if (nPatchIndex >= MAX_NODES) {
							nPatchIndex = MAX_NODES - 1;
						}
					}

					Tokens = _tcstok(NULL, _T("/"));
					nNumTokens++;
				}

				fclose(fp);
			}

			Done = !FindNextFile(hSearch, &wfd);
		}

		FindClose(hSearch);
	}

	nNumPatches = nPatchIndex;

	// Expand all branches
	nNumNodes = TreeView_GetCount(hIpsList);
	for (int i = 0; i < nNumNodes; i++) {
		TreeView_Expand(hIpsList, hItemHandles[i], TVE_EXPAND);
	}
}