Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

libstrangle

Frame rate limiter for Linux.

ADDENDUM

All credit goes to milaq for creating this.
It is however, extremely outdated, and I needed it for my games.

The error that appeared was this:
symbol lookup error: /usr/local/lib/libstrangle/lib64/libstrangle.so: undefined symbol: __libc_dlsym

This error appeared without the STRANGLE_VKONLY option, on OpenGL games.

I managed to track down the issue to this file:

[mattfor@ZenDen /usr/local/src/libstrangle]$ rg __libc_dlsym
src/opengl/real_dlsym.c
27:extern void* __libc_dlsym( void* handle, const char* name );
34: the_real_dlsym = __libc_dlsym( libdl, "dlsym" );
#define_GNU_SOURCE
#include"real_dlsym.h"
#include<stdlib.h>
#include<dlfcn.h>externvoid* __libc_dlsym( void* handle, constchar* name );
void* real_dlsym( void* handle, constchar* name )
{
staticvoid *(*the_real_dlsym)( void*, constchar* );
if ( the_real_dlsym == NULL ) {
void* libdl = dlopen( "libdl.so", RTLD_NOW | RTLD_LOCAL );
the_real_dlsym = __libc_dlsym( libdl, "dlsym" );
}
returnthe_real_dlsym( handle, name );
}

And I overhauled the code to:

#define_GNU_SOURCE
#include"real_dlsym.h"
#include<stdlib.h>
#include<dlfcn.h>void* real_dlsym(void* handle, constchar* name)
{
staticvoid *(*the_real_dlsym)(void*, constchar*);
if (the_real_dlsym == NULL) {
void* libdl = dlopen("libdl.so.2", RTLD_NOW | RTLD_LOCAL);
if (!libdl)
{
returnNULL;
}
the_real_dlsym = (void* (*)(void*, constchar*)) dlvsym(libdl, "dlsym", "GLIBC_2.2.5");
if (!the_real_dlsym) {
the_real_dlsym = (void* (*)(void*, constchar*)) dlsym(RTLD_NEXT, "dlsym");
}
}
return the_real_dlsym ? the_real_dlsym(handle, name) : NULL;
}

Now everything works!

Building

Typically you'll use these commands to build the program

make
sudo make install

Debian, Ubuntu and derivates may need some or all of these packages:

gcc-multilib
g++-multilib
libx11-dev
mesa-common-dev

OpenSUSE needs these packages:

glibc-devel-32bit
gcc
gcc-32bit

Usage

Cap the FPS (frames per second) of a chosen game by using the included script strangle Example:

strangle 60 /path/to/game

Run strangle --help for full usage info

Steam

You can use this with Steam by right-clicking on a game in your library and selecting Properties and then SET LAUNCH OPTIONS... under the General tab. In the input box type: strangle <somenumber> %command%

Laptops

On laptops you can specify an alternative framerate cap when running on battery power with the STRANGLE_FPS_BATTERY env var or by using the <fps>:<battery_fps> syntax with the strangle script. Example:

strangle 60:30 /path/to/game

Vsync

Vertical sync can be controlled by setting the STRANGLE_VSYNC environment variable or with the -v or --vsync command line options. Beware that OpenGL and Vulkan work differently on the same values:

OpenGL

  • -1 - Adaptive sync (unconfirmed if this actually works)
  • 0 - Force off
  • 1 - Force on
  • n - Sync to refresh rate / n.

Vulkan

  • 0 - Force off
  • 1 - Mailbox mode. Vsync with uncapped framerate.
  • 2 - Traditional vsync with framerate capped to refresh rate.
  • 3 - Adaptive vsync with tearing at low framerates.

Examples:

strangle -v 1 /path/to/game
STRANGLE_VSYNC=2 strangle /path/to/game
STRANGLE_VSYNC=1 strangle 40 /path/to/game

Options

Run strangle --help to see command line options.
Strangle can also be controlled with the following environment variables:

ENV VARValueExplanation
STRANGLE_FPS<decimal>Maximum framerate. 0 to disable. Any positive value to enable
STRANGLE_FPS_BATTERY<decimal>Maximum framerate when running on battery power
STRANGLE_VSYNC<int>See the above section on v-sync
STRANGLE_GLFINISH0 or 1Forces glFinish() to run after every frame (OpenGL only)
STRANGLE_PICMIP-16 to 16Mip-map LoD bias. Negative values will increase texture sharpness (and aliasing). Positive values will increase texture blurriness
STRANGLE_AF1 to 16Anisotropic filtering level. Improves sharpness of textures viewed at an angle (Vulkan only)
STRANGLE_TRILINEAR0 or 1Force trilinear filtering (Vulkan only)
STRANGLE_RETRO0 or 1Disables linear texture filtering. Makes textures look blocky. (Vulkan only)
STRANGLE_NODLSYM0 or 1Disables the hooking of dlsym
STRANGLE_VKONLY0 or 1Stops strangle's OpenGL libs from loading
ENABLE_VK_LAYER_TORKEL104_libstrangle0 or 1Enables the implicit Vulkan layer
DISABLE_VK_LAYER_TORKEL104_libstrangle0 or 1Disables the implicit Vulkan layer

Experimental stuff

Mip map lod bias examplevkQuake with STRANGLE_PICMIP=1337

You can adjust the mipmap lod bias in both opengl and vulkan with the environment variable STRANGLE_PICMIP. A higher value means blurrier textures. A negative value could make textures crisper.

Notice

Might crash if used together with other libs that hijack dlsym, such as Steam Overlay. It seems to work with Steam Overlay when placed at the end of LD_PRELOAD for some reason.

About

My fork of libstrangle with a dlsym fix.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages