//commands
        public void CampaignInfoCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args == 0)
            {
                string[] dirs    = Directory.GetDirectories(MainPath + "Campaigns");
                string   Message = "Campaigns: ";
                bool     first   = true;
                foreach (string str in dirs)
                {
                    DirectoryInfo dirInf = new DirectoryInfo(str);
                    Message += (first ? "" : ", ") + dirInf.Name;
                    first    = false;
                }
                uConsole.Log(Message);
            }
            else if (Args == 1)
            {
                string Name  = uConsole.GetString();
                string cPath = MainPath + "Campaigns/" + Name;
                if (!Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " does not exist!");
                    return;
                }
                else if (!File.Exists(cPath + "/CampaignData.json"))
                {
                    uConsole.Log(Name + " is missing CampaignData.json!");
                    return;
                }

                CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));

                string LevelNames = "";
                bool   First      = true;
                foreach (string str in cData.m_ItemIds)
                {
                    LevelNames += (First ? "" : ", ") + str.Replace("CampaignMod", "");
                    First       = false;
                }

                uConsole.Log(
                    "<b>Title:</b> " + cData.m_Title +
                    "\n<b>Description:</b> " + cData.m_Description +
                    "\n<b>WinMessage:</b> " + cData.m_WinMessage +
                    "\n<b>Levels:</b> " + LevelNames
                    );
            }
            else
            {
                uConsole.Log("Usage: campaign_info [name]");
            }
        }
        public void RemoveLevelCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args < 2)
            {
                uConsole.Log("Usage: remove_level <campaign> <level>");
            }
            else
            {
                string Name  = uConsole.GetString();
                string Level = "";
                bool   First = true;
                for (int i = 0; i < Args - 1; i++)
                {
                    Level += (First ? "" : " ") + uConsole.GetString();
                    First  = false;
                }

                string cPath = MainPath + "Campaigns/" + Name;
                if (!Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " does not exist!");
                    return;
                }
                else if (!File.Exists(cPath + "/CampaignData.json"))
                {
                    uConsole.Log(Name + " is missing CampaignData.json!");
                    return;
                }

                CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));

                if (!cData.m_ItemIds.Contains(Level + "CampaignMod"))
                {
                    uConsole.Log(Level + " is not in " + Name);
                    return;
                }

                if (File.Exists(cPath + "/" + Level + ".level"))
                {
                    File.Delete(cPath + "/" + Level + ".level");
                }

                cData.m_ItemIds.Remove(Level + "CampaignMod");

                string json = JsonUtility.ToJson(cData);
                File.WriteAllText(cPath + "/CampaignData.json", json);

                uConsole.Log("Level removed from campaign");
            }
        }
        public void ImportCampaignCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args != 1)
            {
                uConsole.Log("Usage: import_campaign <campaign>");
            }
            else
            {
                string Name  = uConsole.GetString();
                string cPath = MainPath + "Campaigns/" + Name;

                if (!File.Exists(MainPath + "Exports/" + Name + ".campaign"))
                {
                    uConsole.Log("That campaign doesn't exist!");
                    return;
                }

                byte[] cBytes = Utils.UnZipPayload(File.ReadAllBytes(MainPath + "Exports/" + Name + ".campaign"));
                int    offset = 0;

                string             cDataJson = ByteSerializer.DeserializeString(cBytes, ref offset);
                CampaignLayoutData cData     = JsonUtility.FromJson <CampaignLayoutData>(cDataJson);
                List <KeyValuePair <string, byte[]> > LevelBytes = new List <KeyValuePair <string, byte[]> >();

                for (int i = 0; i < cData.m_ItemIds.Count; i++)
                {
                    string lName = ByteSerializer.DeserializeString(cBytes, ref offset);
                    byte[] lData = ByteSerializer.DeserializeByteArray(cBytes, ref offset);
                    LevelBytes.Add(new KeyValuePair <string, byte[]>(lName, lData));
                }

                if (Directory.Exists(cPath))
                {
                    PopUpMessage.Display("Campaign already exists!\nOverwite it?", delegate {
                        Directory.Delete(cPath, true);
                        ImportCampaign(cPath, cDataJson, LevelBytes);
                    });
                }
                else
                {
                    ImportCampaign(cPath, cDataJson, LevelBytes);
                }
            }
        }
        public ResponseData.Campaign GenerateCampaign(string cPath, CampaignLayoutData cData)
        {
            string cName = cData.m_Title;

            if (cData.m_ItemIds.Count == 0)
            {
                uConsole.Log(cName + " doesn't have any levels!");
                return(null);
            }

            List <LevelData> levelDatas = new List <LevelData>();

            foreach (string id in cData.m_ItemIds)
            {
                if (!File.Exists(cPath + "/" + id.Replace("CampaignMod", "") + ".level"))
                {
                    uConsole.Log(cName + " tried to load " + id.Replace("CampaignMod", "") + " but it doesn't exist!");
                    return(null);
                }
                byte[] bytes  = File.ReadAllBytes(cPath + "/" + id.Replace("CampaignMod", "") + ".level");
                int    offset = 0;
                levelDatas.Add(LevelData.Deserialize(bytes, ref offset));
            }

            List <ResponseData.Item> items = new List <ResponseData.Item>();

            foreach (LevelData levelData in levelDatas)
            {
                ResponseData.Item item = levelData.GenerateItem();
                PersistentWorkshopItems.Create(item, levelData.PreviewData, Utils.ZipPayload(levelData.LayoutBytes));

                items.Add(item);
            }

            ResponseData.Campaign campaign = new ResponseData.Campaign();

            campaign.ownedBy = items[0].ownedBy;
            campaign.items   = items.ToArray();

            campaign.id          = cName + "CampaignMod";
            campaign.title       = cName;
            campaign.description = cData.m_Description;
            campaign.winMessage  = cData.m_WinMessage;

            PersistentWorkshopCampaigns.Delete(campaign.id);
            PersistentWorkshopCampaigns.Create(campaign);
            return(campaign);
        }
        public void CreateCampaignCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args != 1)
            {
                uConsole.Log("Usage: create_campaign <name>");
            }
            else
            {
                string Name = uConsole.GetString();
                if (Name.Contains("/") || Name.Contains("\\") || Name.Contains("?") || Name.Contains("%") || Name.Contains("*") ||
                    Name.Contains(":") || Name.Contains("|") || Name.Contains("\"") || Name.Contains("<") || Name.Contains(">") ||
                    Name.Contains(".") || Name.Contains(",") || Name.Contains(";") || Name.Contains("=") || Name.Contains(" "))
                {
                    uConsole.Log(Name + " contains prhobited characters!");
                    return;
                }

                string cPath = MainPath + "Campaigns/" + Name;
                if (Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " already exists!");
                    return;
                }
                else
                {
                    try
                    {
                        Directory.CreateDirectory(cPath);
                        CampaignLayoutData CampData = new CampaignLayoutData(1, "CampaignData", Name + "CampaignMod", Name, "", "", new List <string>());
                        string             json     = JsonUtility.ToJson(CampData);
                        File.WriteAllText(cPath + "/CampaignData.json", json);
                        uConsole.Log("Campaign created!");
                    }
                    catch (Exception e)
                    {
                        uConsole.Log("Something went wrong while creating campaign:\n" + e);
                        return;
                    }
                }
            }
        }
        public void AddThisLevel(string cPath, SandboxLayoutData data, CampaignLayoutData cData, int num)
        {
            data.m_Workshop.m_Id = data.m_Workshop.m_Title + "CampaignMod";
            byte[] layoutData = data.SerializeBinary();

            List <byte> bytes = new List <byte>();

            WorkshopPreview.Create();
            bytes.AddRange(ByteSerializer.SerializeByteArray(layoutData));
            bytes.AddRange(ByteSerializer.SerializeByteArray(WorkshopPreview.m_PreviewBytes));
            bytes.AddRange(ByteSerializer.SerializeString(mName.Value));

            File.WriteAllBytes(cPath + "/" + data.m_Workshop.m_Title + ".level", bytes.ToArray());

            if (cData.m_ItemIds.Contains(data.m_Workshop.m_Id))
            {
                cData.m_ItemIds.Remove(data.m_Workshop.m_Id);
            }
            if (num == -1)
            {
                cData.m_ItemIds.Add(data.m_Workshop.m_Id);
            }
            else
            {
                if (cData.m_ItemIds.Count < num)
                {
                    cData.m_ItemIds.Add(data.m_Workshop.m_Id);
                }
                else
                {
                    cData.m_ItemIds.Insert(num - 1, data.m_Workshop.m_Id);
                }
            }

            try
            {
                string json = JsonUtility.ToJson(cData);
                File.WriteAllText(cPath + "/CampaignData.json", json);
            }
            catch (Exception e)
            {
                uConsole.Log("Something went wrong:\n" + e);
                return;
            }
            uConsole.Log("Level added to campaign at position " + (cData.m_ItemIds.IndexOf(data.m_Workshop.m_Id) + 1));
        }
        public void LoadCampaign(string cPath, string Name)
        {
            if (!Directory.Exists(cPath))
            {
                uConsole.Log(Name + " does not exist!");
                return;
            }
            else if (!File.Exists(cPath + "/CampaignData.json"))
            {
                uConsole.Log(Name + " is missing CampaignData.json!");
                return;
            }

            CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));

            ResponseData.Campaign campaign = GenerateCampaign(cPath, cData);
            if (campaign == null)
            {
                return;
            }
            Keys.Add(campaign.id);

            uConsole.Log(Name + " loaded!");
        }
        public void ExportCampaignCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args != 1)
            {
                uConsole.Log("Usage: export_campaign <campaign>");
            }
            else
            {
                string Name  = uConsole.GetString();
                string cPath = MainPath + "Campaigns/" + Name;
                if (!Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " does not exist!");
                    return;
                }
                else if (!File.Exists(cPath + "/CampaignData.json"))
                {
                    uConsole.Log(Name + " is missing CampaignData.json!");
                    return;
                }

                List <byte> cBytes = new List <byte>();

                CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));

                cBytes.AddRange(ByteSerializer.SerializeString(File.ReadAllText(cPath + "/CampaignData.json")));

                List <LevelData> levelDatas = new List <LevelData>();
                foreach (string id in cData.m_ItemIds)
                {
                    if (!File.Exists(cPath + "/" + id.Replace("CampaignMod", "") + ".level"))
                    {
                        uConsole.Log(Name + " tried to export " + id.Replace("CampaignMod", "") + " but it doesn't exist!");
                        return;
                    }

                    cBytes.AddRange(ByteSerializer.SerializeString(id.Replace("CampaignMod", "")));
                    cBytes.AddRange(ByteSerializer.SerializeByteArray(File.ReadAllBytes(cPath + "/" + id.Replace("CampaignMod", "") + ".level")));
                }

                if (File.Exists(MainPath + "Exports/" + Name + ".campaign"))
                {
                    PopUpMessage.Display("an export of " + Name + "already exists\noverwrite it?", delegate {
                        File.WriteAllBytes(MainPath + "Exports/" + Name + ".campaign", Utils.ZipPayload(cBytes.ToArray()));
                        uConsole.Log("Export created at '" + MainPath + "Exports/" + Name + ".campaign'");
                    });
                }
                else
                {
                    File.WriteAllBytes(MainPath + "Exports/" + Name + ".campaign", Utils.ZipPayload(cBytes.ToArray()));
                    uConsole.Log("Export created at '" + MainPath + "Exports/" + Name + ".campaign'");
                }
            }
        }
        public void AddThisLevelCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            if (GameStateManager.GetState() != GameState.SANDBOX)
            {
                uConsole.Log("You have to be in sandbox mode to use this command!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args == 0)
            {
                uConsole.Log("Usage: add_this_level <campaign> [num]");
            }
            else
            {
                string Name  = uConsole.GetString();
                string cPath = MainPath + "Campaigns/" + Name;

                if (!Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " does not exist!");
                    return;
                }
                else if (!File.Exists(cPath + "/CampaignData.json"))
                {
                    uConsole.Log(Name + " is missing CampaignData.json!");
                    return;
                }
                else if (mName.Value.IsNullOrWhiteSpace())
                {
                    uConsole.Log("Your name can't be empty!");
                    return;
                }

                GameUI.m_Instance.m_WorkshopSubmit.gameObject.SetActive(true);
                GameUI.m_Instance.m_WorkshopSubmit.gameObject.SetActive(false);

                SandboxLayoutData data  = SandboxLayout.SerializeToProxies();
                string            Title = data.m_Workshop.m_Title;
                if (Title.IsNullOrWhiteSpace())
                {
                    uConsole.Log("Level doesn't have a name!");
                    return;
                }
                else
                if (Title.Contains("/") || Title.Contains("\\") || Title.Contains("?") || Title.Contains("%") || Title.Contains("*") ||
                    Title.Contains(":") || Title.Contains("|") || Title.Contains("\"") || Title.Contains("<") || Title.Contains(">") ||
                    Title.Contains(".") || Title.Contains(",") || Title.Contains(";") || Title.Contains("="))
                {
                    uConsole.Log("Level title contains prhobited characters!");
                    return;
                }

                CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));
                if (cData.m_ItemIds.Count >= 16)
                {
                    uConsole.Log("Campaign already has max levels");
                    return;
                }

                int num = -1;
                if (Args > 1)
                {
                    num = uConsole.GetInt();
                    if (num < 1 || num > 16)
                    {
                        uConsole.Log("Position has to be within 1 and 16!");
                        return;
                    }
                }

                if (File.Exists(cPath + "/" + Title + ".level"))
                {
                    PopUpMessage.Display("Level already exists!\nOverwrite level?", delegate { AddThisLevel(cPath, data, cData, num); });
                }
                else
                {
                    AddThisLevel(cPath, data, cData, num);
                }
            }
        }
        public void EditCampaignInfoCommand()
        {
            if (!instance.CheckForCheating())
            {
                uConsole.Log("Campaign Mod is not enabled!");
                return;
            }
            int Args = uConsole.GetNumParameters();

            if (Args < 3)
            {
                uConsole.Log("Usage: edit_campaign_info <name> <title|description|winmessage> <value>");
            }
            else
            {
                string Name    = uConsole.GetString();
                string Setting = uConsole.GetString();
                string Value   = "";
                bool   First   = true;
                for (int i = 0; i < Args - 2; i++)
                {
                    Value += (First ? "" : " ") + uConsole.GetString();
                    First  = false;
                }
                string cPath = MainPath + "Campaigns/" + Name;
                if (!Directory.Exists(cPath))
                {
                    uConsole.Log(Name + " does not exist!");
                    return;
                }
                else if (!File.Exists(cPath + "/CampaignData.json"))
                {
                    uConsole.Log(Name + " is missing CampaignData.json!");
                    return;
                }
                if (Value.Contains("/") || Value.Contains("\\") || Value.Contains("?") || Value.Contains("%") || Value.Contains("*") ||
                    Value.Contains(":") || Value.Contains("|") || Value.Contains("\"") || Value.Contains("<") || Value.Contains(">") ||
                    Value.Contains(".") || Value.Contains(",") || Value.Contains(";") || Value.Contains("="))
                {
                    uConsole.Log("Value contains prhobited characters!");
                    return;
                }

                CampaignLayoutData cData = JsonUtility.FromJson <CampaignLayoutData>(File.ReadAllText(cPath + "/CampaignData.json"));

                if (Setting == "title")
                {
                    if (Value.Contains(" "))
                    {
                        uConsole.Log("The campaign title cant contain a space!");
                        return;
                    }
                    else if (Directory.Exists(MainPath + "Campaigns/" + Value))
                    {
                        uConsole.Log("That campaign already exists!");
                        return;
                    }
                    Directory.Move(cPath, MainPath + "Campaigns/" + Value);
                    cPath         = MainPath + "Campaigns/" + Value;
                    cData.m_Title = Value;
                    string json = JsonUtility.ToJson(cData);
                    File.WriteAllText(cPath + "/CampaignData.json", json);
                }
                else if (Setting == "description")
                {
                    cData.m_Description = Value;
                    string json = JsonUtility.ToJson(cData);
                    File.WriteAllText(cPath + "/CampaignData.json", json);
                }
                else if (Setting == "winmessage")
                {
                    cData.m_WinMessage = Value;
                    string json = JsonUtility.ToJson(cData);
                    File.WriteAllText(cPath + "/CampaignData.json", json);
                }
                else
                {
                    uConsole.Log("Usage: edit_campaign_info <name> <title|description|winmessage> <value>");
                    return;
                }
                uConsole.Log("Campaign info updated!");
            }
        }