/// <summary> /// Restores all the custom gsc pointers to their correct buffers /// </summary> public void ClearGscMods() { try { if (IsInGame()) { SetStatus($"You must be in pre-game lobby before clearing GSC files."); XtraMessageBox.Show(this, "You must be in pre-game lobby before clearing GSC files.", "Can't Inject", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } foreach (string gscFile in LastUsedGscFiles) { GscData.FileItem gscFileData = GetGscFileData(ConsoleType, LastInjectedGameType, gscFile); if (ConsoleType.Equals("PS3")) { PS3.Extension.WriteUInt32(gscFileData.Pointer, gscFileData.Buffer); } else if (ConsoleType.Equals("XBOX")) { Xbox.WriteUInt32(gscFileData.Pointer, gscFileData.Buffer); } } if (ConsoleType.Equals("PS3")) { NotifyMessagePS3("^2Cleared GSC Mods", "Successfully cleared all mods", "party_ready"); } SetStatus($"All GSC files have been restored."); XtraMessageBox.Show(this, "All GSC files have been restored.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { SetStatus($"Unable to clear GSC files. Error: " + ex.Message, ex); XtraMessageBox.Show(this, "Unable to clear GSC files.\n\nMessage:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Injects the specified GSC mods to the their correct game locations /// </summary> /// <param name="modItem"></param> private void InjectModItem(ModsData.ModItem modItem) { try { if (IsInGame()) { SetStatus($"You must be in pre-game lobby before injecting mods."); XtraMessageBox.Show(this, "You must be in pre-game lobby before injecting mods.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } ClearGscMods(); LastUsedGscFiles.Clear(); modItem.DownloadInstallFiles(); // Free Memory Offsets uint freeMemoryOffset; if (ConsoleType.Equals("PS3")) { freeMemoryOffset = 0x51000000; } else { freeMemoryOffset = 0x40300000; } foreach (string installFilePath in modItem.InstallPaths) { foreach (string localFilePath in Directory.GetFiles(modItem.GetDownloadDataPath(), "*.*", SearchOption.AllDirectories)) { string installFileName = Path.GetFileName(installFilePath); if (string.Equals(installFileName, Path.GetFileName(localFilePath), StringComparison.CurrentCultureIgnoreCase)) { GscData.FileItem gscFileData = GetGscFileData(ConsoleType, modItem.GameType, installFilePath); LastUsedGscFiles.Add(installFilePath); byte[] gscFile = File.ReadAllBytes(localFilePath); SetStatus($"{modItem.Name} v{modItem.Version} ({modItem.GetGameType()}) - Injecting GSC file: {installFileName} ..."); if (ConsoleType.Equals("PS3")) { PS3.Extension.WriteUInt32(gscFileData.Pointer, 0x51000000); // Overwrite script pointer PS3.Extension.WriteBytes(0x51000000, gscFile); // Write compiled script buffer to free memory location } else if (ConsoleType.Equals("XBOX")) { Xbox.WriteUInt32(gscFileData.Pointer, 0x40300000); Xbox.WriteByte(0x40300000, gscFile); } /* TESTS FOR INJECTING MUTIPLE GSC FILES aZaZ.. * if (ConsoleType.Equals("PS3")) * { * freeMemoryOffset = GET_ALIGNED_DWORD(freeMemoryOffset + 1); * * PS3.Extension.WriteUInt32(gscFileData.Pointer, freeMemoryOffset); // Overwrite script pointer * PS3.Extension.WriteBytes(freeMemoryOffset, new byte[gscFile.Length + 1]); * PS3.Extension.WriteBytes(freeMemoryOffset, gscFile); // Write compiled script buffer to free memory location * * freeMemoryOffset += (uint)(gscFile.Length + 1); * } * else if (ConsoleType.Equals("XBOX")) * { * freeMemoryOffset = GET_ALIGNED_DWORD(freeMemoryOffset + 1); * * XBOX.SetMemory(gscFileData.Pointer, BitConverter.GetBytes(freeMemoryOffset).Reverse().ToArray()); * XBOX.SetMemory(freeMemoryOffset, new byte[gscFile.Length + 1]); * XBOX.SetMemory(freeMemoryOffset, gscFile); * * * freeMemoryOffset += (uint)(gscFile.Length + 1); * } * * * Xbox.WriteUInt32(gscFileData.Pointer, freeMemoryOffset); */ SetStatus($"{modItem.Name} v{modItem.Version} ({modItem.GetGameType()}) - Injected GSC file: {installFileName}"); MenuItemClearGscMods.Enabled = true; } } } LastInjectedGameType = modItem.GameType; SettingsData.UpdateInstalledMod(modItem.GameType, modItem.Id); SaveSettingsData(); if (ConsoleType.Equals("PS3")) { NotifyMessagePS3("^2Injected GSC Mods", $"{modItem.Name} v{modItem.Version} by {modItem.CreatedBy}", "party_ready"); } SetStatus($"{modItem.Name} v{modItem.Version} ({modItem.GetGameType()}) - Injected all GSC files."); XtraMessageBox.Show(this, $"Injected Mods: {modItem.Name}\nTime: {DateTime.Now:H:mm:ss}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { SetStatus($"Unable to inject GSC files. Error: {ex.Message}", ex); XtraMessageBox.Show(this, $"There was a problem injecting gsc files. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }