Skip to content

Commit c21cfbf

Browse files
committed
As per feedback, cache and clean the function.
1 parent 678a7d9 commit c21cfbf

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

KSPCommunityFixes/BugFixes/DoubleCurvePreserveTangents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DoubleCurvePreserveTangents : BasePatch
1111

1212
protected override void ApplyPatches()
1313
{
14-
if (!KSPCommunityFixes.cleanedDll)
14+
if (!KSPCommunityFixes.IsCleanedDll)
1515
{
1616
AddPatch(PatchType.Transpiler, typeof(DoubleCurve), nameof(DoubleCurve.RecomputeTangents));
1717
}

KSPCommunityFixes/BugFixes/ExtendedDeployableParts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void ApplyPatches()
2323
{
2424
AddPatch(PatchType.Transpiler, typeof(ModuleDeployablePart), nameof(ModuleDeployablePart.startFSM));
2525

26-
if (!KSPCommunityFixes.cleanedDll)
26+
if (!KSPCommunityFixes.IsCleanedDll)
2727
{
2828
AddPatch(PatchType.Transpiler, typeof(ModuleDeployableSolarPanel), nameof(ModuleDeployablePart.OnStart));
2929
}

KSPCommunityFixes/BugFixes/ModuleIndexingMismatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static IEnumerable<CodeInstruction> ShipConstruct_LoadShip_Transpiler(IEnumerabl
379379
// first, remove the original module load call
380380
bool originalFound = false;
381381

382-
if (!KSPCommunityFixes.cleanedDll)
382+
if (!KSPCommunityFixes.IsCleanedDll)
383383
{
384384
for (int i = 0; i < code.Count - 6; i++)
385385
{

KSPCommunityFixes/BugFixes/RefundingOnRecovery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RefundingOnRecovery : BasePatch
5858

5959
protected override void ApplyPatches()
6060
{
61-
if (!KSPCommunityFixes.cleanedDll)
61+
if (!KSPCommunityFixes.IsCleanedDll)
6262
{
6363
AddPatch(PatchType.Transpiler, typeof(Funding), "onVesselRecoveryProcessing");
6464
}

KSPCommunityFixes/KSPCommunityFixes.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,27 @@ public static Version KspVersion
5252
}
5353
}
5454

55-
public static bool cleanedDll
55+
//returns true if KSP Assembly-CSharp is probably a cleaned/deobfuscated image
56+
private static bool? cleanedDllCachedValue = null;
57+
public static bool IsCleanedDll
5658
{
5759
get
5860
{
59-
String dllPath = "";
60-
if (Application.platform == RuntimePlatform.WindowsPlayer)
61+
if (cleanedDllCachedValue != null)
6162
{
62-
dllPath = KSPUtil.ApplicationRootPath + "KSP_x64_Data/Managed/Assembly-CSharp.dll";
63+
return (bool)cleanedDllCachedValue;
6364
}
64-
else if (Application.platform == RuntimePlatform.OSXPlayer)
65+
else
6566
{
66-
dllPath = KSPUtil.ApplicationRootPath + "KSP.app/Contents/Resources/Data/Managed/Assembly-CSharp.dll";
67-
}
68-
else if (Application.platform == RuntimePlatform.LinuxPlayer)
69-
{
70-
dllPath = KSPUtil.ApplicationRootPath + "KSP_Data/Managed/Assembly-CSharp.dll";
71-
}
72-
if (File.Exists(dllPath))
73-
{
74-
Byte[] data = File.ReadAllBytes(dllPath);
75-
if ((data.Length < 10000000) && (KSPCommunityFixes.KspVersion >= new Version(1, 12, 0)))
67+
String dllPath = typeof(GameDatabase).Assembly.Location;
68+
if ((new FileInfo(dllPath).Length < 10000000) && Versioning.version_minor.Equals(12))
7669
{
70+
cleanedDllCachedValue = true;
7771
return true; //certainly a home-cleaned dll, no official 1.12.x build of Assembly-CSharp is less than 10MBs.
7872
}
73+
cleanedDllCachedValue = false;
74+
return false;
7975
}
80-
return false;
8176
}
8277
}
8378

0 commit comments

Comments
 (0)