Exemple #1
0
        public static bool Move(ServerMod sm)
        {
            string folderPath = Path.Combine(Program.Settings.GitDirectory, sm.GitPath);
            string modPath    = Path.Combine(Program.Settings.GitDirectory, sm.Name) + ".pbo";

            try {
                File.Copy(modPath, sm.ServerPath, true);

                Console.WriteLine($"Moved ({sm.Name}): {modPath} => {sm.ServerPath}");

                return(true);
            } catch (Exception ex) {
                Console.WriteLine("Error moving files");
                Util.Assert(ex);
                return(false);
            }
        }
Exemple #2
0
        public static void Pack(ServerMod sm)
        {
            string folderPath = Path.Combine(Program.Settings.GitDirectory, sm.GitPath);
            string modPath    = Path.Combine(Program.Settings.GitDirectory, sm.Name);

            if (sm.UseObfuSQF)
            {
                Console.WriteLine($"Running ObfuSQF for {sm.Name}\n");

                string obfuPath = Path.Combine(Program.Settings.ObfuSQFDirectory, "ObfuSQF_CMD.exe");
                string type     = sm.ObfuSQFMission ? "Mission" : "Mod";

                ProcessStartInfo obfu = new ProcessStartInfo(obfuPath);
                obfu.Arguments       = $"--token {Program.Settings.ObfuSQFToken} --input \"{folderPath}\" --type {type} --output \"{modPath}.pbo\"";
                obfu.UseShellExecute = false;
                obfu.CreateNoWindow  = true;

                ObfuProcs.Add(Process.Start(obfu));
            }
            else
            {
                Console.WriteLine($"Packing {sm.Name}\n");

                PboFile pbo = new PboFile();

                foreach (string s in Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories))
                {
                    string path = s.Replace(folderPath, "");

                    if (path.StartsWith(@"\"))
                    {
                        path = path.Substring(1);
                    }

                    string file = File.ReadAllText(s);

                    pbo.AddEntry(path, Encoding.UTF8.GetBytes(file));
                }

                pbo.Save($"{modPath}.pbo");
            }
        }
Exemple #3
0
        public static bool GitDownload(ServerMod sm)
        {
            if (pulledGits.Contains(sm.GitUrl.ToLower()))
            {
                return(true);
            }
            pulledGits.Add(sm.GitUrl.ToLower());

            Console.WriteLine("");
            Console.WriteLine("Pulling from git...");

            try {
                string token = sm.GitToken.Replace("token ", "");

                string gitPath = Path.Combine(Program.Settings.GitDirectory + "/git.zip");

                if (!Directory.Exists(Program.Settings.GitDirectory))
                {
                    Directory.CreateDirectory(Program.Settings.GitDirectory);
                }


                using (WebClient wc = new WebClient()) {
                    if (sm.GitType == 1)
                    {
                        wc.Headers.Add("Authorization", "token " + token);
                        Console.WriteLine($"{sm.Name} using GitHub");
                    }
                    else if (sm.GitType == 2)
                    {
                        wc.Headers.Add("Private-Token", token);
                        Console.WriteLine($"{sm.Name} using GitLab");
                    }
                    else
                    {
                        throw new Exception("Unknown git type! 1 = GitHub, 2 = GitLab");
                    }
                    wc.DownloadFile(sm.GitUrl, gitPath);
                }

                if (Directory.Exists(Path.Combine(Program.Settings.GitDirectory, sm.GitPath)))
                {
                    Directory.Delete(Program.Settings.GitDirectory, true);
                }
                Directory.CreateDirectory(Program.Settings.GitDirectory);

                // very dirty hack for gitlab stupid file bullshit
                if (sm.GitType == 2)
                {
                    using (ZipArchive archive = ZipFile.OpenRead(gitPath)) {
                        string folderName = archive.Entries[0].FullName;

                        foreach (ZipArchiveEntry entry in archive.Entries.Skip(1))
                        {
                            string name = Program.Settings.GitDirectory + "/" + entry.FullName.Replace(folderName, "");
                            if (entry.FullName.EndsWith("/"))
                            {
                                Directory.CreateDirectory(name);
                            }
                            else
                            {
                                entry.ExtractToFile(name);
                            }
                        }
                    }
                }
                else
                {
                    ZipFile.ExtractToDirectory(gitPath, Program.Settings.GitDirectory); // github :)
                }

                return(true);
            } catch (Exception ex) {
                Console.WriteLine("Error in download: " + ex);
                return(false);
            }
        }
Exemple #4
0
        public static bool GitDownload(ServerMod sm)
        {
            if (pulledGits.Contains(sm.GitUrl.ToLower()))
            {
                return(true);
            }

            pulledGits.Add(sm.GitUrl.ToLower());

            Console.WriteLine("");
            Console.WriteLine("Pulling from git...");

            try {
                string token = sm.GitToken.Replace("token ", "");

                string gitName = Path.GetFileNameWithoutExtension(sm.GitUrl);
                string gitPath = Path.Combine(Program.Settings.GitDirectory, gitName);

                if (!Directory.Exists(Program.Settings.GitDirectory))
                {
                    Directory.CreateDirectory(Program.Settings.GitDirectory);
                }

                // This options allows you to use the SSH option. (Allows for Repo specific auth)
                if (sm.GitType == 3)
                {
                    if (Directory.Exists(gitPath))
                    {
                        return(true);
                    }

                    string branch = "";

                    if (sm.GitPath != "")
                    {
                        branch = $" -b {sm.GitPath}";
                    }

                    Process.Start(new ProcessStartInfo
                    {
                        WorkingDirectory = Program.Settings.GitDirectory,
                        FileName         = "git",
                        Arguments        = $"clone --depth=1{branch} {sm.GitUrl}",
                        UseShellExecute  = false,
                        CreateNoWindow   = true
                    }).WaitForExit();

                    Program.DeleteDirectory(Path.Combine(Program.Settings.GitDirectory, gitName, ".git"));

                    return(true);
                }


                if (Directory.Exists(Path.Combine(Program.Settings.GitDirectory, sm.GitPath)))
                {
                    Directory.Delete(Program.Settings.GitDirectory, true);
                }
                Directory.CreateDirectory(Program.Settings.GitDirectory);

                if (sm.GitType == 2)
                {
                    CloneOptions co = new CloneOptions
                    {
                        CredentialsProvider = (_url, _user, _cred) =>
                                              new UsernamePasswordCredentials
                        {
                            Username = "******",
                            Password = sm.GitToken
                        }
                    };
                    if (sm.GitPath != "")
                    {
                        co.BranchName = sm.GitPath;
                    }
                    Repository.Clone(sm.GitUrl, gitPath, co);
                }
                else
                {
                    CloneOptions co = new CloneOptions
                    {
                        CredentialsProvider = (_url, _user, _cred) =>
                                              new UsernamePasswordCredentials
                        {
                            Username = sm.GitToken,
                            Password = string.Empty
                        }
                    };
                    if (sm.GitPath != "")
                    {
                        co.BranchName = sm.GitPath;
                    }
                    Repository.Clone(sm.GitUrl, gitPath, co);
                }

                return(true);
            } catch (Exception ex) {
                Console.WriteLine("Error in download: " + ex);
                return(false);
            }
        }
Exemple #5
0
        static void RandomizeEverything(ServerMod sm)
        {
            string folderPath = Path.Combine(Settings.GitDirectory, sm.GitPath);


            Console.WriteLine("Begining obfuscation");


            string[] files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                if (file.EndsWith(".ogg") || file.EndsWith(".paa") || file.EndsWith(".jpg") || file.EndsWith(".png"))
                {
                    continue;
                }

                string outName = file;

                string contents = File.ReadAllText(file);

                if (sm.RenameGlobalVars)
                {
                    contents = Util.RenameVars(contents, _globalVars);
                }

                if (sm.RenameLocalVars)
                {
                    contents = Util.RenameVars(contents, _localVars);
                }

                if (sm.RenameFuncs)
                {
                    foreach (KeyValuePair <string, string> kv in _scriptFuncs)
                    {
                        contents = contents.Replace(kv.Key, kv.Value);

                        if (file.Contains(kv.Key))
                        {
                            outName = file.Replace(kv.Key, kv.Value);
                        }
                    }
                }

                if (sm.OneLine)
                {
                    if (file.EndsWith(".sqf"))
                    {
                        contents = FileEdit.OneLine(contents);
                    }
                }

                File.WriteAllText(file, contents);
                if (file != outName)
                {
                    Console.WriteLine($"Filename: {file} => {outName}");
                    File.Move(file, outName);
                }
            }

            Console.WriteLine($"{sm.Name} obfuscated.");
        }
