BrawlBuilder.BrawlBuilder.Patch C# (CSharp) Method

Patch() private method

private Patch ( ProcessStartInfo pStartInfo ) : bool
pStartInfo ProcessStartInfo
return bool
		private bool Patch(ProcessStartInfo pStartInfo)
		{
			string patchArgs = "";
			string gct = gctFile.Text;

			if (File.Exists(_basePath + @"\Resources\temp.gct"))
				gct = _basePath + @"\Resources\temp.gct";

			if (File.Exists(gct))
			{
				// Determine GCT file size
				long gctSize = new FileInfo(gct).Length;

				// Set up offset
				string offset = "80570000";
				foreach (string arg in Environment.GetCommandLineArgs())
					if (arg.StartsWith("--offset="))
						offset = arg.Substring(9);

				patchArgs += " NEW=TEXT,80001800,10C0 LOAD=80001800,\"" + _basePath + "/Resources/patch/codehandler.bin\" XML=\"" + _basePath + "/Resources/patch/PatchCommon.xml\" NEW=DATA," + offset + "," + gctSize.ToString("X") + " LOAD=" + offset + ",\"" + gct + "\"";
			}
			else if (gctFile.Text != "")
			{
				// GCT file was selected, but it has been deleted or moved since the initial check
				StopWorker("GCT file not found, stopping build...");
			}

			if (customID.Checked)
			{
				// Need to patch dol to avoid the Please insert disc screen
				string first = gameID.Text.Substring(0, 4);
				string last = gameID.Text.Substring(4);

				if (first != "RSBE")
				{
					// Convert to hex
					first = BitConverter.ToString(Encoding.ASCII.GetBytes(first)).Replace("-", "");
					patchArgs += " 805A14B0=" + first;
				}

				if (last != "01")
				{
					// Convert to hex
					last = BitConverter.ToString(Encoding.ASCII.GetBytes(last)).Replace("-", "");
					patchArgs += " 805A14B8=" + last;
				}
			}

			if (patchArgs != "")
			{
				// Apply patch
				SetStatus("Patching...");

				pStartInfo.Arguments = "dolpatch ssbb.d/sys/main.dol" + patchArgs;

				if (!DoWit(pStartInfo, true))
					return false;
			}

			if (buildWorker.CancellationPending)
			{
				// Since we have been copying files in, ssbb.d is no longer a clean Brawl. Delete it.
				DeleteBrawlFolder();
				return false;
			}

			return true;
		}