Skip to content

Instantly share code, notes, and snippets.

View PathogenDavid's full-sized avatar
🪄
Got a lot on my plate right now, may be slow to respond

David Maas PathogenDavid

🪄
Got a lot on my plate right now, may be slow to respond
View GitHub Profile
@PathogenDavid
PathogenDavid / NullRefChallenge.cs
Last active August 4, 2023 08:36
Crimes against the .NET Runtime -- Solution to this challenge on the C# Discord: https://discord.com/channels/143867839282020352/578057213084434433/943250054884515840
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
C local = null;
if (local != null && local.Prop)
{
Console.WriteLine(local.ToString()); // Null ref on this line
}
using Biohazrd;
using Microsoft.VisualStudio.Setup.Configuration;
using Microsoft.Win32;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace InfectedWin32.Generator
{
/// <summary>This class helps configure Biohazrd to include a specific version of the Windows SDK and reference files from it</summary>
@PathogenDavid
PathogenDavid / BsonMapper.cs.diff
Created October 10, 2019 11:21
Small, inefficient modification to LiteDB's BsonMapper to allow recursive/mutually recursive database references.
diff --git a/LiteDB/Mapper/BsonMapper.cs b/LiteDB/Mapper/BsonMapper.cs
index 91a7920e..c6dfee9a 100644
--- a/LiteDB/Mapper/BsonMapper.cs
+++ b/LiteDB/Mapper/BsonMapper.cs
@@ -389,11 +389,11 @@ namespace LiteDB
/// </summary>
private static void RegisterDbRefItem(BsonMapper mapper, MemberMapper member, string collection)
{
- // get entity
- var entity = mapper.GetEntityMapper(member.DataType);
@PathogenDavid
PathogenDavid / FixUpNullsBehaviour.cs
Created November 21, 2018 20:25
Workaround for Unity's weird behavior of deserializing some null object references as zombies instead of null - https://github.com/dotnet/csharplang/issues/2020
//----------------------------------------------------------------------------------
// Copyright (c) 2018 David Maas
//
// Permission to use, copy, modify, and/or distribute this software for any purpose
// with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
@PathogenDavid
PathogenDavid / Reebs12Example.cpp
Last active August 25, 2018 11:30
Some example code I wrote for /u/reebs12 on Reddit - https://www.reddit.com/r/gamedev/comments/99y7bb/_/e4raz6j/
#include <Irrlicht.h>
#include <iostream>
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace std;
int main()
@PathogenDavid
PathogenDavid / ModuleWeaver.cs
Last active April 10, 2018 10:08
Evil Fody weaver for force writing readonly fields with test program to be weaved by it.
using Fody;
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Collections.Generic;
using System.Linq;
namespace Evil.Fody
{
public class ModuleWeaver : BaseModuleWeaver
{
@PathogenDavid
PathogenDavid / TupleSerializer.cs
Last active August 26, 2017 18:40
A partially-finished ValueTuple serializer for SharpYaml.
using SharpYaml;
using SharpYaml.Events;
using SharpYaml.Serialization;
using SharpYaml.Serialization.Descriptors;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
namespace YamlPlayground
@PathogenDavid
PathogenDavid / systime.c
Created August 5, 2014 07:28
tsk_switch_handler
void tsk_switch_handler()
{
tm_current_slice--; //609
if (tm_current_slice == 0) //610
{
//Timeslice exhausted, switch to another thread as long as we can get access to the kernel critical section...
if (kernel_critical_section) //612, 613
{
//Thread is in kernel critical section, so we give the thread
//some extra time to leave it. (We can't do anything until it
@PathogenDavid
PathogenDavid / output.txt
Created July 13, 2014 02:37
EnumDisplayDevices Output
======= Display Device 0 =======
DeviceName: \\.\DISPLAY1
DeviceString: AMD Radeon HD 7800 Series
StateFlags: ACTIVE
DeviceID: PCI\VEN_1002&DEV_6819&SUBSYS_E221174B&REV_00
Total display modes: 95
======= Display Device 0,0 =======
DeviceName: \\.\DISPLAY1\Monitor0
DeviceString: Generic PnP Monitor
StateFlags: ACTIVE
@PathogenDavid
PathogenDavid / main.cpp
Created July 13, 2014 02:36
EnumDisplayDevices
#include <Windows.h>
#include <stdio.h>
void PrintDisplayDevice(DISPLAY_DEVICEA* displayDevice, const char* indent = "")
{
printf("%sDeviceName: %s\n", indent, displayDevice->DeviceName);
printf("%sDeviceString: %s\n", indent, displayDevice->DeviceString);
printf("%sStateFlags:", indent);
if (displayDevice->StateFlags & DISPLAY_DEVICE_ACTIVE) { printf(" ACTIVE"); }
if (displayDevice->StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) { printf(" MIRRORING_DRIVER"); }