Exemple #6
0
        public static void Pack(ServerMod sm)
        {
            string gitName = Path.GetFileNameWithoutExtension(sm.GitUrl);

            string gitPath    = Path.Combine(Program.Settings.GitDirectory, gitName);
            string folderPath = Path.Combine(gitPath, sm.Name);
            string modPath    = Path.Combine(Program.Settings.GitDirectory, sm.Name);

            Console.WriteLine($"{folderPath} : {modPath}");



            if (sm.PackingMethod == PackingMethod.ObfuSQF)
            {
                Console.WriteLine($"Running ObfuSQF for {sm.Name}\n");

                string obfuPath = Path.Combine(Program.Settings.ObfuSQFDirectory, "ObfuSQF_CMD.exe");
                string type     = sm.ObfuSQFMission ? "Mission" : "Mod";

                ProcessStartInfo obfu = new ProcessStartInfo(obfuPath)
                {
                    Arguments       = $"--token {Program.Settings.ObfuSQFToken} --input \"{folderPath}\" --type {type} --output \"{modPath}.pbo\"",
                    UseShellExecute = false,
                    CreateNoWindow  = true
                };

                ObfuProcs.Add(Process.Start(obfu));
            }
            else if (sm.PackingMethod == PackingMethod.Normal)
            {
                Console.WriteLine($"Packing {sm.Name}\n");

                PboFile pbo = new PboFile();
                foreach (string s in Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories))
                {
                    string filename = Path.GetFileName(s);
                    if (filename == "mission.sqm")
                    {
                        string Rapify = Path.Combine(Program.Settings.ToolsDirectory, "CfgConvert", "CfgConvert.exe");

                        if (File.Exists(Rapify) /*&& false*/)
                        {
                            Console.WriteLine("Binarising SQM");
                            Process.Start(new ProcessStartInfo
                            {
                                WorkingDirectory = folderPath,
                                FileName         = Rapify,
                                Arguments        = $"-bin {s}",
                                UseShellExecute  = false,
                                CreateNoWindow   = true
                            }).WaitForExit();
                        }
                    }

                    string path = s.Replace(folderPath, "");

                    if (path.StartsWith(@"\"))
                    {
                        path = path.Substring(1);
                    }

                    //string file = File.ReadAllText(s);

                    //pbo.AddEntry(path, Encoding.UTF8.GetBytes(file));

                    byte[] file = File.ReadAllBytes(s);

                    pbo.AddEntry(path, file);
                }

                pbo.Save($"{modPath}.pbo");
            }
            else if (sm.PackingMethod == PackingMethod.SqfSafe)
            {
                Console.WriteLine($"Running SqfSafe for {sm.Name}\n");

                string obfuPath = Path.Combine(Program.Settings.SqfSafeDirectory, "SqfSafe-CLI.exe");

                ProcessStartInfo obfu = new ProcessStartInfo(obfuPath)
                {
                    Arguments       = $"--token {Program.Settings.SqfSafeToken} -f \"{folderPath}\" -p \"{sm.SqfSafeProfile}\" -o \"{modPath}.pbo\"",
                    UseShellExecute = false,
                    CreateNoWindow  = true
                };

                ObfuProcs.Add(Process.Start(obfu));
            }
            else
            {
                Console.WriteLine($"Packing Method not Supported.");
                Util.Assert(false);
            }
        }