Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9107409
Use correct filename case for building on Linux
coledot Dec 14, 2020
0d9f42c
First set of memory leak fixes, mostly involving save file loading
coledot Jan 23, 2021
d90f37e
cleanup & expand on message subscription fixes
coledot Feb 6, 2021
4791c14
add more fixes for OnLanguageChanged subs including travel contract h…
coledot Feb 12, 2021
d9f97f1
replace existing OnLanguageChanged fixes with a set of much simpler f…
coledot Feb 15, 2021
d4d9971
cleanup
coledot Feb 15, 2021
bdf1c30
Ignore vim .swp files
coledot Dec 16, 2020
39ec6ea
Add NavigationMapFilterLagFix, which saves a few seconds in modpacks …
coledot Dec 16, 2020
b0d4d67
Use a more robust & defensive method of finding the code to remove
coledot Dec 16, 2020
ef9bc6c
Update README.md with NavigationMapFilterLagFix
coledot Dec 16, 2020
9f69849
Cleanup
coledot Dec 17, 2020
d069ed9
Merged SimpleMetrics to branch
m22spencer Jan 9, 2019
1f8626c
Cleanup
coledot Dec 22, 2020
485679a
add UnityHeapDump and add logging for MessageCenter subscriptions
coledot Jan 23, 2021
e9b5631
modify UnityHeapDump to sort by children names (easier to diff)
coledot Feb 6, 2021
22c4bff
add Stack_Trace, AuditMessageCenter; replace UnityHeapDump with HeapS…
coledot Feb 6, 2021
6f01d6f
wee fix
coledot Feb 6, 2021
181b0fa
various tweaks to SimpleMetrics
coledot Feb 12, 2021
a5d053b
remove UnityHeapDump
coledot Feb 12, 2021
3dc060c
use Ctrl+Shift+$foo for triggering metrics, other small changes
coledot Feb 21, 2021
aa887e0
make SimpleMetrics off by default
coledot Feb 21, 2021
d248019
remove unrelated changes (really oughtn't have used rebase...)
coledot Feb 21, 2021
c11a54d
update readme
coledot Feb 21, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,4 @@ __pycache__/

libs/
libs.fixed/
*/*.swp
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
# Experimental patches
- MDDB_TagsetQueryInChunks
- Prevent the game from softlocking/infinite loading when MDDB builds queries too large for sqlite3 to handle.
- SimpleMetrics
- Performance measurement tools used by the mod developers. Unless you know what you're doing, leave this set to false.

# Upcoming patches
- ParallelizeLoad (Disabled by default: Experimental, Dangerous)
Expand Down
5 changes: 3 additions & 2 deletions source/BattletechPerformanceFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@
<Compile Include="LoadFixes.cs" />
<Compile Include="ShaderDependencyOverride.cs" />
<Compile Include="ShopTabLagFix.cs" />
<Compile Include="PatchMechLabLimitItems.cs" />
<Compile Include="PatchMechlabLimitItems.cs" />
<Compile Include="EnableLoggingDuringLoads.cs" />
<Compile Include="RemovedFlashpointFix.cs" />
<Compile Include="RemovedContractsFix.cs" />
<Compile Include="EnableConsole.cs" />
<Compile Include="VersionManifestPatches.cs" />
<Compile Include="SimpleMetrics.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\mod.json" />
Expand Down Expand Up @@ -120,4 +121,4 @@
<PostBuildEvent Condition="$(IsLinux) == true">yes | cp "$(TargetDir)$(TargetName).dll" "$(SolutionDir)../../Mods/BattletechPerformanceFix/$(TargetName).dll"</PostBuildEvent>
<PostBuildEvent Condition="$(IsOSX) == true">yes | cp "$(TargetDir)$(TargetName).dll" "$(SolutionDir)../../Mods/BattletechPerformanceFix/$(TargetName).dll"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
51 changes: 38 additions & 13 deletions source/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public static IEnumerable<IEnumerable<T>> GroupsOf<T>(this IEnumerable<T> items,
.GroupBy(kv => kv.idx / count, kv => kv.item)
.Select(x => x.Select(v => v));
}

public static IEnumerable<KeyValuePair<T,K>> Zip<T,K>(this IEnumerable<T> left, IEnumerable<K> right) {
var itl = left.GetEnumerator();
var itr = right.GetEnumerator();

while(itl.MoveNext() && itr.MoveNext()) {
yield return new KeyValuePair<T,K>(itl.Current, itr.Current);
}
}

public static T GetWithDefault<K,T>(this Dictionary<K,T> d, K key, Func<T> lazyDefault)
=> d.TryGetValue(key, out var val) ? val : d[key] = lazyDefault();
Expand Down Expand Up @@ -228,33 +237,49 @@ public static void Patch( this MethodBase method
Trap(() => Main.harmony.Patch( method, patches[0], patches[1], patches[2]));

}

public static MethodBase FindQualifiedMethod(this string qualifiedName) {
var ss = qualifiedName.Split(Array("::"), StringSplitOptions.None).ToArray();
if (ss.Length != 2) throw new Exception($"Invalid QualifiedMethod string {qualifiedName}");
var type = ss[0];
var meth = ss[1];
LogSpam($"FindQualifiedMethod for {type} {meth}");
return AppDomain.CurrentDomain.GetAssemblies()
.Select(asm => asm.GetType(type))
.Where(t => t != null)
.SingleOrDefault()
?.GetMethod(meth, AccessTools.all);
}

public static string QualifiedSignature(this MethodBase method)
=> $"{method.DeclaringType.FullName}::{method.ToString()}";

public static void Patch<T>( this string method
, string premethod = null
, string postmethod = null
, string transpilemethod = null
, int priority = Priority.Normal
) {
public static void Patch( this string method
, Type t
, string premethod = null
, string postmethod = null
, string transpilemethod = null
, int priority = Priority.Normal
) {
MethodBase meth = null;
if (method.StartsWith("ctor")) meth = (MethodBase)typeof(T).GetConstructors(AccessTools.all)[0];
else if (method.StartsWith("get_")) meth = (MethodBase)typeof(T).GetProperties(AccessTools.all)
if (method.StartsWith("ctor")) meth = (MethodBase)t.GetConstructors(AccessTools.all)[0];
else if (method.StartsWith("get_")) meth = (MethodBase)t.GetProperties(AccessTools.all)
.FirstOrDefault(mm => { LogDebug($"{mm.Name}"); return method.EndsWith(mm.Name); })
?.GetGetMethod();
else meth = (MethodBase)typeof(T).GetMethods(AccessTools.all)
else meth = (MethodBase)t.GetMethods(AccessTools.all)
.FirstOrDefault(mm => mm.Name == method && mm.GetMethodBody() != null);
meth.LogIfNull($"Failed to find patchable function {method} on {typeof(T).FullName}");
meth.LogIfNull($"Failed to find patchable function {method} on {t.FullName}");
meth.Patch(premethod, postmethod, transpilemethod, priority);
}

public static void Pre<T>(this string method, string patchmethod = null, int priority = Priority.Normal)
=> method.Patch<T>(patchmethod ?? $"{method}_Pre", null, null, priority);
=> method.Patch(typeof(T), patchmethod ?? $"{method}_Pre", null, null, priority);

public static void Post<T>(this string method, string patchmethod = null, int priority = Priority.Normal)
=> method.Patch<T>(null, patchmethod ?? $"{method}_Post", null, priority);
=> method.Patch(typeof(T), null, patchmethod ?? $"{method}_Post", null, priority);

public static void Transpile<T>(this string method, string patchmethod = null, int priority = Priority.Normal)
=> method.Patch<T>(null, null, patchmethod ?? $"{method}_Transpile", priority);
=> method.Patch(typeof(T), null, null, patchmethod ?? $"{method}_Transpile", priority);

// C# macros when...
public static void Pre<T>(this string method, Action<T> f) where T : class
Expand Down
1 change: 1 addition & 0 deletions source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static void Start(string modDirectory, string json)
{ typeof(RemovedContractsFix), true },
{ typeof(VersionManifestPatches), true },
{ typeof(EnableConsole), false },
{ typeof(SimpleMetrics), false }
};


Expand Down
Loading