Skip to content

Commit c012b87

Browse files
committed
feat: implemented non premium nexus download (overwrite premium download method for this)
1 parent 60add21 commit c012b87

7 files changed

Lines changed: 149 additions & 19 deletions

File tree

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
# Fork Information
2+
3+
In this Release I have implemented the functionality that nexus update also works with non premium account.
4+
5+
Just update session.txt (next to Stardrop.exe) with your session Cookie which usually looks like this (Omitted some of it):
6+
7+
fwroute=1746959198.828.20660.220449|b...dofWOlI; ab=0|1746962235
8+
9+
You can get the session token when opening the network path of your browser and go to any mod and click "Slow Download":
10+
11+
![alt text](image-1.png)
12+
13+
In Network path under Downloads?GenerateDownloadUrl copy whole Cookie text:
14+
15+
![alt text](image.png)
16+
17+
I have overwritten the logic for premium download so don't use this if you have nexus premium.
18+
119
# Stardrop
2-
20+
321
Stardrop is an open-source, cross-platform mod manager for the game [Stardew Valley](https://www.stardewvalley.net/). It is built using the Avalonia UI framework.
422

523
Stadrop utilizes [SMAPI (Stardew Modding API)](https://smapi.io/) to simplify the management and update checking for all applicable Stardew Valley mods.
@@ -15,20 +33,22 @@ See the [GitBook pages](https://floogen.gitbook.io/stardrop/) for detailed docum
1533
See the [release page](https://github.com/Floogen/Stardrop/releases/latest) for the latest builds.
1634

1735
# Credits
36+
1837
## Translations
38+
1939
Stardrop has been generously translated into several languages by the following users:
2040

21-
* **Chinese** - guanyintu, PIut02, Z2549, CuteCat233
22-
* **French** - xynerorias
23-
* **German** - Schn1ek3
24-
* **Hungarian** - martin66789
25-
* **Italian** - S-zombie
26-
* **Portuguese** - aracnus
27-
* **Russian** - Rongarah
28-
* **Spanish** - Evexyron, Gaelhaine
29-
* **Thai** - ellipszist
30-
* **Turkish** - KediDili
31-
* **Ukrainian** - burunduk, ChulkyBow
41+
- **Chinese** - guanyintu, PIut02, Z2549, CuteCat233
42+
- **French** - xynerorias
43+
- **German** - Schn1ek3
44+
- **Hungarian** - martin66789
45+
- **Italian** - S-zombie
46+
- **Portuguese** - aracnus
47+
- **Russian** - Rongarah
48+
- **Spanish** - Evexyron, Gaelhaine
49+
- **Thai** - ellipszist
50+
- **Turkish** - KediDili
51+
- **Ukrainian** - burunduk, ChulkyBow
3252

3353
# Gallery
3454

Stardrop/Stardrop.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<PackageReference Include="CommandLineParser" Version="2.9.1" />
4141
<PackageReference Include="Json.More.Net" Version="2.0.1" />
4242
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
43+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4344
<PackageReference Include="Projektanker.Icons.Avalonia" Version="5.13.0" />
4445
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="5.13.0" />
4546
<PackageReference Include="semver" Version="2.3.0" />
@@ -152,13 +153,21 @@
152153
<ZipName Include="Stardrop-win-x64.zip" />
153154
</ItemGroup>
154155

156+
157+
<ItemGroup>
158+
<None Update="session.txt">
159+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
160+
</None>
161+
</ItemGroup>
162+
155163
<Target Name="FolderProfile - Windows" AfterTargets="Publish" Condition="$(Configuration)=='Release' And $(RuntimeIdentifier)=='win-x64'">
156164
<Exec Command="del @(ZipName) 2&gt;nul" WorkingDirectory="$(PublishDir)" />
157165

158166
<Exec Command="@(WSL) mkdir @(TempFolderPath)" WorkingDirectory="$(PublishDir)" />
159167

160168
<Exec Command="@(WSL) mv Themes @(TempFolderPath)" WorkingDirectory="$(PublishDir)" />
161169
<Exec Command="@(WSL) mv i18n @(TempFolderPath)" WorkingDirectory="$(PublishDir)" />
170+
<Exec Command="@(WSL) mv session.txt @(TempFolderPath)" WorkingDirectory="$(PublishDir)" />
162171
<Exec Command="@(WSL) mv Stardrop.exe Stardrop.pdb @(TempFolderPath)" WorkingDirectory="$(PublishDir)" />
163172

164173
<Exec Command="ren @(TempFolderPath) Stardrop" WorkingDirectory="$(PublishDir)" />

Stardrop/Utilities/NexusHelper.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.IO;
3+
using System.Net.Http;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Newtonsoft.Json;
8+
9+
namespace Stardrop.Utilities
10+
{
11+
public static class NexusHelper
12+
{
13+
// Get Session_cookie and place here. (Click on Slow Download and check network tab in browser)
14+
private static string session_cookie = "";
15+
private static string stardew_game_id = "1303";
16+
private static string nexus_download_url = "https://www.nexusmods.com/Core/Libs/Common/Managers/Downloads?GenerateDownloadUrl";
17+
18+
19+
20+
public static string MakeDownloadLink(string refererUrl, string fileId)
21+
{
22+
session_cookie = File.ReadAllText("session.txt");
23+
string downloadUrl = null;
24+
HttpClientHandler handler = new HttpClientHandler()
25+
{
26+
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
27+
};
28+
29+
var request = (HttpWebRequest)WebRequest.Create(nexus_download_url);
30+
request.Accept = "*/*";
31+
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
32+
33+
request.Headers.Add("Accept-Encoding", "gzip, deflate, br, zstd");
34+
request.Headers.Add("Accept-Language", "en,de;q=0.9,de-DE;q=0.8,en-US;q=0.7");
35+
request.Headers.Add("Cache-Control", "no-cache");
36+
request.Headers.Add("Origin", "https://www.nexusmods.com");
37+
request.Referer = refererUrl;
38+
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
39+
request.Headers.Add("Cookie", session_cookie);
40+
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
41+
42+
var postData = "fid=" + fileId;
43+
postData += "&game_id=" + stardew_game_id;
44+
var data = Encoding.ASCII.GetBytes(postData);
45+
46+
request.Method = "POST";
47+
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
48+
request.ContentLength = data.Length;
49+
50+
using (var stream = request.GetRequestStream())
51+
{
52+
stream.Write(data, 0, data.Length);
53+
}
54+
try
55+
{
56+
var response = (HttpWebResponse)request.GetResponse();
57+
58+
if (response.StatusCode == HttpStatusCode.OK)
59+
{
60+
string responseBody = new StreamReader(response.GetResponseStream()).ReadToEnd();
61+
62+
try
63+
{
64+
var responseData = JsonConvert.DeserializeObject<dynamic>(responseBody);
65+
66+
downloadUrl = responseData?.url;
67+
68+
if (string.IsNullOrEmpty(downloadUrl))
69+
{
70+
throw new Exception("No download URL found in the response.");
71+
}
72+
}
73+
catch (Newtonsoft.Json.JsonException)
74+
{
75+
throw new Exception($"Failed to parse the response as JSON from {refererUrl}");
76+
}
77+
}
78+
else
79+
{
80+
throw new Exception($"Request failed for {refererUrl} with status code {response.StatusCode}");
81+
}
82+
}
83+
catch (Exception ex)
84+
{
85+
throw new Exception($"Error during POST request: {ex.Message}");
86+
}
87+
88+
return downloadUrl;
89+
}
90+
91+
}
92+
}

Stardrop/Views/MainWindow.axaml.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,12 +1514,18 @@ private async Task HandleBulkModInstall()
15141514
return;
15151515
}
15161516

1517-
if (Program.settings.NexusDetails is null || Program.settings.NexusDetails.IsPremium is false)
1518-
{
1519-
await CreateWarningWindow(Program.translation.Get("ui.warning.download_without_premium"), Program.translation.Get("internal.ok"));
1520-
return;
1521-
}
1522-
else if (_viewModel.Mods.Where(m => String.IsNullOrEmpty(m.InstallStatus) is false).Count() == 0)
1517+
//if (Program.settings.NexusDetails is null || Program.settings.NexusDetails.IsPremium is false)
1518+
//{
1519+
// await CreateWarningWindow(Program.translation.Get("ui.warning.download_without_premium"), Program.translation.Get("internal.ok"));
1520+
// return;
1521+
//}
1522+
//else if (_viewModel.Mods.Where(m => String.IsNullOrEmpty(m.InstallStatus) is false).Count() == 0)
1523+
//{
1524+
// await CreateWarningWindow(Program.translation.Get("ui.warning.no_downloads_available"), Program.translation.Get("internal.ok"));
1525+
// return;
1526+
//}
1527+
1528+
if (_viewModel.Mods.Where(m => String.IsNullOrEmpty(m.InstallStatus) is false).Count() == 0)
15231529
{
15241530
await CreateWarningWindow(Program.translation.Get("ui.warning.no_downloads_available"), Program.translation.Get("internal.ok"));
15251531
return;
@@ -2146,7 +2152,10 @@ private void UpdateProfile(Profile profile)
21462152
return null;
21472153
}
21482154

2149-
var modDownloadLink = await Nexus.Client.GetFileDownloadLink(modId.Value, modFile.Id, serverName: EnumParser.GetDescription(Program.settings.PreferredNexusServer));
2155+
// Here
2156+
//var modDownloadLink = await Nexus.Client.GetFileDownloadLink(modId.Value, modFile.Id, serverName: EnumParser.GetDescription(Program.settings.PreferredNexusServer));
2157+
string nexusDownloadLink = $"https://www.nexusmods.com/stardewvalley/mods/{mod.NexusModId}?tab=files&file_id={modFile.Id.ToString()}";
2158+
var modDownloadLink = NexusHelper.MakeDownloadLink(nexusDownloadLink, modFile.Id.ToString());
21502159
if (modDownloadLink is null)
21512160
{
21522161
await CreateWarningWindow(String.Format(Program.translation.Get("ui.warning.failed_nexus_install"), mod.Name), Program.translation.Get("internal.ok"));

Stardrop/session.txt

Whitespace-only changes.

image-1.png

68.2 KB
Loading

image.png

90.8 KB
Loading

0 commit comments

Comments
 (0)