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 / 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 / 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
{
@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 / my default.vcxproj
Last active May 22, 2022 17:32
A short and readable single .vcxproj file that opens and builds in Visual Studio 2012, 2013, 2015, 2017 and 2019 with good default settings.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="DisplayText">
<PropertyGroup Label="UserMacros">
<VisualStudioYear Condition="'$(VisualStudioVersion)' == '11.0' Or '$(PlatformToolsetVersion)' == '110' Or '$(MSBuildToolsVersion)' == '4.0'">2012</VisualStudioYear>
<VisualStudioYear Condition="'$(VisualStudioVersion)' == '12.0' Or '$(PlatformToolsetVersion)' == '120' Or '$(MSBuildToolsVersion)' == '12.0'">2013</VisualStudioYear>
<VisualStudioYear Condition="'$(VisualStudioVersion)' == '14.0' Or '$(PlatformToolsetVersion)' == '140' Or '$(MSBuildToolsVersion)' == '14.0'">2015</VisualStudioYear>
<VisualStudioYear Condition="'$(VisualStudioVersion)' == '15.0' Or '$(PlatformToolsetVersion)' == '141' Or '$(MSBuildToolsVersion)' == '15.0'">2017</VisualStudioYear>
<VisualStudioYear Condition="'$(VisualStudioVersion)' == '16.0' Or '$(PlatformToolsetVersion)' == '142' Or '$(MSBuildTo

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 / RetroArch.vcxproj
Last active September 14, 2020 21:08
Basic RetroArch Visual Studio project file with just minimal features 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
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">