コード例 #1
0
ファイル: App.xaml.cs プロジェクト: wook8170/MetroWPFTemplate
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Load Settings
            Settings.LoadSettings(true);

            // Create Closing Method
            Current.Exit += (o, args) =>
            {
                // Update Settings with Window Width/Height
                Settings.ApplicationSizeMaximize = (Settings.HomeWindow.WindowState == WindowState.Maximized);
                if (!Settings.ApplicationSizeMaximize)
                {
                    Settings.ApplicationSizeWidth  = Settings.HomeWindow.Width;
                    Settings.ApplicationSizeHeight = Settings.HomeWindow.Height;
                }

                // Save Settings
                Settings.UpdateSettings();
            };

            // Global Exception Catching
#if !DEBUG
            Application.Current.DispatcherUnhandledException += (o, args) =>
            {
                MetroException.Show((Exception)args.Exception);

                args.Handled = true;
            };
#endif
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: abenavente406/Quickbeam
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Snazzy exception dialog
            Current.DispatcherUnhandledException += (o, args) =>
            {
                MetroException.Show(args.Exception);

                args.Handled = true;
            };

            // Create Assembly Storage
            MetroIdeStorage = new Storage();

            // Create jumplist
            JumpLists.UpdateJumplists();

            // Set closing method
            Current.Exit += (o, args) =>
            {
                // Update Settings with Window Width/Height
                MetroIdeStorage.MetroIdeSettings.ApplicationSizeMaximize =
                    (MetroIdeStorage.MetroIdeSettings.HomeWindow.WindowState == WindowState.Maximized);
                if (MetroIdeStorage.MetroIdeSettings.ApplicationSizeMaximize)
                {
                    return;
                }

                MetroIdeStorage.MetroIdeSettings.ApplicationSizeWidth =
                    MetroIdeStorage.MetroIdeSettings.HomeWindow.Width;
                MetroIdeStorage.MetroIdeSettings.ApplicationSizeHeight =
                    MetroIdeStorage.MetroIdeSettings.HomeWindow.Height;
            };
        }
コード例 #3
0
        private void StartupDetermineType(string path)
        {
            try
            {
                if (File.Exists(path))
                {/*
                  * // Magic Check
                  * string magic;
                  * using (var stream = new EndianReader(File.OpenRead(path), Endian.BigEndian))
                  *     magic = stream.ReadAscii(0x04).ToLower();
                  *
                  * switch (magic)
                  * {
                  *     case "head":
                  *     case "daeh":
                  *         // Map File
                  *         AddCacheTabModule(path);
                  *         return;
                  * }*/
                }

                MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #4
0
ファイル: Home.xaml.cs プロジェクト: mark-casey/Assembly
        private void StartupDetermineType(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    // Magic Check
                    string magic;
                    using (var stream = new EndianReader(File.OpenRead(path), Endian.BigEndian))
                        magic = stream.ReadAscii(0x04).ToLower();

                    switch (magic)
                    {
                    case "head":
                    case "daeh":
                        // Map File
                        AddCacheTabModule(path);
                        return;

                    case "asmp":
                        // Patch File
                        AddPatchTabModule(path);
                        return;

                    case "_blf":
                        // BLF Container, needs more checking
                        var blf = new PureBLF(path);
                        blf.Close();
                        if (blf.BLFChunks.Count > 2)
                        {
                            switch (blf.BLFChunks[1].ChunkMagic)
                            {
                            case "levl":
                                AddInfooTabModule(path);
                                return;

                            case "mapi":
                                AddImageTabModule(path);
                                return;
                            }
                        }
                        MetroMessageBox.Show("Unsupported BLF Type", "The selected BLF file is not supported in assembly.");
                        return;

                    default:
                        MetroMessageBox.Show("Unsupported file type", "The selected file is not supported in assembly.");
                        return;
                    }
                }

                MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #5
0
        private void PokeXenonPatch()
        {
            try
            {
                if (App.AssemblyStorage.AssemblySettings.Xbdm == null ||
                    String.IsNullOrEmpty(App.AssemblyStorage.AssemblySettings.Xbdm.DeviceIdent))
                {
                    MetroMessageBox.Show("No Xbox 360 Console Detected",
                                         "Make sure your xbox 360 console is turned on, and the IP is entered in the App.AssemblyStorage.AssemblySettings.");
                    return;
                }

                if (currentPatchToPoke.MetaChangesIndex >= 0)
                {
                    if (currentPatchToPoke.SegmentChanges.Count > 1)
                    {
                        if (MetroMessageBox.Show("Possible unexpected results ahead!",
                                                 "This patch contains edits to segments other than the meta, ie locales and the file header, it could crash if you continue. \n\nDo you wish to continue?",
                                                 MetroMessageBox.MessageBoxButtons.YesNo) == MetroMessageBox.MessageBoxResult.No)
                        {
                            return;
                        }
                    }

                    SegmentChange changes = currentPatchToPoke.SegmentChanges[currentPatchToPoke.MetaChangesIndex];
                    if (changes.OldSize != changes.NewSize)
                    {
                        // can't poke, patch injects meta
                        MetroMessageBox.Show("Unable to Poke Patch",
                                             "This patch contains meta that has been injected, and can't be poked.");
                        return;
                    }

                    foreach (DataChange change in changes.DataChanges)
                    {
                        App.AssemblyStorage.AssemblySettings.Xbdm.MemoryStream.Seek(currentPatchToPoke.MetaPokeBase + change.Offset,
                                                                                    SeekOrigin.Begin);
                        App.AssemblyStorage.AssemblySettings.Xbdm.MemoryStream.Write(change.Data, 0x00, change.Data.Length);
                    }
                }
                else if (currentPatchToPoke.MetaChanges.Count > 0)
                {
                    foreach (DataChange change in currentPatchToPoke.MetaChanges)
                    {
                        App.AssemblyStorage.AssemblySettings.Xbdm.MemoryStream.Seek(change.Offset, SeekOrigin.Begin);
                        App.AssemblyStorage.AssemblySettings.Xbdm.MemoryStream.Write(change.Data, 0x00, change.Data.Length);
                    }
                }

                MetroMessageBox.Show("Patch Poked!", "Your patch has been poked successfully. Have fun!");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #6
0
ファイル: Home.xaml.cs プロジェクト: nuwaching3/Assembly
 private void StartupDetermineType(string path)
 {
     try
     {
         ProcessContentFile(path);
     }
     catch (Exception ex)
     {
         MetroException.Show(ex);
     }
 }
コード例 #7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

#if !DEBUG
            Current.DispatcherUnhandledException += (o, args) =>
            {
                MetroException.Show(args.Exception);

                args.Handled = true;
            };
#endif
            // Reset Directory
            System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            // Load version info
            VersionInfo.Load("version.json");

            // Create Assembly Storage
            AssemblyStorage = new Storage();

            // Update Assembly Protocol
            AssemblyProtocol.UpdateProtocol();

            // Create jumplist
            JumpLists.UpdateJumplists();

            // Create XBDM Instance
            AssemblyStorage.AssemblySettings.Xbdm = new Xbdm(AssemblyStorage.AssemblySettings.XdkNameIp);

            // Try and delete all temp data
            VariousFunctions.EmptyUpdaterLocations();

            // Dubs, checkem
            _0xabad1dea.CheckServerStatus();

            // Update File Defaults
            FileDefaults.UpdateFileDefaults();

            // Set closing method
            Current.Exit += (o, args) =>
            {
                // Update Settings with Window Width/Height
                AssemblyStorage.AssemblySettings.ApplicationSizeMaximize =
                    (AssemblyStorage.AssemblySettings.HomeWindow.WindowState == WindowState.Maximized);
                if (AssemblyStorage.AssemblySettings.ApplicationSizeMaximize)
                {
                    return;
                }

                AssemblyStorage.AssemblySettings.ApplicationSizeWidth  = AssemblyStorage.AssemblySettings.HomeWindow.Width;
                AssemblyStorage.AssemblySettings.ApplicationSizeHeight = AssemblyStorage.AssemblySettings.HomeWindow.Height;
            };
        }
コード例 #8
0
        private void btnGrabImageFromXbox_Click(object sender, RoutedEventArgs e)
        {
            // Show Mask
            ImageGrabMask.Visibility = Visibility.Visible;
            btnAddImage.IsEnabled    = btnGrabImageFromXbox.IsEnabled = false;

            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (o, args) =>
            {
                try
                {
                    // Grab Screenshot from Xbox
                    string screenshotFileName = Path.GetTempFileName();
                    string screenshotPng      = Path.GetTempFileName();

                    if (!App.AssemblyStorage.AssemblySettings.Xbdm.GetScreenshot(screenshotFileName))
                    {
                        Dispatcher.Invoke(
                            new Action(
                                () =>
                                MetroMessageBox.Show("Not Connected", "You are not connected to a debug Xbox 360, unable to get screenshot")));
                        return;
                    }

                    // do stuff
                    BitmapSource bitmapSource = DDSConversion.Deswizzle(screenshotFileName, 1204, 720, true, true);

                    // convert to png
                    SaveImage(screenshotPng, bitmapSource);

                    // upload
                    string response = Imgur.UploadToImgur(File.ReadAllBytes(screenshotPng));

                    string finalString = string.Format("http://i.imgur.com/{0}.png", response);

                    Dispatcher.Invoke(new Action(() => _generatorViewModel.Images.Add(new ModPostInfo.Image
                    {
                        Url = finalString
                    })));
                }
                catch (Exception ex)
                {
                    Dispatcher.Invoke(new Action(() => MetroException.Show(ex)));
                }
            };
            backgroundWorker.RunWorkerCompleted += (o, args) =>
            {
                ImageGrabMask.Visibility = Visibility.Collapsed;
                btnAddImage.IsEnabled    = btnGrabImageFromXbox.IsEnabled = true;
            };
            backgroundWorker.RunWorkerAsync();
        }
コード例 #9
0
 private void SaveCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     IsEnabled = true;
     if (e.Error == null)
     {
         MetroMessageBox.Show("Language Pack Editor", "Strings saved successfully!");
     }
     else
     {
         MetroException.Show(e.Error);
     }
 }
コード例 #10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
#if !DEBUG
            Application.Current.DispatcherUnhandledException += (o, args) =>
            {
                MetroException.Show((Exception)args.Exception);

                args.Handled = true;
            };
#endif
        }
コード例 #11
0
        private void LoadPatchToPoke()
        {
            try
            {
                using (var reader = new EndianReader(File.OpenRead(txtPokePatchFile.Text), Endian.LittleEndian))
                {
                    string magic = reader.ReadAscii(4);
                    reader.SeekTo(0);

                    if (magic == "asmp")
                    {
                        // Load into UI
                        reader.Endianness             = Endian.BigEndian;
                        currentPatchToPoke            = AssemblyPatchLoader.LoadPatch(reader);
                        txtPokePatchAuthor.Text       = currentPatchToPoke.Author;
                        txtPokePatchDesc.Text         = currentPatchToPoke.Description;
                        txtPokePatchName.Text         = currentPatchToPoke.Name;
                        txtPokePatchInternalName.Text = currentPatchToPoke.MapInternalName;
                        //txtPokePatchMapID.Text = currentPatchToPoke.MapID.ToString(CultureInfo.InvariantCulture);

                        // Set Visibility
                        PokePatchControls.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        MetroMessageBox.Show("You can't poke a patch from Alteration/Ascension. Convert it to a Assembly Patch first");
                        return;
                    }
                }

                // Set Screenshot
                if (currentPatchToPoke.Screenshot == null)
                {
                    // Set default
                    var source = new Uri(@"/Assembly;component/Metro/Images/super_patcher.png", UriKind.Relative);
                    imgPokePreview.Source = new BitmapImage(source);
                }
                else
                {
                    var image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = new MemoryStream(currentPatchToPoke.Screenshot);
                    image.EndInit();
                    imgPokePreview.Source = image;
                }
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #12
0
ファイル: Home.xaml.cs プロジェクト: nuwaching3/Assembly
 internal void SessionManager_SessionDied(object sender, SessionDiedEventArgs e)
 {
     Dispatcher.InvokeAsync((Action) delegate
     {
         App.AssemblyStorage.AssemblyNetworkPoke.Clients.Clear();
         App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider.Kill();
         App.AssemblyStorage.AssemblyNetworkPoke.IsConnected        = false;
         App.AssemblyStorage.AssemblyNetworkPoke.IsServer           = false;
         App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider = null;
         App.AssemblyStorage.AssemblyNetworkPoke.PokeSessionManager = null;
         if (e != null && !(e.Error is IOException))
         {
             MetroException.Show(e.Error);
         }
         MetroMessageBox.Show("Group Poking Killed", "Peer poking session has stopped.  Reverting to local poking...");
     });
 }
コード例 #13
0
        //[STAThread]
        //public static void Main()
        //{

        //}

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Load Supported Builds
            Manager.SupportedGame = new Manager.SupportedGames();

            // Load Settings
            Settings.LoadSettings(true);

            // Update Liberty Protocol
            LibertyProtocol.UpdateProtocol();

            // Create Temporary Directories
            VariousFunctions.CreateTemporaryDirectories();

            // Clean-up Old Temporary Files
            VariousFunctions.CleanUpTemporaryFiles();

            // Create Closing Method
            Application.Current.Exit += (o, args) =>
            {
                // Update Settings with Window Width/Height
                Settings.applicationSizeMaximize = (Settings.HomeWindow.WindowState == WindowState.Maximized);
                if (!Settings.applicationSizeMaximize)
                {
                    Settings.applicationSizeWidth  = Settings.HomeWindow.Width;
                    Settings.applicationSizeHeight = Settings.HomeWindow.Height;
                }

                // Save Settings
                Settings.UpdateSettings();
            };

            // Global Exception Catching
#if !DEBUG
            Application.Current.DispatcherUnhandledException += (o, args) =>
            {
                MetroException.Show((Exception)args.Exception);

                args.Handled = true;
            };
#endif
        }
コード例 #14
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (
                    MetroMessageBox.Show("Plugin Conversion Failed!",
                                         "There was an error converting your plugins... Would you like to see it?", MetroMessageBox.MessageBoxButtons.YesNo) ==
                    MetroMessageBox.MessageBoxResult.Yes)
                {
                    MetroException.Show(e.Error);
                }
            }
            else
            {
                MetroMessageBox.Show("Plugin conversion Complete!", "Your plugins have been successfully converted.");
            }

            EndConversion();
        }
コード例 #15
0
        private void SignInThread(object credentialsObj)
        {
            // Try to Sign In
            try
            {
                var credentials = (UserCredentials)credentialsObj;

                // Send Signin Package to Server
                SignInResponse response = SignIn.AttemptSignIn(credentials.Username, credentials.Password);
                if (response == null || !response.Successful)
                {
                    Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to Sign In", response.ErrorMessage); }));
                    return;
                }

                // Set the UI to show that we have signed in successfully
                Dispatcher.Invoke(new Action(delegate
                {
                    gridNetworkType.Visibility = gridSignedIn.Visibility = Visibility.Visible;
                    gridSignIn.Visibility      = Visibility.Collapsed;
                    lblSignedInWelcome.Text    = response.DisplayName.ToLower();
                    lblSignedInPosts.Text      = string.Format("posts: {0:##,###}", response.PostCount);

                    // Validate Avatar
                    if (!string.IsNullOrEmpty(response.AvatarUrl) && response.AvatarUrl != "http://uploads.xbchaos.netdna-cdn.com/")
                    {
                        ImageLoader.LoadImageAndFade(imgSignedInAvatar, new Uri(response.AvatarUrl), new AnimationHelper(this));
                    }

                    MetroMessageBox.Show("welcome", "Welcome to network poking, " + response.DisplayName);
                }));
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(new Action(delegate { MetroException.Show(ex); }));
            }
        }
コード例 #16
0
        // Patch Applying
        private void btnApplyPatch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check the user isn't completly retarded
                if (!CheckAllApplyMandatoryFields() || currentPatch == null)
                {
                    return;
                }

                // Check the output name
                if (cacheOutputName != "")
                {
                    if (Path.GetFileNameWithoutExtension(txtApplyPatchOutputMap.Text) != cacheOutputName)
                    {
                        if (MetroMessageBox.Show("Warning",
                                                 "This patch suggests to use the filename \"" + cacheOutputName +
                                                 ".map\" to save this map. This filename may be required in order for the map to work correctly.\r\n\r\nAre you sure you want to save this map as \"" +
                                                 Path.GetFileName(txtApplyPatchOutputMap.Text) + "\"?",
                                                 MetroMessageBox.MessageBoxButtons.OkCancel) != MetroMessageBox.MessageBoxResult.OK)
                        {
                            Close();
                            return;
                        }
                    }
                }

                // Paths
                string unmoddedMapPath = txtApplyPatchUnmodifiedMap.Text;
                string outputPath      = txtApplyPatchOutputMap.Text;

                // Copy the original map to the destination path
                File.Copy(unmoddedMapPath, outputPath, true);

                // Open the destination map
                using (var stream = new EndianStream(File.Open(outputPath, FileMode.Open, FileAccess.ReadWrite), Endian.BigEndian))
                {
                    EngineDatabase engineDb  = XMLEngineDatabaseLoader.LoadDatabase("Formats/Engines.xml");
                    ICacheFile     cacheFile = CacheFileLoader.LoadCacheFile(stream, outputPath, engineDb);
                    if (currentPatch.MapInternalName != null && cacheFile.InternalName != currentPatch.MapInternalName)
                    {
                        MetroMessageBox.Show("Unable to apply patch",
                                             "Hold on there! That patch is for " + currentPatch.MapInternalName +
                                             ".map, and the unmodified map file you selected doesn't seem to match that. Find the correct file and try again.");
                        return;
                    }
                    if (!string.IsNullOrEmpty(currentPatch.BuildString) && cacheFile.BuildString != currentPatch.BuildString)
                    {
                        MetroMessageBox.Show("Unable to apply patch",
                                             "Hold on there! That patch is for a map with a build version of" + currentPatch.BuildString +
                                             ", and the unmodified map file you selected doesn't seem to match that. Find the correct file and try again.");
                        return;
                    }

                    // Apply the patch!
                    if (currentPatch.MapInternalName == null)
                    {
                        currentPatch.MapInternalName = cacheFile.InternalName;
                    }
                    // Because Ascension doesn't include this, and ApplyPatch() will complain otherwise

                    PatchApplier.ApplyPatch(currentPatch, cacheFile, stream);

                    // Check for blf snaps
                    if (cbApplyPatchBlfExtraction.IsChecked != null &&
                        (PatchApplicationPatchExtra.Visibility == Visibility.Visible && (bool)cbApplyPatchBlfExtraction.IsChecked))
                    {
                        string extractDir   = Path.GetDirectoryName(outputPath);
                        string blfDirectory = Path.Combine(extractDir, "images");
                        string infDirectory = Path.Combine(extractDir, "info");
                        if (!Directory.Exists(blfDirectory))
                        {
                            Directory.CreateDirectory(blfDirectory);
                        }
                        if (!Directory.Exists(infDirectory))
                        {
                            Directory.CreateDirectory(infDirectory);
                        }

                        string infPath = Path.Combine(infDirectory, Path.GetFileName(currentPatch.CustomBlfContent.MapInfoFileName));
                        File.WriteAllBytes(infPath, currentPatch.CustomBlfContent.MapInfo);

                        foreach (BlfContainerEntry blfContainerEntry in currentPatch.CustomBlfContent.BlfContainerEntries)
                        {
                            string blfPath = Path.Combine(blfDirectory, Path.GetFileName(blfContainerEntry.FileName));
                            File.WriteAllBytes(blfPath, blfContainerEntry.BlfContainer);
                        }
                    }
                }

                MetroMessageBox.Show("Patch Applied!", "Your patch has been applied successfully. Have fun!");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #17
