Skip to content

Instantly share code, notes, and snippets.

@Noxalus
Noxalus / README.md
Created July 28, 2020 14:19
Unity Modding

Code / Logic

  • How to load new scripts?
    • Compile MOD project DLL and load the Assembly during runtime in the original project (done by ModTool)
  • How to ensure the loaded code is secure?
    • Using Mono.Cecil (an official Unity package exists for that), we can limit the access to certain methods/APIs (done by ModTool)
  • How to use the original project code? (inherit from an existing classes, use existing components, etc...)
    • Export the project DLL (and its dependencies) in an .unitypackage file to import in the MOD project (done by ModTool)
    • TODO: Original project code should be under an assembly definition file and the needed DLL referenced by the ASMDEF should be included in the .unitypackage?
  • How to make sure the Unity settings for the MOD corresponds to the one of the original project?
@Noxalus
Noxalus / TargetFPS.cs
Last active January 9, 2019 09:26
A Unity component to force max FPS to a specific value
using UnityEngine;
public class TargetFPS : MonoBehaviour
{
[SerializeField] private int _targetFramerateValue = 60;
void Awake()
{
Application.targetFrameRate = _targetFramerateValue;
QualitySettings.vSyncCount = 0;
@Noxalus
Noxalus / CameraScreenshot.cs
Created January 9, 2019 09:23
Unity component to take a screenshot of the camera rendering
using System.IO;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class CameraScreenshot : MonoBehaviour
{
[SerializeField] private RenderTexture _outputTexture = null;
[SerializeField] private KeyCode _key = KeyCode.Space;
[SerializeField] private string _path = string.Empty;
@Noxalus
Noxalus / SceneWindow.cs
Created January 4, 2019 10:52
Add a entry in the Unity menu Window/Scenes that shows a window to easily load scene files.
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
class SceneWindow : EditorWindow
{
[MenuItem("Window/Scenes")]
public static void ShowWindow()
using UnityEngine;
using System.Collections;
public class DragObject2D : MonoBehaviour
{
public float dampingRatio = 0.5f;
public float frequency = 5f;
private TargetJoint2D targetJoint;
@Noxalus
Noxalus / rabbitmq-dlx-queue.js
Created August 10, 2017 15:06
RabbitMQ DLX + priority queue
let messageOptions = {
persistent: true,
expiration: 5000,
priority: 10
};
var queues = {
INCOMING_MESSAGE_QUEUE: { name: 'incomming_message', options: { durable: true }, exchange: 'incomming-message-exchange', routing: 'incomming-message-routing' },
INCOMING_MESSAGE_DLX_QUEUE: {
name: 'incomming_message_dlx',
@Noxalus
Noxalus / Game1.cs
Created January 15, 2017 15:03
MonoGame.Extended: BoxingViewportAdapter issue with RenderTarget
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.ViewportAdapters;
namespace Demo.ViewportAdapters
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
@Noxalus
Noxalus / test.cpp
Last active May 23, 2017 23:35
GearVR intergration with SDL
// Setup the Java references.
ovrJava java;
auto jniEnv = (JNIEnv*)SDL_AndroidGetJNIEnv();
JavaVM* javaVm;
jniEnv->GetJavaVM(&javaVm);
auto activity = (jobject)SDL_AndroidGetActivity();
@Noxalus
Noxalus / gist:18de2603812e31e687de
Created May 29, 2015 08:41
Detect red circles with OpenCV 2.4.11
Mat src(height, width, CV_8UC4, const_cast<unsigned char*>(imageData.data()));
Mat src_gray, hsv, final;
// Create the final image to display
cvtColor(src, final, CV_BGRA2RGBA);
// Remove useless alpha canal
cvtColor(src, src, CV_BGRA2BGR);
// Convert image to HSV
@Noxalus
Noxalus / gist:a51af67ba868730ae3bc
Created May 26, 2015 17:13
Use GaussianBlur with OpenCV
void proccessImage(std::vector<unsigned char>& imageData, int width, int height)
{
Mat src(width, height, CV_8UC4, const_cast<unsigned char*>(imageData.data()));
Mat src_gray, final;
// Convert the source image to gray
cvtColor(src, src_gray, CV_BGRA2GRAY);
// Apply gaussian blur on the gray image
GaussianBlur(src_gray, src_gray, cv::Size(9, 9), 2, 2);