Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Add new Draw Distance mod among other things (#279)
Browse files Browse the repository at this point in the history
* Update Crender Class

Used regenny to remove znear and zfar and added new offset for draw distance.

i dont know why regenny does the private public thing now. guess its a feature

* ReAdd Znear and Zfar

Im not 100% sure if these vaules are correct but its the best i could find
setting Zfar to 0 seems to break rending in a way that would make me think its Zfar

if this is incorrect and someone is able to fix them that would be great
Kcamera does use them but luckly currently nothing uses that class so its not overly important

* Add DrawDistance Mod

* Fix unlimited Zoom mod

* Reenable character Window Title mod

all prerequirements for this mod to work again where already updated
  • Loading branch information
riskdoe authored Apr 15, 2023
1 parent 6d21040 commit 27252ca
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ list(APPEND Kanan_SOURCES
"Kanan/DInputHook.cpp"
"Kanan/DisableNagle.cpp"
"Kanan/DontMoveToSquadChat.cpp"
"Kanan/DrawDistance.cpp"
"Kanan/EnableMultiClient.cpp"
"Kanan/EntityViewer.cpp"
"Kanan/EquipmentOverride.cpp"
Expand Down Expand Up @@ -182,6 +183,7 @@ list(APPEND Kanan_SOURCES
"Kanan/DInputHook.hpp"
"Kanan/DisableNagle.hpp"
"Kanan/DontMoveToSquadChat.hpp"
"Kanan/DrawDistance.hpp"
"Kanan/EnableMultiClient.hpp"
"Kanan/EntityViewer.hpp"
"Kanan/EquipmentOverride.hpp"
Expand Down
58 changes: 58 additions & 0 deletions Kanan/DrawDistance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <imgui.h>

#include "Kanan.hpp"
#include "DrawDistance.hpp"

namespace kanan {

DrawDistance::DrawDistance()
: m_distance { 25000 }
, m_isEnabled { false }
{ }

void DrawDistance::onFrame() {
auto game = g_kanan->getGame();

//get render, if no render return
auto renderer = game->getRenderer();
if (renderer == nullptr) {
return;
}
//get camera, if no camera return
auto camera = renderer->camera;
if (camera == nullptr) {
return;
}
//get cameraState, if no cameraState return
auto cameraState = camera->state;
if (cameraState == nullptr) {
return;
}
//if enabled set to wanted draw distance
if (m_isEnabled) {
cameraState->drawDistance = m_distance;
}
}

void DrawDistance::onUI() {
if (ImGui::CollapsingHeader("Draw Distance")) {
ImGui::Checkbox("Enable Draw Distance", &m_isEnabled);
ImGui::Text("This is likely to cause lag if too high");
ImGui::SliderFloat("Distance", &m_distance, 0.0f, 500000.0f, "%.0f");
if (ImGui::Button("Reset")) {
m_distance = 25000.0f;
}
}
}

void DrawDistance::onConfigLoad(const Config& cfg) {
m_distance = cfg.get<float>("DrawDistance.Vaule").value_or(25000.0f);
m_isEnabled = cfg.get<bool>("DrawDistance.Enabled").value_or(m_isEnabled);
}

void DrawDistance::onConfigSave(Config& cfg) {
cfg.set<float>("DrawDistance.Vaule", m_distance);
cfg.set<bool>("DrawDistance.Enabled", m_isEnabled);
}

}
21 changes: 21 additions & 0 deletions Kanan/DrawDistance.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Mod.hpp"

namespace kanan {
class DrawDistance : public Mod {
public:
DrawDistance();

void onFrame() override;

void onUI() override;

void onConfigLoad(const Config& cfg) override;
void onConfigSave(Config& cfg) override;

private:
float m_distance;
bool m_isEnabled;
};
} // namespace kanan
20 changes: 10 additions & 10 deletions Kanan/Mabinogi/CRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ class CRenderer {
public:
class CCameraState {
public:
char pad_0[0x10];
private: char pad_0[0x10]; public:
Vector3 target; // 0x10
char pad_1c[0x4];
private: char pad_1c[0x4]; public:
Vector3 position; // 0x20
char pad_2c[0x8];
private: char pad_2c[0x8]; public:
Vector4 forward; // 0x34
float drawDistance; // 0x44
float zNear; // 0x48
float zFar; // 0x4c
float zNear; // 0x44
float zFar; // 0x48
float drawDistance; // 0x4c
float fov; // 0x50
float screenWidth; // 0x54
float screenHeight; // 0x58
char pad_5c[0x1c];
private: char pad_5c[0x1c]; public:
float aspectRatio; // 0x78
char pad_7c[0xd0];
private: char pad_7c[0xd0]; public:
Matrix4x4 transformMatrix; // 0x14c
}; // Size: 0x18c

CCameraState* state; // 0x0
}; // Size: 0x8

char pad_0[0x38];
private: char pad_0[0x38]; public:
CCamera* camera; // 0x38
char pad_40[0xc0];
private: char pad_40[0xc0]; public:
}; // Size: 0x100
#pragma pack(pop)
5 changes: 4 additions & 1 deletion Kanan/Mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Currtarget.hpp"
#include "CookingMod.hpp"
#include "CharacterWindowTitle.hpp"
#include "DrawDistance.hpp"

#include "Log.hpp"

Expand Down Expand Up @@ -126,12 +127,14 @@ namespace kanan {
addMod(make_unique<CookingMod>());
addMod(make_unique<EquipmentOverride>());
addMod(make_unique<FieldOfView>());
addMod(make_unique<DrawDistance>());
addMod(make_unique<FreezeTimeOfDay>());
/* addMod(make_unique<StatusUI>());
addMod(make_unique<AutoChangeChannels>());
addMod(make_unique<ChangeChannelHotkey>());*/
addMod(make_unique<Currtarget>());
//addMod(make_unique<CharacterWindowTitle>());
addMod(make_unique<CharacterWindowTitle>());


log("[Mods] Finished loading mods.");
}
Expand Down
4 changes: 2 additions & 2 deletions Kanan/Patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"category": "Graphics",
"patches": [
{
"pattern": "F3 0F 10 46 14 F3 0F 5D C1",
"patch": "90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90"
"pattern": "f3 0f 10 73 1c f3 0f 5d c1",
"patch": "90 90 90 90 90"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions mabinogi.genny
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ class CRenderer 0x100 {
Vector3 target @ 0x10
Vector3 position +4
Vector4 forward +8
float znear
float zfar
float drawDistance
float zNear
float zFar
float fov
float screenWidth
float screenHeight
Expand Down

0 comments on commit 27252ca

Please sign in to comment.