コード例 #1
0
ファイル: VariantController.cs プロジェクト: 0xdeafcafe/Onyx
        // POST api/variant
        public string Post()
        {
            if (!(Request.Content is StreamContent))
            {
                throw new InvalidOperationException();
            }

            try
            {
                var data = Request.Content as StreamContent;

                var newData    = data.ReadAsByteArrayAsync().Result;
                var gt         = GameType.Load(newData);
                var decompiler = new WumboScriptDecompiler();
                decompiler.AddScript(gt.Script);

                var outputPath = Path.GetTempFileName();
                using (var output = new StreamWriter(outputPath))
                {
                    output.WriteLine("-- Decompiled with Onyx");
                    output.WriteLine("-- Variant name: " + gt.ContentName);
                    output.WriteLine("-- Base variant: " + gt.MegaloStrings[gt.BaseNameStringIndex].English);
                    output.WriteLine();
                    decompiler.Finish(output);
                }

                return(File.ReadAllText(outputPath));
            }
            catch
            {
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
        private void btnCreateAndDeploy_Click(object sender, EventArgs e)
        {
            var tempStfsFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\gfaiutzayvy545555iuug2vmslaqbaaaaaaaaaaaa";

            File.Copy(_inputStfsPackage, tempStfsFile, true);

            // Get Base Shit
            Stream templateStfs = new FileStream(tempStfsFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var    stfs         = new StfsPackage(templateStfs)
            {
                Name = string.Format("{0}/{1} - Yrs2013", _cityA, _cityB)
            };

            stfs.SaveMetadata();

            // Extract shit
            var tempFile = Path.GetTempFileName();

            stfs.ExtractFile("variant", tempFile);

            // Load Shit
            var gametype = GameType.Load(tempFile);

            gametype = CreateMegaloGametype(gametype, Convert.ToUInt32(txtGametypeLength.Text));

            // Save Shit
            gametype.Save(tempFile);
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant"))
            {
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");
            }
            File.Copy(tempFile, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");

            // Inject Shit
            stfs.ReplaceFile(tempFile, "variant");

            // Fix Shit
            stfs.Rehash();
            stfs.SaveChanges(@"Stfs/KV_D.bin");
            templateStfs.Close();

            // Transfer Stuff
            XboxCommunication.XboxCopy(tempStfsFile, @"hdd:\Content\E00006B45A52FF20\4D530919\00000001");

            // Tell Shit
            MessageBox.Show("Gametype deployed to console");
        }
コード例 #3
0
ファイル: CreateController.cs プロジェクト: 0xdeafcafe/Onyx
        public ActionResult Index(CreateProject createProject, HttpPostedFileBase stfsUpload)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // Get the User
            var user = Helpers.GetAuthenticatedUser();

            if (user == null)
            {
                return(View());
            }

            // Check Name is Unique
            if (_dbContext.Projects.Count(p =>
                                          !p.IsDeleted && p.Name.ToLower().Equals(createProject.ProjectName.ToLower())) > 0)
            {
                ModelState.AddModelError("ProjectName", "You can't have 2 Projects with the same name.");
                return(View());
            }

            // Do file validation stuff
            if (stfsUpload == null)
            {
                ModelState.AddModelError("File", "You must select a Halo 4 Gametype to create a project.");
                return(View());
            }
            else
            {
                var outputPath      = Path.GetTempFileName();
                var variantExtrated = Path.GetTempFileName();
                System.IO.File.WriteAllBytes(outputPath, VariousFunctions.StreamToByteArray(stfsUpload.InputStream));
                try
                {
                    var stfsParsed = new StfsPackage(outputPath);

                    // Validate contains variant
                    if (!stfsParsed.FileExists("variant"))
                    {
                        throw new Exception();
                    }

                    // Extract variant
                    stfsParsed.ExtractFile("variant", variantExtrated);

                    var gametype = GameType.Load(variantExtrated);

                    // TODO: seralize gametype data
                    var seralizedData = "";

                    // Write data to Database
                    var project = new Project
                    {
                        Name        = createProject.ProjectName,
                        Description = createProject.ProjectDescription,
                        UserId      = user.Id
                    };

                    // Write data to the S3 Bucket
                    try
                    {
                        var s3 = new S3Storage();
                        s3.WriteObject(VariousFunctions.StreamToByteArray(stfsUpload.InputStream),
                                       S3Storage.StorageLocations.Stfs, project.StfsId);
                        s3.WriteObject(seralizedData,
                                       S3Storage.StorageLocations.Solution, project.SolutionId);
                    }
                    catch
                    {
                        return(RedirectToAction("Index").Error("There was an unknown error trying to create the project."));
                    }

                    // Save project to database
                    _dbContext.Projects.Add(project);
                    _dbContext.SaveChanges();

                    // Delete files now we done, yo
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    // Redirect outa here
                    return(RedirectToAction("Edit", new { id = project.Id }));
                }
                catch
                {
                    // Uh Oh, NSA - get the f**k out of here, and delete all the evidence.
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    ModelState.AddModelError("File", "Invalid Halo 4 Gametype.");
                    return(View());
                }
            }
        }