Skip to content

Instantly share code, notes, and snippets.

View ogxd's full-sized avatar
👋

Olivier Giniaux ogxd

👋
View GitHub Profile
@aaaddress1
aaaddress1 / clrHosting_v4.0.cpp
Last active March 22, 2024 14:50
CLR Hosting: running dotNet binary in C/C++ & rewrite from .NET(4+) COM interface
// CLR Hosting, by aaaddress1@chroot.org
//
// it's a new edition rewrite for .NET(4+) COM interface
// original from github.com/etormadiv/HostingCLR
// & blog.xpnsec.com/hiding-your-dotnet-etw
//
// this PoC supports the following .NET entry:
// >>>> static void Main(string[] args);
//
#include <stdio.h>
@mtolk
mtolk / mermaid.html
Created September 16, 2020 12:59
This gist was created to anwser a question about using mermaidjs in the zola static site generator: https://zola.discourse.group/t/mermaid-integration/573?u=marco
<!-- should be in templates/ -->
<html>
<head>
<style>
div.mermaid {
width:25%;
}
</style>
</head>
<body>
#include <stdio.h>
#include <Windows.h>
#include <MSCorEE.h>
#include <MetaHost.h>
#include <evntprov.h>
int main()
{
ICLRMetaHost* metaHost = NULL;
IEnumUnknown* runtime = NULL;
@ogxd
ogxd / Screenshot.cs
Last active April 11, 2024 06:17
Unity Editor tool to take high quality screenshots with transparent background, high resolution and auto cropping.
using System.IO;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class Screenshot
{
static Screenshot()
{
EditorApplication.delayCall += () => {
@ogxd
ogxd / TransformExtensions.cs
Last active November 23, 2023 06:34
Get or set a Transform matrix using TRS decompositions
using UnityEngine;
public static class TransformExtensions {
private static void GetTRS(this Matrix4x4 matrix, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
{
float det = matrix.GetDeterminant();
// Scale
scale.x = matrix.MultiplyVector(new Vector3(1, 0, 0)).magnitude;
@ogxd
ogxd / Dispatcher.cs
Created October 3, 2019 16:46
Dispatcher for Unity
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.LowLevel;
#pragma warning disable CS1998
@ogxd
ogxd / MonoContext.cs
Last active March 9, 2020 21:49
Coroutines outside of Unity's component, global update callback & main thread dispatcher
using System;
using System.Collections.Concurrent;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
[ExecuteInEditMode]
public sealed class MonoContext : MonoBehaviour {
public static UnityEvent OnUpdate;
@ogxd
ogxd / Profiling.cs
Last active March 9, 2020 21:49
Display elasped time in a time interval.
using System;
using System.Collections.Generic;
using System.Diagnostics;
public static class Profiling {
private static Dictionary<string, Stopwatch> stopwatches = new Dictionary<string, Stopwatch>();
public static void Start(string key) {
if (!stopwatches.ContainsKey(key))
@ogxd
ogxd / ProjectReferences.cs
Last active March 9, 2020 21:49
Easy project references for Unity, without using Resources.Load ! Faster and cleaner.
using UnityEngine;
public class ProjectReferences<T> : ScriptableObject where T : ScriptableObject
{
private static T instance;
public static T Instance {
get {
if (instance == null) {
instance = Resources.Load<T>(typeof(T).Name);
if (instance == null) {
@ogxd
ogxd / MeshFromBounds.cs
Last active March 9, 2020 21:49
Create a Unity mesh from given bounds
public Mesh CreateMeshFromBounds(Vector3 center, Vector3 extends) {
var xm_ym_zm = new Vector3(center.x - extends.x, center.y - extends.y, center.z - extends.z);
var xp_ym_zm = new Vector3(center.x + extends.x, center.y - extends.y, center.z - extends.z);
var xm_yp_zm = new Vector3(center.x - extends.x, center.y + extends.y, center.z - extends.z);
var xp_yp_zm = new Vector3(center.x + extends.x, center.y + extends.y, center.z - extends.z);
var xm_ym_zp = new Vector3(center.x - extends.x, center.y - extends.y, center.z + extends.z);
var xp_ym_zp = new Vector3(center.x + extends.x, center.y - extends.y, center.z + extends.z);
var xm_yp_zp = new Vector3(center.x - extends.x, center.y + extends.y, center.z + extends.z);
var xp_yp_zp = new Vector3(center.x + extends.x, center.y + extends.y, center.z + extends.z);