Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View schellingb's full-sized avatar

Bernhard Schelling schellingb

View GitHub Profile
@schellingb
schellingb / UE4GameUserSettingsLoader.cpp
Created March 26, 2024 03:45
Load GameUserSettings.ini from a UE4 build of a game in a UE5 build of a game
#if PLATFORM_WINDOWS && !WITH_EDITOR && UE_BUILD_SHIPPING
static struct FUE4GameUserSettingsLoader
{
FUE4GameUserSettingsLoader()
{
// This static constructor is called early enough that we can bind these required delegates before engine startup
FCoreDelegates::TSCountPreLoadConfigFileRespondersDelegate().AddStatic(CountPreLoadConfigFileRespondersDelegate);
FCoreDelegates::TSPreLoadConfigFileDelegate().AddStatic(PreLoadConfigFileDelegate);
FCoreDelegates::TSPreSaveConfigFileDelegate().AddStatic(PreSaveConfigFileDelegate);
}
@schellingb
schellingb / access_private_member.cpp
Last active November 21, 2022 02:19
Safest hack to access private data of a C++ class
/*
Access C++ Private Member
License: Public Domain (www.unlicense.org)
Based on http://cpp.kjx.cz/private_backdoor.html which itself is based on http://bloglitb.blogspot.com/2011/12/access-to-private-members-safer.html
*/
#include <stdio.h>
class CSafe
{

Building a universal Windows 7/Windows 10 .NET EXE

The problem with building a .NET (classic) executable that runs on both clean Windows 7 install and on Windows 10 is that Windows 7 only ships with .NET 3.5 inbox and Windows 10 ships with .NET 4.X. A .NET 3.5 executable will not run on a (clean install) Windows 10 directly. It can be coerced to do so in multiple ways, but none of them are "worry-free single file" solutions (config file, registry settings, environment variables, etc.).

One of the solutions is to set COMPLUS_OnlyUseLatestCLR environment variable to 1 before the process starts. This will allow .NET 4.X to take over execution of the program. This still doesn't qualify as "worry-free" because we need a batch file or something else to set the envionment for us before the process start (it's too late once Main is executing).

One weird trick to run the same executable on both Windows 7 and Windows 10

When I said we need to set COMPLUS_OnlyUseLatestCLR environment variable to 1 bef

@schellingb
schellingb / risc_x86_runcode.c
Last active January 17, 2021 14:10
DOSBox - risc_x86 gen_runcode without inline assembly
static BlockReturn gen_runcodeInit(Bit8u *code);
static BlockReturn (*gen_runcode)(Bit8u *code) = gen_runcodeInit;
static BlockReturn gen_runcodeInit(Bit8u *code) {
Bit8u* oldpos = cache.pos;
cache.pos = &cache_code_link_blocks[128];
gen_runcode = (BlockReturn(*)(Bit8u*))cache.pos;
#if 1
cache_addb(0x53); // push ebx
@schellingb
schellingb / UE4-Macro_VS_Range_VS_Lambda_VS_TFunctionRef_VS_TFunction.cpp
Last active August 28, 2022 01:01
UE4 Macro VS Range VS Lambda VS TFunctionRef VS TFunction
#define SpiralForMacro(STARTX, STARTY, CODE) \
{ \
FIntPoint tile = FIntPoint(0, 0), delta = FIntPoint(0, -1); \
for (;;) \
{ \
FIntPoint tc = {(STARTX) + tile.X, (STARTY) + tile.Y}; \
\
{ CODE } \
\
if ((tile.X == tile.Y) || ((tile.X < 0) && (tile.X == -tile.Y)) || ((tile.X > 0) && (tile.X == 1-tile.Y))) \
@schellingb
schellingb / generate_wav_header.c
Last active December 2, 2023 15:06
Generate WAV header
Bit8u hdr[44];
#define WAV_WRITE_LE16(b,v) { (b)[0] = (unsigned char)((unsigned short)(v) & 0xFF); (b)[1] = (unsigned char)((unsigned short)(v) >> 8); }
#define WAV_WRITE_LE32(b,v) { (b)[0] = (unsigned char)((unsigned int)(v) & 0xFF); (b)[1] = (unsigned char)(((unsigned int)(v) >> 8) & 0xFF); (b)[2] = (unsigned char)(((unsigned int)(v) >> 16) & 0xFF); (b)[3] = (unsigned char)((unsigned int)(v) >> 24); }
WAV_WRITE_LE32(hdr + 0, 0x46464952U); //"RIFF"
WAV_WRITE_LE32(hdr + 4, 36 + pcm_data_size); //chunk size
WAV_WRITE_LE32(hdr + 8, 0x45564157U); //"WAVE"
WAV_WRITE_LE32(hdr + 12, 0x20746d66U); //subchunk 1 id "fmt "
WAV_WRITE_LE32(hdr + 16, 16); //subchunk 1 size
WAV_WRITE_LE16(hdr + 20, 1); //audio format
WAV_WRITE_LE16(hdr + 22, channels); //num of chan
@schellingb
schellingb / RetroArch.vcxproj
Created September 14, 2020 21:05
RetroArch Visual Studio project file with vulkan and glcore that should build on any Visual Studio version 2012+
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
@schellingb
schellingb / RetroArch.vcxproj.filters
Created September 14, 2020 21:03
RetroArch Visual Studio project filters file for getting the solution folder structure
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="griffin\griffin.c">
<Filter>griffin</Filter>
</ClCompile>
<ClCompile Include="griffin\griffin_cpp.cpp">
<Filter>griffin</Filter>
</ClCompile>
<ClCompile Include="griffin\griffin_glslang.cpp">
@schellingb
schellingb / RetroArch-vulkan-glcore.vcxproj
Created September 14, 2020 20:06
RetroArch Visual Studio project file with vulkan and glcore that should build on any Visual Studio version 2012+
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
@schellingb
schellingb / testra.sh
Last active August 13, 2020 13:59
Clone RetroArch branch to ramdisk and build and test
sudo mkdir /mnt/ramdisk 2>/dev/null
sudo chmod 777 /mnt/ramdisk 2>/dev/null
sudo umount /mnt/ramdisk 2>/dev/null
sudo mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk
cd /mnt/ramdisk
git clone --single-branch --branch some_branch_to_check --depth 1 https://github.com/schellingb/RetroArch.git
#git clone --single-branch --branch master --depth 1 https://github.com/libretro/RetroArch.git
cd RetroArch
rm -rf .git
./configure && make -j4 DEBUG=1 && ./retroarch