Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
/ ModManager Public archive

Commit

Permalink
Version 5.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MatuxGG committed Aug 17, 2022
1 parent 02172e9 commit ccfe00c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 36 deletions.
5 changes: 5 additions & 0 deletions ModManager5/Classes/InstalledMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ public InstalledMod()
this.gameVersion = "";
this.options = new List<string>() { };
}

public bool hasOption(string optionName)
{
return options.Contains(optionName);
}
}
}
84 changes: 53 additions & 31 deletions ModManager5/Classes/ModManagerUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static class ModManagerUI
public static Form SettingsForm;
public static Form CreditsForm;
public static Form EmptyForm;
public static Form OptionsForm;

public static TextBox LoginPseudoText;
public static TextBox LoginPasswordText;
Expand Down Expand Up @@ -497,7 +498,7 @@ public static void refreshModForm(Form f)

if (cat.id == "local")
{
TableLayoutPanel InfoPanel = Visuals.InfoLabel(Translator.get("In your ZIP file, you need to include:\n") +
TableLayoutPanel InfoPanel = Visuals.InfoLabel(Translator.get("In your ZIP file, you need to include") + "\n" +
Translator.get("ⓘ BepInEx folder, mono folder, doorstop_config.ini & winhttp.dll ⓘ")
);
f.Controls.Add(InfoPanel);
Expand All @@ -514,7 +515,7 @@ public static void refreshModForm(Form f)

if (ConfigManager.config.launcher != "Steam" && f.Name != "local")
{
TableLayoutPanel AlertPanel = Visuals.AlertLabel(Translator.get("⚠ You are not using Among Us from Steam. As a consequence, some mods may not be available. ⚠\n") +
TableLayoutPanel AlertPanel = Visuals.AlertLabel(Translator.get("⚠ You are not using Among Us from Steam. As a consequence, some mods may not be available. ⚠") + "\n" +
Translator.get("If you're using Among Us from Steam, please change launcher in Settings.")
);
f.Controls.Add(AlertPanel);
Expand Down Expand Up @@ -553,7 +554,6 @@ public static void refreshModForm(Form f)
ModPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
ModPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
ModPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
ModPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
}

int size = mods.Count();
Expand Down Expand Up @@ -657,12 +657,14 @@ public static void refreshModForm(Form f)
ModFavorite.Image = global::ModManager5.Properties.Resources.favoriteFilled;
ModFavorite.Click += new EventHandler((object sender, EventArgs e) => {
ConfigManager.removeFavoriteMod(m.id);
ConfigManager.update();
reloadMods();
});
} else
{
ModFavorite.Click += new EventHandler((object sender, EventArgs e) => {
ConfigManager.addFavoriteMod(m.id);
ConfigManager.update();
reloadMods();
});
}
Expand All @@ -687,21 +689,20 @@ public static void refreshModForm(Form f)
});
ModPanel.Controls.Add(ModDiscord, 6, line);
}

PictureBox ModEdit = Visuals.ModPic("ModEdit", global::ModManager5.Properties.Resources.edit);
allocatedControls.Add(ModEdit);
ModPanel.Controls.Add(ModEdit, 5, line);
if (m.options.Count() == 0 || im == null)
{
ModEdit.Image = null;
ModEdit.Cursor = System.Windows.Forms.Cursors.Default;
} else
}
else
{
ModEdit.Click += new EventHandler((object sender, EventArgs e) => {
openOptionsForm(m);
});
}

Label ModVersion = Visuals.ModLabel("ModVersion", m.githubLink == "1" ? m.release.TagName : "");
allocatedControls.Add(ModVersion);
ModPanel.Controls.Add(ModVersion, 2, line);
Expand Down Expand Up @@ -986,7 +987,6 @@ public static void refreshModForm(Form f)
line++;
}


if (cat.id == "local")
{
f.Controls.Add(Visuals.LocalModsOverlay());
Expand All @@ -997,33 +997,29 @@ public static void refreshModForm(Form f)

f.Controls.Add(Visuals.LabelTitle(Translator.get(cat.name)));
}

public static void openOptionsForm(Mod m)
{
var formPopup = new Form();
formPopup.MinimumSize = new System.Drawing.Size(600, 100 * m.options.Count());
int width = (int)((60 * Screen.PrimaryScreen.Bounds.Width) / 100);
if (width < formPopup.MinimumSize.Width)
width = formPopup.MinimumSize.Width;
int height = (int)((60 * Screen.PrimaryScreen.Bounds.Height) / 100);
if (height < formPopup.MinimumSize.Height)
height = formPopup.MinimumSize.Height;
formPopup.Size = new Size(width, height);
formPopup.StartPosition = FormStartPosition.CenterScreen;
formPopup.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
formPopup.BackColor = ThemeList.theme.AppBackgroundColor;
formPopup.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
formPopup.ForeColor = ThemeList.theme.TextColor;
formPopup.Icon = global::ModManager5.Properties.Resources.modmanager;
formPopup.Name = "OptionsPopup";
formPopup.Text = m.name + " options";
InstalledMod im = ConfigManager.getInstalledModById(m.id);

OptionsForm = new Form();
OptionsForm.FormBorderStyle = FormBorderStyle.FixedSingle;
OptionsForm.MaximizeBox = false;
OptionsForm.Size = new Size(800, 40 + 50 * m.options.Count());
OptionsForm.StartPosition = FormStartPosition.CenterScreen;
OptionsForm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
OptionsForm.BackColor = ThemeList.theme.AppBackgroundColor;
OptionsForm.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
OptionsForm.ForeColor = ThemeList.theme.TextColor;
OptionsForm.Icon = global::ModManager5.Properties.Resources.modmanager;
OptionsForm.Name = "OptionsForm";
OptionsForm.Text = m.name + " options";

Panel ContainerOptionsPanel = new Panel();
ContainerOptionsPanel.Name = "ContainerOptionsPanel";
ContainerOptionsPanel.BackColor = Color.Transparent;
ContainerOptionsPanel.Dock = DockStyle.Fill;
ContainerOptionsPanel.AutoScroll = true;
formPopup.Controls.Add(ContainerOptionsPanel);
ContainerOptionsPanel.AutoScroll = false;
OptionsForm.Controls.Add(ContainerOptionsPanel);

TableLayoutPanel ModOptionsPanel = new TableLayoutPanel();
ModOptionsPanel.Name = "ModOptionsPanel";
Expand All @@ -1034,14 +1030,39 @@ public static void openOptionsForm(Mod m)
foreach (string optionName in m.options)
{
Mod option = ModList.getModById(optionName);
formPopup.Controls.Add(Visuals.ModLabel(optionName, optionName));
}
MMButton OptionButton = new MMButton("trans");
OptionsForm.Controls.Add(Visuals.OptionsLine(OptionButton, optionName));

OptionButton.Click += new EventHandler((object sender, EventArgs e) =>
{
MMButton c = (MMButton)sender;
if (c.Text == Translator.get("Enabled"))
{
im.options.Remove(optionName);
ConfigManager.update();
c.Text = Translator.get("Disabled");
} else if (c.Text == Translator.get("Disabled"))
{
im.options.Add(optionName);
ConfigManager.update();
c.Text = Translator.get("Enabled");
}
});

if (im.hasOption(optionName))
{
OptionButton.Text = Translator.get("Enabled");
} else if (ConfigManager.getInstalledModById(optionName) != null)
{
OptionButton.Text = Translator.get("Disabled");
} else
{
OptionButton.Text = Translator.get("Not installed");
}
}

formPopup.ShowDialog();
OptionsForm.ShowDialog();
}

public static void loadServers()
{
Utils.log("Load servers START", "ModManagerUI");
Expand Down Expand Up @@ -1321,6 +1342,7 @@ public static void loadSettings()
{
ModWorker.removeAllMods();
ConfigManager.config.launcher = launcher;
ConfigManager.update();
Form f = activeForm;
ModManagerUI.reloadMods();
openForm(f);
Expand Down
30 changes: 25 additions & 5 deletions ModManager5/Classes/ModWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ public static void startMod(Mod m)
return;
}

InstalledMod im = ConfigManager.getInstalledModById(m.id);

string dirPath;
string optionsPath = dirPath = ModManager.appDataPath + @"\mods\" + m.id + "-options";
if (m.type == "local")
{
dirPath = ModManager.appDataPath + @"\localMods\" + m.name;
Expand All @@ -156,10 +159,25 @@ public static void startMod(Mod m)
{
cleanGame();
Utils.DirectoryCopy(dirPath, ConfigManager.config.amongUsPath, true);
foreach(string optionName in m.options)
{
Utils.DirectoryCopy(ModManager.appDataPath + @"\mods\" + optionName, ConfigManager.config.amongUsPath, true);
}
Process.Start("explorer", ConfigManager.config.amongUsPath + @"\Among Us.exe");
} else
{
Process.Start("explorer", dirPath + @"\Among Us.exe");
if (im.options.Count() > 0)
{
Utils.DirectoryCopy(dirPath, optionsPath, true);
foreach (string optionName in m.options)
{
Utils.DirectoryCopyWithoutReplacement(ModManager.appDataPath + @"\mods\" + optionName, optionsPath);
}
Process.Start("explorer", optionsPath + @"\Among Us.exe");
} else
{
Process.Start("explorer", dirPath + @"\Among Us.exe");
}
}


Expand Down Expand Up @@ -517,7 +535,9 @@ public static void UninstallMod(Mod m)
return;
} else
{
Utils.DirectoryDelete(ModManager.appDataPath + @"\mods\" + m.id);
string modPath = ModManager.appDataPath + @"\mods\" + m.id;
Utils.DirectoryDelete(modPath);
Utils.DirectoryDelete(modPath + "-options");
}

ConfigManager.config.installedMods.Remove(im);
Expand Down Expand Up @@ -704,7 +724,7 @@ private static void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)

dataLoad(m);

InstalledMod newMod = new InstalledMod(m.id, m.release.TagName, m.gameVersion, existingMod.options);
InstalledMod newMod = new InstalledMod(m.id, m.release.TagName, m.gameVersion, existingMod == null ? new List<string>() { } : existingMod.options);
ConfigManager.config.installedMods.Add(newMod);
ConfigManager.update();

Expand Down Expand Up @@ -767,8 +787,6 @@ public static Boolean installFiles(Mod m, string destPath)
return true;
}



public static Boolean installDll(Mod m, ReleaseAsset file, string destPath)
{
string fileName = file.Name;
Expand Down Expand Up @@ -828,6 +846,8 @@ public static string getBepInExInsideRec(string path)
return dir.FullName;
}
}

ModManagerUI.reloadMods();
return null;
}

Expand Down
33 changes: 33 additions & 0 deletions ModManager5/Classes/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,39 @@ public static void DirectoryCopy(string sourceDirName, string destDirName, bool
}
}

public static void DirectoryCopyWithoutReplacement(string sourceDirName, string destDirName)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
return;
}

DirectoryInfo[] dirs = dir.GetDirectories();

// If the destination directory doesn't exist, create it.
Directory.CreateDirectory(destDirName);

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
if (!new FileInfo(tempPath).Exists)
{
file.CopyTo(tempPath, false);
}
}

foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopyWithoutReplacement(subdir.FullName, tempPath);
}
}

public static void DirectoryDelete(string dirName)
{
if (Directory.Exists(dirName))
Expand Down
18 changes: 18 additions & 0 deletions ModManager5/Classes/Visuals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ public static Label LabelContent(string title, ContentAlignment align, DockStyle
return ContentLabel;
}

public static TableLayoutPanel OptionsLine(Button OptionButton, string title)
{
TableLayoutPanel t = Visuals.createLayoutPanelH(0, 50, DockStyle.Top, new int[] { 30, 70 });

t.Margin = new System.Windows.Forms.Padding(20, 20, 20, 20);
t.BackColor = ThemeList.theme.AppOverlayColor;

Label label = Visuals.LabelContent(title, ContentAlignment.MiddleLeft, DockStyle.Fill);
label.Text = title;
t.Controls.Add(label, 1, 0);

OptionButton.AutoSize = true;
OptionButton.Dock = DockStyle.Fill;
t.Controls.Add(OptionButton, 0, 0);

return t;
}

public static TableLayoutPanel centeredTextbox(string title, TextBox textbox)
{
TableLayoutPanel LayoutPanel = Visuals.createLayoutPanelH(0, 100, DockStyle.Fill, new int[] { 20, 60, 20 });
Expand Down

0 comments on commit ccfe00c

Please sign in to comment.