kanan icon indicating copy to clipboard operation
kanan copied to clipboard

[Request] Disable whatever prevents monitors from sleeping

Open Aahzmandius opened this issue 8 years ago • 3 comments

Anyone know where to start with this mod? If I remember right it was originally by The Proffessor and is still a working part of Abyss.

Aahzmandius avatar Oct 02 '16 03:10 Aahzmandius

I believe this is part of windows and the bios, and not part of the game itself but I could be wrong. Typically sleep and power save settings will not allow sleep when a full screen type application such as video or flash/java is running unless told otherwise for power saving purposes. Since mabi uses ftp and connects through your browser settings for web through window's explorer/edge you may find the options to this in the media sleep settings in advanced window under power and sleep options, there is a link at the top of the window that says something along the lines of "change settings that are currently unavailable". Select sharing multimedia and set it from prevent idle sleep to allow sleep. Some devices can also cause this to happen. Let me know if this works as I am not home to test it. This will however apply to all media including web video. Sometimes hard drive activity can cause the computer to not sleep as well. When the computer goes to sleep it stores temporary information about things currently running in memory, which is lost on power loss. However if you have hybrid sleep enabled it will also save his information to the hard drive so it can be easily restored after loss of power.

Kyralis avatar Oct 13 '16 13:10 Kyralis

Well the win32 API has a lot of power management functions (see: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373163(v=vs.85).aspx ). Mabi probably calls one of these to prevent the monitors from going to sleep, or some other win32 API. I'll take a look soon.

cursey avatar Oct 13 '16 15:10 cursey

Yup, it's SetThreadExecutionState().

Using powercfg -requests in an admin command prompt will allow you to see the current system requests that can prevent monitor/computer from sleeping or going into standby. Mabi will normally show under DISPLAY and SYSTEM, preventing monitor and system from sleeping.

var setThreadExecutionState = native('Kernel32.dll', 'SetThreadExecutionState', 'uint', ['uint'], 'stdcall');

var socketCall = scan('E8 ? ? ? ? 8B F0 83 C4 0C 83 FE FF');
var socketOffset = Memory.readS32(socketCall.add(1));
var socketAddress = socketCall.add(5).toInt32() + socketOffset;

var listener = Interceptor.attach(ptr(socketAddress), {
    onLeave(retval) {
        dmsg("SetThreadExecuteState: " + setThreadExecutionState(0x80000000));
        listener.detach();
    }
});

This works correctly and allows the monitor to sleep, but is obviously ugly for several reasons. Simply calling dmsg("SetThreadExecuteState: " + setThreadExecutionState(0x80000000)); during coalesce or even as a delayed script wasn't enough to remove mabi's request to keep the monitor on, so for testing I borrowed and attached to same location for DisableNagle.js to run a little after logging in. Unfortunately I'm not good with memory addresses, so will have to wait for someone more experienced to clean this up 😅

Aahzmandius avatar Oct 20 '16 00:10 Aahzmandius