예제 #1
0
        void DecodeSaveVariant(KBlam.RuntimeData.Variants.GameEngineVariant gev, string xmlFilename,
                               MegaloModel.MegaloScriptModelTagElementStreamFlags modelStreamFlags, bool ignoreWritePredicates)
        {
            var megalo_variant = gev.TryGetMegaloVariant();

            if (megalo_variant != null)
            {
                megalo_variant.TagElementStreamSerializeFlags =
                    KBlam.RuntimeData.Variants.GameEngineMegaloVariantTagElementStreamFlags.UseStringTableNames |
                    KBlam.RuntimeData.Variants.GameEngineMegaloVariantTagElementStreamFlags.UseUserOptionNames;
                megalo_variant.EngineDefinition.TagElementStreamSerializeFlags =
                    modelStreamFlags;
            }

            using (var xml = IO.XmlElementStream.CreateForWrite("GameVariant"))
            {
                xml.StreamMode            = FileAccess.Write;
                xml.IgnoreWritePredicates = ignoreWritePredicates;

                gev.Serialize(xml);

                using (var sw = new System.IO.StreamWriter(xmlFilename, false, System.Text.Encoding.UTF8))
                    xml.Document.Save(sw);
            }
        }
예제 #2
0
        bool EncodeVariantBlob(FileStream fs,
                               KBlam.RuntimeData.Variants.GameEngineVariant gev)
        {
            var megalo_variant = gev.TryGetMegaloVariant();
            var blf_result     = KBlam.Blob.Transport.BlobChunkVerificationResultInfo.ValidResult;

            long blffile_length = KBlam.Blob.GameEngineVariantBlob.GetBlfFileLength(mGameBuildAndTarget);

            using (var blf = new KBlam.Blob.Transport.BlobTransportStream())
            {
                blf.GameTarget = mGameBuildAndTarget;

                var blob_system = mRequiredSystems.BlobSystemRef.System;

                if (fs.Length < blffile_length)
                {
                    fs.SetLength(blffile_length);
                }

                blf_result = blf.OpenForWrite(fs, mFileOffset, blffile_length);
                if (blf_result.IsValid)
                {
                    blf.UnderlyingStream.StreamMode = FileAccess.Write;

                    int engine_version_to_write = mEngineVersion;
                    if (megalo_variant != null)
                    {
                        if (megalo_variant.EngineVersion <= 0)
                        {
                            megalo_variant.EngineVersion = engine_version_to_write;
                        }
                        else
                        {
                            engine_version_to_write = megalo_variant.EngineVersion;
                        }
                    }

                    var chdr = (KBlam.Blob.ContentHeaderBlob)blob_system.CreateObject(mGameBuildAndTarget, KBlam.Blob.WellKnownBlob.ContentHeader);
                    chdr.ChangeData(gev.Variant.BaseVariant.Header, engine_version_to_write);

                    var mpvr = (KBlam.Blob.GameEngineVariantBlob)blob_system.CreateObject(mGameBuildAndTarget, KBlam.Blob.WellKnownBlob.GameVariant);
                    mpvr.ChangeData(gev);

                    blf_result = blf.WriteChunksSansAuthentication(chdr, mpvr);
                }
            }

            if (blf_result.IsInvalid)
            {
                Console.WriteLine("Error: Failed to encode variant file{0}{1}", System.Environment.NewLine,
                                  blf_result.BuildErrorMessage());
            }

            return(blf_result.IsValid);
        }
예제 #3
0
        bool EncodeVariantPreprocess(
            KBlam.RuntimeData.Variants.GameEngineVariant gev, string filePath)
        {
            var mv = gev.TryGetMegaloVariant();

            if (mv == null)
            {
                return(true);
            }

            if (mClearTitleUpdateData)
            {
                mv.ClearTitleUpdateData();
            }
            if (mClearWeaponTuning)
            {
                mv.ClearWeaponTunings();
            }

            // #TODO_MGLO: AddAllTeams

            return(true);
        }
