Skip to content

Instantly share code, notes, and snippets.

View kornman00's full-sized avatar

Sean kornman00

View GitHub Profile
@kornman00
kornman00 / GetDelegateForFunctionPointer.cs
Created August 18, 2012 06:55
GetDelegateForFunctionPointer, kornman00
using System;
using System.Linq;
using Contracts = System.Diagnostics.Contracts;
using Contract = System.Diagnostics.Contracts.Contract;
using Reflect = System.Reflection;
using Interop = System.Runtime.InteropServices;
namespace KSoft.Reflection
{
public static partial class Util
@kornman00
kornman00 / ProfilerWindowInterop.cs
Created February 21, 2016 21:39
Preferences editor for Unity3D's profiler window
// Use at your own risk.
// Should work with any Unity Editor since at least 4.6
// These macros make it so changes aren't actually committed to the EditorPrefs. Instead, changes are Debug.Log'd
//#define VIEW_PREFS_READ_ONLY
#define CHART_PREFS_READ_ONLY
// You'll need this defined, unless you have my BitVector32 from https://bitbucket.org/KornnerStudios/ksoft
#define USE_SYSTEM_BITVECTOR
using System;
@kornman00
kornman00 / EnumAndCustomComparer.cs
Created April 12, 2016 17:25
The power of per-frame GC analysis blog source
// #IMPL: If you change the underlying type, update ProtoSomething.ComparerImpl too!
public enum HardCodedThing : byte
{
Some,
Thing,
Something,
Darkside
cMaxCount,
};
@kornman00
kornman00 / After.cs
Created April 14, 2016 21:14
Avoiding heap allocations in generic serialization code
// #NOTE: be mindful of how large T actually is and whether or not your runtime does or doesn't
// optimize passing large structs by reference instead of copying bits to other parts of the stack
public static T Read<T>(this BinaryReader reader, T item = default(T))
where T : IStreamSerializable, new()
{
if (item == null) // value types are never null, so this helps us avoid heap allocations
item = new T();
item.Load(reader);
return item;
@kornman00
kornman00 / SeeingSharpCpp_Il2CppSetOption.cpp
Created November 30, 2015 05:26
Code Listings for Seeing Sharp C++: The Il2CppSetOption attribute
extern TypeInfo* Int32U5BU5D_t1872284309_0_il2cpp_TypeInfo_var;
// NOTE: 'Int32U5BU5D_t1872284309_0' is to IL2CPP as 'int[]' is to C#
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksEnabled()
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksEnabled_m_1098767581_0 (Object_t * __this /* static, unused */, const MethodInfo* method)
{
Int32U5BU5D_t1872284309_0* V_0 = {0};
{
//var array = new int[1];
@kornman00
kornman00 / objects.xml
Created February 19, 2017 17:19
Change building commands in Halo Wars supporting docs
<Object name="unsc_bldg_barracks_01" id="0" dbid="137">
<Command Type="TrainSquad" Position="1">unsc_inf_marine_01</Command>
<Command Type="TrainSquad" Position="1">unsc_inf_odst_01</Command>
<Command Type="TrainSquad" Position="2">unsc_inf_flameMarine_01</Command>
<Command Type="TrainSquad" Position="3">unsc_inf_spartan_01</Command>
<Command Type="Research" Position="7">unsc_marine_upgrade1</Command>
<Command Type="Research" Position="7">unsc_marine_upgrade2</Command>
<Command Type="Research" Position="7">unsc_marine_upgrade3</Command>
<Command Type="Research" Position="7">unsc_odst_upgrade1</Command>
@kornman00
kornman00 / sort.xslt
Created March 14, 2017 14:01
Sort non 1st level XML elements and their attributes for better diffing
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*">
<xsl:sort select="name()"/>
</xsl:apply-templates>
@kornman00
kornman00 / SeeingSharpCpp_Statics.cs
Created December 13, 2015 22:21
Code Listings for Seeing Sharp C++: Behind the IL2CPP magic of Metadata and Statics
using System;
namespace SharpCpp
{
public struct ValueTypeWithCctor
{
public int Value;
// Comment this out and the CPP code for operator+ won't have a prologue nor invoke IL2CPP_RUNTIME_CLASS_INIT.
// This causes a hidden cctor to be generated by the compiler.
@kornman00
kornman00 / TraceListViewModel.cs
Created August 29, 2022 05:26
TraceListViewModel for Gemini PR #328
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
using Gemini.Framework;
using Gemini.Framework.Services;
using Gemini.Modules.Inspector;
namespace SomeRedactedAppName.Modules.TraceList