0
        // Meta Sorting

        private void LoadPatch(bool isAlteration)
        {
            try
            {
                using (var reader = new EndianReader(File.OpenRead(txtApplyPatchFile.Text), Endian.LittleEndian))
                {
                    string magic = reader.ReadAscii(4);
                    reader.SeekTo(0);

                    if (magic == "asmp")
                    {
                        // Load into UI
                        reader.Endianness              = Endian.BigEndian;
                        currentPatch                   = AssemblyPatchLoader.LoadPatch(reader);
                        txtApplyPatchAuthor.Text       = currentPatch.Author;
                        txtApplyPatchDesc.Text         = currentPatch.Description;
                        txtApplyPatchName.Text         = currentPatch.Name;
                        txtApplyPatchInternalName.Text = currentPatch.MapInternalName;
                        //txtApplyPatchMapID.Text = currentPatch.MapID.ToString(CultureInfo.InvariantCulture);

                        // Set Visibility
                        PatchApplicationPatchExtra.Visibility =
                            currentPatch.CustomBlfContent != null
                                                                ? Visibility.Visible
                                                                : Visibility.Collapsed;
                        ApplyPatchControls.Visibility = Visibility.Visible;
                        btnExtractInfo.IsEnabled      = true;
                    }
                    else
                    {
                        currentPatch                   = OldPatchLoader.LoadPatch(reader, isAlteration);
                        txtApplyPatchAuthor.Text       = currentPatch.Author;
                        txtApplyPatchDesc.Text         = currentPatch.Description;
                        txtApplyPatchName.Text         = "Ascension/Alteration Patch";
                        txtApplyPatchInternalName.Text = "Ascension/Alteration Patch";

                        ApplyPatchControls.Visibility         = Visibility.Visible;
                        PatchApplicationPatchExtra.Visibility = Visibility.Collapsed;
                        btnExtractInfo.IsEnabled = false;
                    }
                    if (currentPatch.OutputName != null)
                    {
                        cacheOutputName = currentPatch.OutputName;
                    }
                }

                // Set Screenshot
                if (currentPatch.Screenshot == null)
                {
                    // Set default
                    var source = new Uri(@"/Assembly;component/Metro/Images/super_patcher.png", UriKind.Relative);
                    imgApplyPreview.Source = new BitmapImage(source);
                }
                else
                {
                    var image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = new MemoryStream(currentPatch.Screenshot);
                    image.EndInit();
                    imgApplyPreview.Source = image;
                }
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #18
0
        // Patch Creation
        private void btnCreatePatch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check the user isn't completly retarded
                if (!CheckAllCreateMandatoryFields())
                {
                    return;
                }

                // Check the user isn't a skid
                if (!CheckAllCreateMetaFilesExists())
                {
                    return;
                }

                // Paths
                string cleanMapPath  = txtCreatePatchUnModifiedMap.Text;
                string moddedMapPath = txtCreatePatchModifiedMap.Text;
                string outputPath    = txtCreatePatchOutputPatch.Text;
                string previewImage  = txtCreatePatchPreviewImage.Text;

                // Details
                string author     = txtCreatePatchContentAuthor.Text;
                string desc       = txtCreatePatchContentDescription.Text;
                string name       = txtCreatePatchContentName.Text;
                string outputName = txtCreatePatchOutputName.Text;

                // Make dat patch
                var patch = new Patch
                {
                    Author      = author,
                    Description = desc,
                    Name        = name,
                    OutputName  = outputName,
                    Screenshot  = String.IsNullOrEmpty(previewImage)
                                                ? null
                                                : File.ReadAllBytes(previewImage),
                    BuildString = _buildInfo.Version,
                    PC          = String.IsNullOrEmpty(_buildInfo.GameExecutable)
                                                ? false
                                                : true
                };

                EndianReader originalReader = null;
                EndianReader newReader      = null;
                try
                {
                    originalReader = new EndianReader(File.OpenRead(cleanMapPath), Endian.BigEndian);
                    newReader      = new EndianReader(File.OpenRead(moddedMapPath), Endian.BigEndian);

                    ICacheFile originalFile = CacheFileLoader.LoadCacheFile(originalReader, cleanMapPath,
                                                                            App.AssemblyStorage.AssemblySettings.DefaultDatabase);
                    ICacheFile newFile = CacheFileLoader.LoadCacheFile(newReader, moddedMapPath, App.AssemblyStorage.AssemblySettings.DefaultDatabase);

                    if (cbCreatePatchHasCustomMeta.IsChecked != null && (bool)cbCreatePatchHasCustomMeta.IsChecked &&
                        cboxCreatePatchTargetGame.SelectedIndex < 4)
                    {
                        var      targetGame      = (TargetGame)cboxCreatePatchTargetGame.SelectedIndex;
                        byte[]   mapInfo         = File.ReadAllBytes(txtCreatePatchMapInfo.Text);
                        var      mapInfoFileInfo = new FileInfo(txtCreatePatchMapInfo.Text);
                        FileInfo blfFileInfo;

                        patch.CustomBlfContent = new BlfContent(mapInfoFileInfo.FullName, mapInfo, targetGame);

                        #region Blf Data

                        if (PatchCreationBlfOption0.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf0.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption1.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf1.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption2.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf2.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption3.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf3.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }

                        #endregion
                    }

                    PatchBuilder.BuildPatch(originalFile, originalReader, newFile, newReader, patch);
                }
                finally
                {
                    if (originalReader != null)
                    {
                        originalReader.Dispose();
                    }
                    if (newReader != null)
                    {
                        newReader.Dispose();
                    }
                }

                IWriter output = new EndianWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write), Endian.BigEndian);
                AssemblyPatchWriter.WritePatch(patch, output);
                output.Dispose();

                MetroMessageBox.Show("Patch Created!",
                                     "Your patch has been created in the designated location. Happy sailing, modder!");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
コード例 #19
0
        private void PokePCPatch()
        {
            try
            {
                if (string.IsNullOrEmpty(currentPatchToPoke.BuildString))
                {
                    return;
                }

                var pokeInfo = App.AssemblyStorage.AssemblySettings.DefaultDatabase.FindEngineByVersion(currentPatchToPoke.BuildString);
                if (pokeInfo == null)
                {
                    MetroMessageBox.Show("Unsupported Build",
                                         "This patch is for a build (" + currentPatchToPoke.BuildString + ") that this installation of Assembly does not support. Make sure you are up to date or add a definition manually.");
                    return;
                }

                if (pokeInfo.Name.Contains("Vista"))
                {
                    MetroMessageBox.Show("Unsupported Build",
                                         "This patch is for Halo 2 Vista which cannot be poked at this time.");
                    return;
                }

                if (string.IsNullOrEmpty(pokeInfo.GameExecutable) || string.IsNullOrEmpty(pokeInfo.GameModule) || pokeInfo.Poking == null)
                {
                    MetroMessageBox.Show("Unsupported Build",
                                         "This patch is for a build (" + pokeInfo.Version + ") that this installation of Assembly does not have enough information for to poke patches.\r\n" +
                                         "This includes a gameExecutable and gameModule value and a poking definition which includes a pointer with the game version you are running.\r\n" +
                                         "Make sure you are up to date or add a definition manually.");
                    return;
                }



                var gameRTE    = new ThirdGenMCCRTEProvider(pokeInfo);
                var gameStream = gameRTE.GetMetaStream();

                if (currentPatchToPoke.MetaChangesIndex >= 0)
                {
                    if (currentPatchToPoke.SegmentChanges.Count > 1)
                    {
                        if (MetroMessageBox.Show("Possible unexpected results ahead!",
                                                 "This patch contains edits to segments other than the meta, ie locales and the file header, it could crash if you continue. \n\nDo you wish to continue?",
                                                 MetroMessageBox.MessageBoxButtons.YesNo) == MetroMessageBox.MessageBoxResult.No)
                        {
                            return;
                        }
                    }

                    SegmentChange changes = currentPatchToPoke.SegmentChanges[currentPatchToPoke.MetaChangesIndex];
                    if (changes.OldSize != changes.NewSize)
                    {
                        // can't poke, patch injects meta
                        MetroMessageBox.Show("Unable to Poke Patch",
                                             "This patch contains meta that has been injected, and can't be poked.");
                        return;
                    }

                    foreach (DataChange change in changes.DataChanges)
                    {
                        gameStream.BaseStream.Seek(currentPatchToPoke.MetaPokeBase + change.Offset,
                                                   SeekOrigin.Begin);
                        gameStream.BaseStream.Write(change.Data, 0x00, change.Data.Length);
                    }
                }
                else if (currentPatchToPoke.MetaChanges.Count > 0)
                {
                    foreach (DataChange change in currentPatchToPoke.MetaChanges)
                    {
                        gameStream.BaseStream.Seek(change.Offset, SeekOrigin.Begin);
                        gameStream.BaseStream.Write(change.Data, 0x00, change.Data.Length);
                    }
                }

                MetroMessageBox.Show("Patch Poked!", "Your patch has been poked successfully. Have fun!");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }