Skip to content

Commit 4e22d7f

Browse files
committed
Disgusting fix for broken Mono
1 parent bb05f4c commit 4e22d7f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

ArchiSteamFarm/ArchiSteamFarm.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Compile Include="JSON\GitHub.cs" />
110110
<Compile Include="JSON\Steam.cs" />
111111
<Compile Include="Logging.cs" />
112+
<Compile Include="Mono.cs" />
112113
<Compile Include="Program.cs" />
113114
<Compile Include="Properties\AssemblyInfo.cs" />
114115
<Compile Include="Trading.cs" />

ArchiSteamFarm/GlobalConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ internal static GlobalConfig Load(string filePath) {
159159
globalConfig.FarmingDelay = DefaultFarmingDelay;
160160
}
161161

162+
if ((globalConfig.FarmingDelay > 5) && Mono.RequiresWorkaroundForBug41701()) {
163+
Logging.LogGenericWarning("Your Mono runtime is affected by bug 41701, FarmingDelay of " + globalConfig.FarmingDelay + " is not possible - value of 5 will be used instead");
164+
globalConfig.FarmingDelay = 5;
165+
}
166+
162167
if (globalConfig.HttpTimeout == 0) {
163168
Logging.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout + ". Value of " + DefaultHttpTimeout + " will be used instead");
164169
globalConfig.HttpTimeout = DefaultHttpTimeout;

ArchiSteamFarm/Mono.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace ArchiSteamFarm {
5+
internal static class Mono {
6+
internal static bool RequiresWorkaroundForBug41701() {
7+
// https://bugzilla.xamarin.com/show_bug.cgi?id=41701
8+
Version version = GetMonoVersion();
9+
if (version == null) {
10+
return false;
11+
}
12+
13+
return version >= new Version(4, 4);
14+
}
15+
16+
private static Version GetMonoVersion() {
17+
Type type = Type.GetType("Mono.Runtime");
18+
if (type == null) {
19+
return null; // OK, not Mono
20+
}
21+
22+
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
23+
if (displayName == null) {
24+
Logging.LogNullError(nameof(displayName));
25+
return null;
26+
}
27+
28+
string versionString = (string) displayName.Invoke(null, null);
29+
if (string.IsNullOrEmpty(versionString)) {
30+
Logging.LogNullError(nameof(versionString));
31+
return null;
32+
}
33+
34+
int index = versionString.IndexOf(' ');
35+
if (index <= 0) {
36+
Logging.LogNullError(nameof(index));
37+
return null;
38+
}
39+
40+
versionString = versionString.Substring(0, index);
41+
42+
Version version;
43+
if (Version.TryParse(versionString, out version)) {
44+
return version;
45+
}
46+
47+
Logging.LogNullError(nameof(version));
48+
return null;
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)