Skip to content

Commit 64cd523

Browse files
committed
Bug Fixes & Improvements
Fixed some bugs, added better error handling and added a "connect via url" option as well as changed some file handling etc
1 parent a7be5f3 commit 64cd523

File tree

13 files changed

+259
-50
lines changed

13 files changed

+259
-50
lines changed

DCTS.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,37 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Debug|ARM = Debug|ARM
12+
Debug|ARM64 = Debug|ARM64
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
1115
Release|Any CPU = Release|Any CPU
16+
Release|ARM = Release|ARM
17+
Release|ARM64 = Release|ARM64
18+
Release|x64 = Release|x64
19+
Release|x86 = Release|x86
1220
EndGlobalSection
1321
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1422
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1523
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|ARM.ActiveCfg = Debug|Any CPU
25+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|ARM.Build.0 = Debug|Any CPU
26+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|ARM64.ActiveCfg = Debug|Any CPU
27+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|ARM64.Build.0 = Debug|Any CPU
28+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|x64.ActiveCfg = Debug|x64
29+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|x64.Build.0 = Debug|x64
30+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|x86.ActiveCfg = Debug|Any CPU
31+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Debug|x86.Build.0 = Debug|Any CPU
1632
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|Any CPU.ActiveCfg = Release|Any CPU
1733
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|ARM.ActiveCfg = Release|Any CPU
35+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|ARM.Build.0 = Release|Any CPU
36+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|ARM64.ActiveCfg = Release|Any CPU
37+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|ARM64.Build.0 = Release|Any CPU
38+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|x64.ActiveCfg = Release|Any CPU
39+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|x64.Build.0 = Release|Any CPU
40+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|x86.ActiveCfg = Release|Any CPU
41+
{EE83FDC7-82C6-4EC7-B7AB-07468010A22C}.Release|x86.Build.0 = Release|Any CPU
1842
EndGlobalSection
1943
GlobalSection(SolutionProperties) = preSolution
2044
HideSolutionNode = FALSE

ModLoader/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<setting name="skippedVersion" serializeAs="String">
2020
<value />
2121
</setting>
22+
<setting name="FirstRunAfterUpgrade" serializeAs="String">
23+
<value>True</value>
24+
</setting>
2225
</DCTS.Properties.Settings>
2326
</userSettings>
2427
</configuration>

ModLoader/CryptoHelper.cs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModLoader;
22
using System;
33
using System.Diagnostics;
4+
using System.Reflection.Metadata;
45
using System.Security.Cryptography;
56
using System.Text;
67
using System.Text.Json;
@@ -22,7 +23,8 @@ public CryptoHelper()
2223
RSA-SHA256-PKCS1 signs and verifies data
2324
*/
2425

25-
private readonly string KeyFilePath = Path.Combine(Application.StartupPath, "privatekey.json");
26+
27+
private readonly string KeyFilePath = Path.Combine(Form1.appPath, "privatekey.json");
2628

2729
public (string PrivateKey, string PublicKey) EnsureKeyPair()
2830
{
@@ -158,30 +160,39 @@ public string EncryptEnvelope(string plaintext, string recipientPemOrPassword)
158160

159161
public string DecryptEnvelope(string method, string encKey, string iv, string tag, string ciphertext, string privateKeyPem)
160162
{
161-
byte[] aesKey;
162-
163-
if (method == "rsa")
164-
{
165-
byte[] encKeyBytes = Convert.FromBase64String(encKey);
166-
using var rsa = RSA.Create();
167-
rsa.ImportFromPem(privateKeyPem.AsSpan());
168-
aesKey = rsa.Decrypt(encKeyBytes, RSAEncryptionPadding.OaepSHA1);
169-
}
170-
else if (method == "password")
163+
try
171164
{
172-
throw new Exception("password mode not supported in this overload");
173-
}
174-
else throw new Exception("unsupported method");
165+
byte[] aesKey;
175166

176-
byte[] ivBytes = Convert.FromBase64String(iv);
177-
byte[] tagBytes = Convert.FromBase64String(tag);
178-
byte[] cipherBytes = Convert.FromBase64String(ciphertext);
167+
if (method == "rsa")
168+
{
169+
byte[] encKeyBytes = Convert.FromBase64String(encKey);
170+
using var rsa = RSA.Create();
171+
rsa.ImportFromPem(privateKeyPem.AsSpan());
172+
aesKey = rsa.Decrypt(encKeyBytes, RSAEncryptionPadding.OaepSHA1);
173+
}
174+
else if (method == "password")
175+
{
176+
throw new Exception("password mode not supported in this overload");
177+
}
178+
else throw new Exception("unsupported method");
179+
180+
byte[] ivBytes = Convert.FromBase64String(iv);
181+
byte[] tagBytes = Convert.FromBase64String(tag);
182+
byte[] cipherBytes = Convert.FromBase64String(ciphertext);
179183

180-
byte[] plainBytes = new byte[cipherBytes.Length];
181-
using var aes = new AesGcm(aesKey);
182-
aes.Decrypt(ivBytes, cipherBytes, tagBytes, plainBytes);
184+
byte[] plainBytes = new byte[cipherBytes.Length];
185+
using var aes = new AesGcm(aesKey);
186+
aes.Decrypt(ivBytes, cipherBytes, tagBytes, plainBytes);
183187

184-
return Encoding.UTF8.GetString(plainBytes);
188+
return Encoding.UTF8.GetString(plainBytes);
189+
}
190+
catch (Exception ex)
191+
{
192+
Logger.Log("Cant decrypt data");
193+
Logger.Log(ex.Message);
194+
return "";
195+
}
185196
}
186197

187198

ModLoader/DCTS.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageIcon>server icon.png</PackageIcon>
1717
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
1818
<Version>$(VersionPrefix)</Version>
19+
<Platforms>AnyCPU;x64</Platforms>
1920
</PropertyGroup>
2021

2122
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -26,6 +27,14 @@
2627
<Deterministic>False</Deterministic>
2728
</PropertyGroup>
2829

30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
31+
<Deterministic>False</Deterministic>
32+
</PropertyGroup>
33+
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
35+
<Deterministic>False</Deterministic>
36+
</PropertyGroup>
37+
2938
<ItemGroup>
3039
<Content Include="web\**\*">
3140
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -47,7 +56,7 @@
4756
<ItemGroup>
4857
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3537.50" />
4958
<PackageReference Include="MtrDev.WebView2.Interop" Version="0.9.430.3" />
50-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
59+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
5160
<PackageReference Include="SSH.NET" Version="2025.0.0" />
5261
</ItemGroup>
5362

ModLoader/Form1.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public partial class Form1 : Form
3636
public static string branch = DCTS.Properties.Settings.Default.branch;
3737
private bool didInit = false;
3838

39+
public static string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "dcts");
40+
3941

4042
// some hacky shit
4143
[DllImport("dwmapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
@@ -326,6 +328,11 @@ private void StartFadeOut(int interval, double fadeStep)
326328

327329
private void Form1_Load(object sender, EventArgs e)
328330
{
331+
if (!Directory.Exists(appPath))
332+
{
333+
Directory.CreateDirectory(appPath);
334+
}
335+
329336
Logger.Clear();
330337
EnableDarkTitlebar(this.Handle);
331338

@@ -337,7 +344,6 @@ private void Form1_Load(object sender, EventArgs e)
337344
);
338345

339346
cryptoHelper.EnsureKeyPair();
340-
341347
Updater.CheckAsync("hackthedev/dcts-client-shipping", GetVersion());
342348
}
343349

ModLoader/Program.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ static class Program
77
[STAThread]
88
static void Main(string[] args)
99
{
10-
DCTS.Properties.Settings.Default.Upgrade();
11-
DCTS.Properties.Settings.Default.Save();
12-
DCTS.Properties.Settings.Default.Reload();
13-
10+
if (DCTS.Properties.Settings.Default.FirstRunAfterUpgrade)
11+
{
12+
DCTS.Properties.Settings.Default.Upgrade();
13+
DCTS.Properties.Settings.Default.FirstRunAfterUpgrade = false;
14+
DCTS.Properties.Settings.Default.Save();
15+
}
1416

1517
bool isNewInstance;
1618
using (Mutex mutex = new Mutex(true, "MySuperSickAppMutexForDCTS", out isNewInstance))

ModLoader/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ModLoader/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<Setting Name="skippedVersion" Type="System.String" Scope="User">
1515
<Value Profile="(Default)" />
1616
</Setting>
17+
<Setting Name="FirstRunAfterUpgrade" Type="System.Boolean" Scope="User">
18+
<Value Profile="(Default)">True</Value>
19+
</Setting>
1720
</Settings>
1821
</SettingsFile>

ModLoader/Updater.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ public static async Task CheckAsync(string repo, string currentVersion)
2424
return;
2525

2626
// return if we skipped this version
27-
if (Properties.Settings.Default.skippedVersion.Length > 0)
27+
if (DCTS.Properties.Settings.Default.skippedVersion.Length > 0)
2828
{
29-
if (remoteVersion == Properties.Settings.Default.skippedVersion) ;
30-
return;
29+
if (remoteVersion == DCTS.Properties.Settings.Default.skippedVersion)
30+
{
31+
return;
32+
}
3133
}
3234

3335
DialogResult result = MessageBox.Show(
@@ -49,9 +51,9 @@ public static async Task CheckAsync(string repo, string currentVersion)
4951
// option to skip version
5052
if (skipVersion == DialogResult.Yes)
5153
{
52-
Properties.Settings.Default.skippedVersion = remoteVersion;
53-
Properties.Settings.Default.Save();
54-
Properties.Settings.Default.Reload();
54+
DCTS.Properties.Settings.Default.skippedVersion = remoteVersion;
55+
DCTS.Properties.Settings.Default.Save();
56+
DCTS.Properties.Settings.Default.Reload();
5557
}
5658

5759
return;
@@ -64,12 +66,6 @@ public static async Task CheckAsync(string repo, string currentVersion)
6466

6567
if (File.Exists(zipPath))
6668
{
67-
MessageBox.Show(
68-
$"The update was downloaded!\n" +
69-
$"- ) After pressing 'OK' a ZIP file dialog will appear." +
70-
$"- ) Continue to unzip it." +
71-
$"- ) If asked to replace files, choose to replace them all",
72-
"DCTS", MessageBoxButtons.OK, MessageBoxIcon.Error);
7369
Process.Start(zipPath);
7470

7571
Application.Exit();

ModLoader/logo 4x4.png

9.02 KB
Loading

0 commit comments

Comments
 (0)