This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helper class for scribing ref-deep dicts | |
public class Scribe_Dictionary<T, S> | |
{ | |
List<T> tmpKeys; | |
List<S> tmpVals; | |
public void Scribe(ref Dictionary<T, S> dict, string name) | |
{ | |
if (Verse.Scribe.mode == LoadSaveMode.Saving) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using HarmonyLib; | |
using RimWorld; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Reflection; | |
using Verse; | |
using Verse.Sound; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see https://developer.apple.com/forums/thread/655225 | |
func openFilePaths() -> [String] { | |
(0..<getdtablesize()).map { fd in | |
// Return "" for invalid file descriptors. | |
var flags: CInt = 0 | |
guard fcntl(fd, F_GETFL, &flags) >= 0 else { | |
return "" | |
} | |
// Return "?" for file descriptors not associated with a path, for | |
// example, a socket. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The following C# code from LINQPad (free windows app) uses a method (Test) that | |
// returns an enumeration. Have a look how the IL code that the compiler generates | |
// looks like: | |
static IEnumerable<int> Test() | |
{ | |
yield return 100; | |
var n = Rand.Range(200, 500); | |
yield return n; | |
yield return 600; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* the following will print | |
A: val1=123, val2=456 | |
B: val1=123 | |
With C, we also have 456 | |
C: val1=123 | |
B: done | |
A: done | |
Press any key to exit | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var obj = new SomeObject(); | |
var val = new SomeValue { n = 999 }; | |
Original_Object(obj); | |
Original_Value(val); | |
Original_Object_Ref(ref obj); | |
Original_Value_Ref(ref val); | |
Console.WriteLine(val.n); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<RootNamespace>Analyzer</RootNamespace> | |
<AssemblyName>PerformanceAnalyzer</AssemblyName> | |
<TargetFramework>net472</TargetFramework> | |
<LangVersion>8.0</LangVersion> | |
<PlatformTarget>x64</PlatformTarget> | |
<OutputPath>..\1.2\Assemblies\</OutputPath> | |
<Optimize>true</Optimize> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use with LINQPad | |
void Main() | |
{ | |
var f = new Foo(); | |
var n1 = Traverse.Create(f).Field("bar").Field("n").GetValue<int>(); | |
Console.WriteLine($"n1={n1}"); | |
// does not work because `Field("bar") returns a copy of the struct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
Process(typeof(AttackTargetFinder)); | |
} | |
static Dictionary<FieldInfo, FieldInfo> replacementFields = new Dictionary<FieldInfo, FieldInfo>(); | |
public static void Process(Type type) | |
{ | |
var aName = new AssemblyName(type.Name + "_Replacement"); | |
var ab = AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.RunAndSave); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
Patches.FieldReplace(typeof(TargetClass), "foo"); | |
// Test code | |
var tc = new TargetClass(); | |
tc.Test(); | |
tc.Test(); | |
} |