-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
171 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "ZoomManager.hpp" | ||
|
||
static ZoomManager* mInstance; | ||
ZoomManager::ZoomManager(AmethystContext* context, ConfigManager* config) { | ||
mConfig = config; | ||
|
||
context->mHookManager.CreateHook<&BaseOptions::getSensitivity>(ZoomManager::mGetSensitivity, ZoomManager::sensitivityHook); | ||
context->mHookManager.CreateHook<&LevelRendererPlayer::getFov>(ZoomManager::mGetFov, ZoomManager::fovHook); | ||
|
||
mInstance = this; | ||
} | ||
|
||
ZoomManager* ZoomManager::getInstance() { | ||
return mInstance; | ||
} | ||
|
||
void ZoomManager::setEnabled(bool value) { | ||
mEnabledStart = std::chrono::system_clock::now(); | ||
mEnabled = value; | ||
} | ||
|
||
float ZoomManager::fovHook(LevelRendererPlayer* self, float a, bool a2) { | ||
static ZoomManager* instance = ZoomManager::getInstance(); | ||
|
||
static std::string zoomType = instance->mConfig->getZoomType(); | ||
static float targetFov = instance->mConfig->getTargetFov(); | ||
static float duration = instance->mConfig->getDuration(); | ||
|
||
float currentFov = instance->mGetFov.thiscall<float>(self, a, a2); | ||
if(currentFov == 70.0f) return currentFov; | ||
|
||
if(zoomType == "gradual") { | ||
auto currentTime = std::chrono::system_clock::now(); | ||
std::chrono::duration<float> elapsedTime = currentTime - instance->mEnabledStart; | ||
|
||
float time = std::clamp(elapsedTime.count(), 0.0f, duration); | ||
float rate = (currentFov - targetFov) / duration; | ||
|
||
if(instance->mEnabled) | ||
return (time * -rate) + currentFov; | ||
else return time * rate; | ||
} else if(zoomType == "instant" && instance->mEnabled) return targetFov; | ||
|
||
return currentFov; | ||
} | ||
|
||
float ZoomManager::sensitivityHook(BaseOptions* self, unsigned int inputMode) { | ||
static ZoomManager* instance = ZoomManager::getInstance(); | ||
|
||
static float dampen = (100.0f - instance->mConfig->getSensitivityDampen()) / 100.0f; | ||
|
||
static std::string zoomType = instance->mConfig->getZoomType(); | ||
static float duration = instance->mConfig->getDuration(); | ||
|
||
float currentSensitivity = instance->mGetSensitivity.thiscall<float>(self, inputMode); | ||
float targetSensitivity = currentSensitivity * dampen; | ||
|
||
if(zoomType == "gradual") { | ||
auto currentTime = std::chrono::system_clock::now(); | ||
std::chrono::duration<float> elapsedTime = currentTime - instance->mEnabledStart; | ||
|
||
float time = std::clamp(elapsedTime.count(), 0.0f, duration); | ||
float rate = (currentSensitivity - targetSensitivity) / duration; | ||
|
||
if(instance->mEnabled) | ||
return (time * -rate) + currentSensitivity; | ||
else return time * rate; | ||
} else if(zoomType == "instant" && instance->mEnabled) return targetSensitivity; | ||
|
||
return currentSensitivity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include "minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.hpp" | ||
#include "minecraft/src-client/common/client/options/BaseOptions.hpp" | ||
|
||
#include "amethyst/runtime/AmethystContext.hpp" | ||
#include "amethyst/runtime/HookManager.hpp" | ||
|
||
#include "ConfigManager.hpp" | ||
#include <chrono> | ||
|
||
class ZoomManager { | ||
public: | ||
ZoomManager(AmethystContext*, ConfigManager*); | ||
static ZoomManager* getInstance(); | ||
void setEnabled(bool); | ||
|
||
private: | ||
static float sensitivityHook(BaseOptions*, unsigned int); | ||
static float fovHook(LevelRendererPlayer*, float, bool); | ||
SafetyHookInline mGetSensitivity; | ||
SafetyHookInline mGetFov; | ||
|
||
std::chrono::system_clock::time_point mEnabledStart; | ||
ConfigManager* mConfig; | ||
bool mEnabled; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters