Skip to content

Commit

Permalink
Merge pull request #8 from cdf/Monterey-fix
Browse files Browse the repository at this point in the history
Monterey fix
  • Loading branch information
cdf committed Oct 20, 2021
2 parents 3a8cde2 + f0aea42 commit 2f81eea
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
NightShiftEnabler Changelog
===========================
#### v1.1.1
- Fix Monterey compatibility

#### v1.1.0
- Rewrite to use basic Lilu userspace patching APIs for Big Sur compatibility

Expand Down
35 changes: 14 additions & 21 deletions NightShiftEnabler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
0F848D9A23FC6A7E00FEC38C /* kern_nse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F848D9823FC6A7E00FEC38C /* kern_nse.cpp */; };
0F848D9B23FC6A7E00FEC38C /* kern_nse.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0F848D9923FC6A7E00FEC38C /* kern_nse.hpp */; };
1C748C2D1C21952C0024EED2 /* kern_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C748C2C1C21952C0024EED2 /* kern_start.cpp */; };
CE405EC91E49DD9700AA0B3D /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE405EC71E49DD7100AA0B3D /* libkmod.a */; };
CE405ED91E4A080700AA0B3D /* plugin_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE405ED81E4A080700AA0B3D /* plugin_start.cpp */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -48,24 +47,12 @@
CE405EC31E49DD7100AA0B3D /* kern_user.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_user.hpp; sourceTree = "<group>"; };
CE405EC41E49DD7100AA0B3D /* kern_util.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_util.hpp; sourceTree = "<group>"; };
CE405EC61E49DD7100AA0B3D /* LegacyIOService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LegacyIOService.h; sourceTree = "<group>"; };
CE405EC71E49DD7100AA0B3D /* libkmod.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = ../Lilu/MacKernelSDK/Library/x86_64/libkmod.a; sourceTree = "<group>"; };
CE405ECF1E49EC9100AA0B3D /* kern_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_config.hpp; sourceTree = "<group>"; };
CE405ED21E49F9FC00AA0B3D /* kern_api.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_api.hpp; sourceTree = "<group>"; };
CE405ED81E4A080700AA0B3D /* plugin_start.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_start.cpp; sourceTree = "<group>"; };
CE405EDA1E4A080F00AA0B3D /* plugin_start.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = plugin_start.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
1C748C231C21952C0024EED2 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CE405EC91E49DD9700AA0B3D /* libkmod.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0F2DBBCA243CF1DE0017A37C /* Docs */ = {
isa = PBXGroup;
Expand All @@ -77,13 +64,21 @@
name = Docs;
sourceTree = "<group>";
};
0FDD21652718E61B0081A2E7 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
1C748C1D1C21952C0024EED2 = {
isa = PBXGroup;
children = (
0F2DBBCA243CF1DE0017A37C /* Docs */,
CE405EC81E49DD7B00AA0B3D /* SDK */,
1C748C291C21952C0024EED2 /* NightShiftEnabler */,
1C748C281C21952C0024EED2 /* Products */,
0FDD21652718E61B0081A2E7 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -130,7 +125,6 @@
isa = PBXGroup;
children = (
CE405EC61E49DD7100AA0B3D /* LegacyIOService.h */,
CE405EC71E49DD7100AA0B3D /* libkmod.a */,
CE405ED81E4A080700AA0B3D /* plugin_start.cpp */,
);
name = Library;
Expand Down Expand Up @@ -165,7 +159,6 @@
buildConfigurationList = 1C748C311C21952C0024EED2 /* Build configuration list for PBXNativeTarget "NightShiftEnabler" */;
buildPhases = (
1C748C221C21952C0024EED2 /* Sources */,
1C748C231C21952C0024EED2 /* Frameworks */,
1C748C241C21952C0024EED2 /* Headers */,
1C748C251C21952C0024EED2 /* Resources */,
1C642F521C8F157A006B4C51 /* CopyFiles */,
Expand Down Expand Up @@ -360,7 +353,7 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1.1.0;
CURRENT_PROJECT_VERSION = 1.1.1;
DEPLOYMENT_POSTPROCESSING = YES;
DEVELOPMENT_TEAM = "";
GCC_ENABLE_FLOATING_POINT_LIBRARY_CALLS = NO;
Expand All @@ -380,11 +373,11 @@
"$(PROJECT_DIR)/MacKernelSDK/Library/x86_64",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MODULE_NAME = com.cdf.NightShiftEnabler;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1.0;
MODULE_VERSION = 1.1.1;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -413,7 +406,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1.1.0;
CURRENT_PROJECT_VERSION = 1.1.1;
DEAD_CODE_STRIPPING = YES;
DEPLOYMENT_POSTPROCESSING = YES;
DEVELOPMENT_TEAM = "";
Expand All @@ -434,11 +427,11 @@
);
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MODULE_NAME = com.cdf.NightShiftEnabler;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1.0;
MODULE_VERSION = 1.1.1;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down
6 changes: 3 additions & 3 deletions NightShiftEnabler/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>$(MODULE_VERSION)</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(MODULE_VERSION)</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>IOKitPersonalities</key>
<dict>
<key>com.cdf.NightShiftEnabler</key>
Expand Down
9 changes: 2 additions & 7 deletions NightShiftEnabler/kern_nse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ void NSE::init() {
if (getKernelVersion() == KernelVersion::Sierra && getKernelMinorVersion() < 4)
return;

sharedCachePath = UserPatcher::getSharedCachePath();

DBGLOG("nse", "chosen shared cache path is %s", sharedCachePath);

lilu.onPatcherLoadForce([](void *user, KernelPatcher &patcher) {
static_cast<NSE *>(user)->processKernel(patcher);
}, this);
}

void NSE::PatchModelMinVersionBLR(const void *data, size_t size, const char (&path)[PATH_MAX]) {
if (UNLIKELY(strcmp(path, "/System/Library/PrivateFrameworks/CoreBrightness.framework/Versions/A/CoreBrightness") == 0) ||
UNLIKELY(strcmp(path, callbackNSE->sharedCachePath) == 0)) {
if (UserPatcher::matchSharedCachePath(path)) {

if (getKernelVersion() >= KernelVersion::HighSierra && getKernelMinorVersion() >= 2) {
if ((getKernelVersion() == KernelVersion::HighSierra && getKernelMinorVersion() >= 2) || getKernelVersion() >= KernelVersion::Mojave) {
static const uint8_t find[28] = {
0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00
Expand Down
2 changes: 1 addition & 1 deletion NightShiftEnabler/kern_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PluginConfiguration ADDPR(config) {
bootargBeta,
arrsize(bootargBeta),
KernelVersion::Sierra,
KernelVersion::BigSur,
KernelVersion::Monterey,
[]() {
nse.init();
}
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ NightShiftEnabler is a simple successor to a now apparently unmaintained [unlock

#### Implementation

The current version uses a [patch](https://pikeralpha.wordpress.com/2017/01/30/4398/) developed by Pike R. Alpha and is based on the "unfair" component of [WhateverGreen](https://github.com/acidanthera/WhateverGreen).
The current version uses a [patch](https://pikeralpha.wordpress.com/2017/01/30/4398/) developed by Pike R. Alpha and is based on the "unfair" component of [WhateverGreen](https://github.com/acidanthera/WhateverGreen), which uses a patching strategy originally developed for [Polaris22Fixup](https://github.com/osy/Polaris22Fixup).

#### Configuration

- `-nsedbg` enables debug printing (available in DEBUG binaries)
- `-nseoff` disables the plugin
- `-nsebeta` enables the plugin on macOS versions newer than Big Sur
- `-nsebeta` enables the plugin on macOS versions newer than Monterey

#### Credits

- [Apple](https://www.apple.com) for macOS
- [vit9696](https://github.com/vit9696) for [Lilu](https://github.com/vit9696/Lilu) and [WhateverGreen](https://github.com/acidanthera/WhateverGreen)
- [Pike R. Alpha](https://github.com/Piker-Alpha) for the Night Shift [patch](https://pikeralpha.wordpress.com/2017/01/30/4398/)
- [osy](https://github.com/osy) for [Polaris22Fixup](https://github.com/osy/Polaris22Fixup)

0 comments on commit 2f81eea

Please sign in to comment.