예제 #4
0
        bool EncodeVariantPreprocess(EncodeSwitches switches,
                                     KBlam.RuntimeData.Variants.GameEngineVariant gev, string filePath)
        {
            const string k_teams_xml_filename = @"Games\Halo4\Definitions\VariantGameTeams.xml";

            var mv = gev.TryGetMegaloVariant();

            #region CreateVariantFile
            if ((switches & EncodeSwitches.CreateVariantFile) != 0)
            {
                string dir = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(dir))
                {
                    Console.WriteLine("Error: The directory for the game file doesn't exist or is inaccessible: {0}",
                                      dir);
                    return(false);
                }

                using (var fs = File.Create(filePath))
                {
                    fs.SetLength(KBlam.Blob.GameEngineVariantBlob.GetBlfFileLength(mGameBuildAndTarget));
                }
            }
            else if (!File.Exists(filePath))
            {
                Console.WriteLine("Error: Output game file does not exist");
                return(false);
            }
            #endregion
            #region ClearWeaponTuning
            if ((switches & EncodeSwitches.ClearWeaponTuning) != 0 && mv != null)
            {
                mv.ClearWeaponTunings();
            }
            #endregion
            #region AddAllTeams
            if ((switches & EncodeSwitches.AddAllTeams) != 0 && mGameBuildAndTarget.Build.IsWithinSameBranch(KBlam.Engine.EngineRegistry.EngineBranchHalo4))
            {
                var bv = gev.Variant.BaseVariant;

                foreach (var team in bv.TeamOptions.Teams)
                {
                    team.NameString.Clear();
                }

                if (File.Exists(k_teams_xml_filename))
                {
                    using (var xml = new IO.XmlElementStream(k_teams_xml_filename, System.IO.FileAccess.Read))
                    {
                        xml.InitializeAtRootElement();
                        xml.StreamMode = System.IO.FileAccess.Read;

                        var team_xml_game = KBlam.Engine.EngineBuildHandle.None;
                        KBlam.Engine.EngineBuildHandle.Serialize(xml, ref team_xml_game);
                        if (team_xml_game.IsWithinSameBranch(KBlam.Engine.EngineRegistry.EngineBranchHalo4))
                        {
                            bv.TeamOptions.SerializeTeams(xml);
                        }
                        else
                        {
                            Console.WriteLine("Warning: Teams xml is not for this game, not modifying variant's team data");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Warning: Teams xml not found, not modifying variant's team data");
                }
            }
            #endregion

            if (mv == null)
            {
                return(true);
            }

            #region sanity check category name
#if false
            string megalo_category_name;
            if (mv != null && mCornbread == false && mCategoryIndexToName.TryGetValue(mv.EngineCategory, out megalo_category_name))
            {
                if (mv.CategoryString.Count == 0)
                {
                    mv.CategoryString.Add(megalo_category_name);
                }
                else if (mv.CategoryString[0].English != megalo_category_name)
                {
                    mv.CategoryString[0].Set(megalo_category_name);
                }
            }
            else if (mv != null && mCornbread == false)
            {
                Console.WriteLine("Warning: Invalid Megalo category data {0}, defaulting",
                                  mv.EngineCategory);

                mv.BaseVariant.Header.EngineCategoryIndex = mv.EngineCategory = kCommunityCategoryIndex;
                if (mv.CategoryString.Count == 0)
                {
                    mv.CategoryString.Add(kCommunityCategory);
                }
                else
                {
                    mv.CategoryString[0].Set(kCommunityCategory);
                }
            }
#endif
            #endregion
            #region watermark
#if false
            if (mv != null)
            {
                var mv_h4 = mv as KBlam.Games.Halo4.RuntimeData.Variants.GameEngineMegaloVariantHalo4;

                if (mv_h4 != null)
                {
                    const string k_water_mark = "Halomods in your pods!";

                    if (mv_h4.IntroDescriptionString.Count == 0)
                    {
                        mv_h4.IntroDescriptionString.Add(k_water_mark);
                    }
                    else
                    {
                        mv_h4.IntroDescriptionString[0].Set(k_water_mark);
                    }
                }
            }
#endif
            #endregion

            return(true);
        }