コード例 #1
0
ファイル: MainForm.cs プロジェクト: Drake53/War3App
        private static void DecompileMapBackgroundWork(object sender, DoWorkEventArgs e)
        {
            var outputFile = (string)e.Argument;

            var filesToDecompile = (MapFiles)0;

            foreach (var checkBox in _filesToDecompileCheckBoxes)
            {
                if (checkBox.Checked)
                {
                    filesToDecompile |= checkBox.MapFile;
                }
            }

            var decompiledMap = MapDecompiler.DecompileMap(_map, filesToDecompile, _worker);

            if (decompiledMap is null)
            {
                return;
            }

            var mapBuilder = new MapBuilder(decompiledMap);

            mapBuilder.AddFiles(_archive);
            mapBuilder.Build(outputFile);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Orden4/WCSharp
        public static void Build(bool launch)
        {
            // Ensure these folders exist
            Directory.CreateDirectory(ASSETS_FOLDER_PATH);
            Directory.CreateDirectory(OUTPUT_FOLDER_PATH);

            // Load existing map data
            var map     = Map.Open(BASE_MAP_PATH);
            var builder = new MapBuilder(map);

            builder.AddFiles(BASE_MAP_PATH, "*", SearchOption.AllDirectories);
            builder.AddFiles(ASSETS_FOLDER_PATH, "*", SearchOption.AllDirectories);

            // Set debug options if necessary, configure compiler
            var csc      = DEBUG ? "-debug -define:DEBUG" : null;
            var csproj   = Directory.EnumerateFiles(SOURCE_CODE_PROJECT_FOLDER_PATH, "*.csproj", SearchOption.TopDirectoryOnly).Single();
            var compiler = new Compiler(csproj, OUTPUT_FOLDER_PATH, string.Empty, null, "", "", csc, false, null, string.Empty)
            {
                IsExportMetadata       = true,
                IsModule               = false,
                IsInlineSimpleProperty = false,
                IsPreventDebugObject   = true,
                IsCommentsDisabled     = !DEBUG
            };

            // Collect required paths and compile
            var coreSystemFiles = CSharpLua.CoreSystem.CoreSystemProvider.GetCoreSystemFiles();
            var blizzardJ       = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Warcraft III/JassHelper/Blizzard.j");
            var commonJ         = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Warcraft III/JassHelper/common.j");
            var compileResult   = map.CompileScript(compiler, coreSystemFiles, blizzardJ, commonJ);

            // If compilation failed, output an error
            if (!compileResult.Success)
            {
                throw new Exception(compileResult.Diagnostics.First(x => x.Severity == DiagnosticSeverity.Error).GetMessage());
            }

            // Update war3map.lua so you can inspect the generated Lua code easily
            File.WriteAllText(Path.Combine(OUTPUT_FOLDER_PATH, OUTPUT_SCRIPT_NAME), map.Script);

            // Build w3x file
            var archiveCreateOptions = new MpqArchiveCreateOptions
            {
                ListFileCreateMode   = MpqFileCreateMode.Overwrite,
                AttributesCreateMode = MpqFileCreateMode.Prune,
                BlockSize            = 3,
            };

            builder.Build(Path.Combine(OUTPUT_FOLDER_PATH, OUTPUT_MAP_NAME), archiveCreateOptions);

            // Launch if that option was selected
            if (launch)
            {
                var wc3exe = ConfigurationManager.AppSettings["wc3exe"];
                if (File.Exists(wc3exe))
                {
                    var commandLineArgs = new StringBuilder();
                    var isReforged      = Version.Parse(FileVersionInfo.GetVersionInfo(wc3exe).FileVersion) >= new Version(1, 32);
                    if (isReforged)
                    {
                        commandLineArgs.Append(" -launch");
                    }
                    else if (GRAPHICS_API != null)
                    {
                        commandLineArgs.Append($" -graphicsapi {GRAPHICS_API}");
                    }

                    if (!PAUSE_GAME_ON_LOSE_FOCUS)
                    {
                        commandLineArgs.Append(" -nowfpause");
                    }

                    var mapPath         = Path.Combine(OUTPUT_FOLDER_PATH, OUTPUT_MAP_NAME);
                    var absoluteMapPath = new FileInfo(mapPath).FullName;
                    commandLineArgs.Append($" -loadfile \"{absoluteMapPath}\"");

                    Process.Start(wc3exe, commandLineArgs.ToString());
                }
                else
                {
                    throw new Exception("Please set wc3exe in Launcher/app.config to the path of your Warcraft III executable.");
                }
            }
        }