Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: My Mod(ExR, ExS, EvE) #1

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Dropship/Data/mods.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@
"Versioning" : {
"v2.2.1" : "2021.7.20e"
}
},
"ExtremeRoles": {
"Name": "Extreme Roles",
"Author": "yukieiji",
"Releases": "https://api.github.com/repos/yukieiji/ExtremeRoles/releases",
"Versioning": {
"v12.1.4.2": "2024.11.26"
},
"DllName": "ExtremeRoles"
},
"ExtremeSkins": {
"Name": "Extreme Skins",
"Author": "yukieiji",
"Releases": "https://api.github.com/repos/yukieiji/ExtremeRoles/releases",
"Dependencies": {
"ExtremeRoles": "v12.1.4.2"
},
"Versioning": {
"v12.1.4.2": "2024.11.26"
},
"DllName": "ExtremeSkins"
},
"ExtremeVoiceEngine": {
"Name": "Extreme Voice Engine",
"Author": "yukieiji",
"Releases": "https://api.github.com/repos/yukieiji/ExtremeRoles/releases",
"Dependencies": {
"ExtremeRoles": "v12.1.4.2"
},
"Versioning": {
"v12.1.4.2": "2024.11.26"
},
"DllName": "ExtremeVoiceEngine"
}
}
}
29 changes: 19 additions & 10 deletions Dropship/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
Logger.Log("Downloading modlist...");
var request = await _HttpClient.GetAsync("https://github.com/xChipseq/Dropship-Mod-Manager/raw/main/Data/mods.json");
var json = await request.Content.ReadFromJsonAsync<ModList>();
ModList = json.List;

Check warning on line 42 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
else
{
Logger.Log("Getting modlist from resources...");
string json = LoadJson("Dropship.Data.mods.json");
ModList list = JsonSerializer.Deserialize<ModList>(json);

Check warning on line 48 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
ModList = list.List;

Check warning on line 49 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}
catch (Exception ex)
Expand All @@ -57,7 +57,7 @@
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Couldn't get mod data from github, getting it from local resources...");
Console.ForegroundColor = ConsoleColor.White;
DownloadModData(false);

Check warning on line 60 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@
return mods;
}

public static bool IsModDownloaded(string modName, string modVersion = null)

Check warning on line 121 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 121 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 121 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 121 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 121 in Dropship/DataManager.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
if (modVersion != null) // check for specific version
{
Expand Down Expand Up @@ -147,21 +147,25 @@

public static async Task<bool> DownloadMod(string modName, string version, bool dependency = false)
{
ModData mod = ModList[modName];
if (!ModList.TryGetValue(modName, out var mod))
{
return false;
}

string modFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mods", $"{modName}");
try
{
Release releaseToDownload = null;
if (version == "latest")
{
string url = ModList[modName].ReleasesUrl + "/latest"; // link to the latest release
string url = mod.Releases + "/latest"; // link to the latest release
var latestresponse = _HttpClient.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result;
releaseToDownload = await latestresponse.Content.ReadFromJsonAsync<Release>();
}
else
{
// search for the tag with specified version
var searchresponse = _HttpClient.GetAsync(ModList[modName].ReleasesUrl, HttpCompletionOption.ResponseHeadersRead).Result;
var searchresponse = _HttpClient.GetAsync(mod.Releases, HttpCompletionOption.ResponseHeadersRead).Result;
List<Release> releases = await searchresponse.Content.ReadFromJsonAsync<List<Release>>();

foreach (var release in releases)
Expand All @@ -183,7 +187,12 @@
ReleaseAsset assetToDownload = null;
foreach (var asset in releaseToDownload.Assets)
{
if (asset.FileName.EndsWith(".dll"))
var assetName = asset.FileName;
if (assetName.EndsWith(".dll") &&
(
string.IsNullOrEmpty(mod.DllName) ||
mod.DllName == assetName.Replace(".dll", "")
))
{
assetToDownload = asset;
break;
Expand Down Expand Up @@ -233,11 +242,11 @@
contentStream.Close();

// Check for dependencies
if (ModList[modName].Dependencies.Count > 0 && !dependency)
if (mod.Dependencies.Count > 0 && !dependency)
{
Console.WriteLine("\nChecking for dependencies...");

foreach (var d in ModList[modName].Dependencies)
foreach (var d in mod.Dependencies)
{
if (!IsModDownloaded(d.Value, d.Key))
{
Expand All @@ -251,18 +260,18 @@
if (!dependency)
{
Console.WriteLine($"\n{modName} successfully installed");
if (ModList[modName].Versioning.ContainsKey(releaseToDownload.Version))
if (mod.Versioning.ContainsKey(releaseToDownload.Version))
{
if (DepotDownloader.IsVersionInstalled(releaseToDownload.Version))
{
Console.WriteLine($"Among Us {ModList[modName].Versioning[releaseToDownload.Version]} is specified for {modName} {releaseToDownload.Version}\nDownload it? [y/n]");
Console.WriteLine($"Among Us {mod.Versioning[releaseToDownload.Version]} is specified for {modName} {releaseToDownload.Version}\nDownload it? [y/n]");
string input = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(input))
{
if (input.ToLower() == "y")
{
string buildid = ManifestVersionsList[ModList[modName].Versioning[releaseToDownload.Version]];
DepotDownloader.DownloadBuild(buildid, ModList[modName].Versioning[releaseToDownload.Version]);
string buildid = ManifestVersionsList[mod.Versioning[releaseToDownload.Version]];
DepotDownloader.DownloadBuild(buildid, mod.Versioning[releaseToDownload.Version]);
}
}
}
Expand Down
24 changes: 9 additions & 15 deletions Dropship/Objects/ModData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

namespace Dropship.Objects;

public class ModData
public record class ModData(
string Name,
string Author,
string Releases, // This is the github api link that are we getting releases from
Dictionary<string, string> Dependencies, // All the mod's dependecies and their versions. Empty if none
Dictionary<string, string> Versioning, // This list contains some predefined game versions for tags
string? DllName = null)
{
[JsonPropertyName("Name")]
public string Name { get; set; }

[JsonPropertyName("Author")]
public string Author { get; set; }

[JsonPropertyName("Releases")]
public string ReleasesUrl { get; set; } // This is the github api link that are we getting releases from

[JsonPropertyName("Dependencies")]
public Dictionary<string, string> Dependencies { get; set; } // All the mod's dependecies and their versions. Empty if none

[JsonPropertyName("Versioning")]
public Dictionary<string, string> Versioning { get; set; } // This list contains some predefined game versions for tags
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? DllName { get; set; } = DllName;
}

public class ModList
Expand Down
Loading