Skip to content

Commit

Permalink
Overlay: add INI settings, make clipboard button copy nodes as INI
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Dec 8, 2024
1 parent 0b255f4 commit 6b6b224
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
7 changes: 7 additions & 0 deletions OutRun2006Tweaks.ini
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ RandomHighwayAnimSets = false
# (Tweaks will try to port forward for you using UPnP, but you may need to forward ports 41455 / 41456 / 41457 in order to host games)
DemonwareServerOverride = clarissa.port0.org

[Overlay]
# Enables OR2006Tweaks overlay, currently only used for debug tools
Enabled = false

# Font scale to use for overlay
FontScale = 1.5

[Bugfixes]
# Fixes looping clop sound effect remaining active through the session.
FixPegasusClopping = true
Expand Down
6 changes: 6 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ namespace Settings
spdlog::info(" - RandomHighwayAnimSets: {}", RandomHighwayAnimSets);
spdlog::info(" - DemonwareServerOverride: {}", DemonwareServerOverride);

spdlog::info(" - OverlayEnabled: {}", OverlayEnabled);
spdlog::info(" - OverlayFontScale: {}", OverlayFontScale);

spdlog::info(" - FixPegasusClopping: {}", FixPegasusClopping);
spdlog::info(" - FixRightSideBunkiAnimations: {}", FixRightSideBunkiAnimations);
spdlog::info(" - FixC2CRankings: {}", FixC2CRankings);
Expand Down Expand Up @@ -249,6 +252,9 @@ namespace Settings
RandomHighwayAnimSets = ini.Get("Misc", "RandomHighwayAnimSets", std::move(RandomHighwayAnimSets));
DemonwareServerOverride = ini.Get("Misc", "DemonwareServerOverride", std::move(DemonwareServerOverride));

OverlayEnabled = ini.Get("Overlay", "Enabled", std::move(OverlayEnabled));
OverlayFontScale = ini.Get("Overlay", "FontScale", std::move(OverlayFontScale));

FixPegasusClopping = ini.Get("Bugfixes", "FixPegasusClopping", std::move(FixPegasusClopping));
FixRightSideBunkiAnimations = ini.Get("Bugfixes", "FixRightSideBunkiAnimations", std::move(FixRightSideBunkiAnimations));
FixC2CRankings = ini.Get("Bugfixes", "FixC2CRankings", std::move(FixC2CRankings));
Expand Down
72 changes: 53 additions & 19 deletions src/hooks_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ std::array<std::bitset<16384>, 256> ObjectExclusions;
int ExclusionsStageNum = 0; // stageid the exclusions are setup for, if stageid doesn't match current exclusions will be cleared
int NumObjects = 0;

bool DrawDistanceIncreaseEnabled = false;

void Overlay_DrawDistOverlay()
{
uint32_t cur_stage_num = Game::GetStageUniqueNum(Game::GetNowStageNum(8));
Expand All @@ -30,29 +32,34 @@ void Overlay_DrawDistOverlay()

static ImGuiTableFlags table_flags = ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_HighlightHoveredColumn;

ImGui::Text("How to use:");
ImGui::Text("- When you see an ugly LOD object, pause the game with ESC, and press F11 to bring up this window");
ImGui::Text("- Reduce the Draw Distance below to the lowest value which still shows the LOD object for you");
ImGui::Text("- Once you find the draw-distance that shows the object, click each node checkbox until you find the node responsible");
ImGui::Text("- After finding the node, you can hover over the checkbox to get the IDs for it");
ImGui::Text("Usage:");
ImGui::Text("- When an ugly LOD object appears, pause the game with ESC and press F11 to bring up this window");
ImGui::Text("- Reduce the Draw Distance below to the lowest value which still has the LOD object appearing");
ImGui::Text("- Once you find the draw-distance that shows the object, click each node checkbox to disable nodes");
ImGui::Text("- After you find the node responsible, you can use \"Copy to clipboard\" below to copy the IDs of them, or hover over the node");
ImGui::Text("- Post the IDs for LODs you find in the \"DrawDistanceIncrease issue reports\" github thread and we can add exclusions for them!");
ImGui::NewLine();

if (!DrawDistanceIncreaseEnabled)
{
ImGui::Text("Error: DrawDistanceIncrease must be enabled in INI before launching.");
ImGui::End();
return;
}

ImGui::SliderInt("Draw Distance", &Settings::DrawDistanceIncrease, 0, 1024);
if (ImGui::Button("<<<"))
Settings::DrawDistanceIncrease--;
ImGui::SameLine();
if (ImGui::Button(">>>"))
Settings::DrawDistanceIncrease++;

ImGui::Text("cur_stage_num = 0x%X", cur_stage_num);

if (num_columns > 0)
{
ImGui::Text("Nodes at DrawDistance %d:", Settings::DrawDistanceIncrease);

num_columns += 1;
if (ImGui::BeginTable("table_angled_headers", num_columns, table_flags))
if (ImGui::BeginTable("NodeTable", num_columns, table_flags))
{
ImGui::TableSetupColumn("Object ID", ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_NoReorder);
for (int n = 1; n < num_columns; n++)
Expand All @@ -63,8 +70,25 @@ void Overlay_DrawDistOverlay()
ImGui::PushID(objectIdx);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
//ImGui::AlignTextToFramePadding();
ImGui::Text("Object %d", objectIdx);
if (ImGui::Button(std::format("Object {}", objectIdx).c_str()))
{
bool areAllExcluded = true;
for (int i = 0; i < ObjectNodes[objectIdx].size(); i++)
{
auto nodeId = ObjectNodes[objectIdx][i];
if (!ObjectExclusions[objectIdx][nodeId])
{
areAllExcluded = false;
break;
}
}

for (int i = 0; i < ObjectNodes[objectIdx].size(); i++)
{
auto nodeId = ObjectNodes[objectIdx][i];
ObjectExclusions[objectIdx][nodeId] = areAllExcluded ? false : true;
}
}

for (int i = 0; i < ObjectNodes[objectIdx].size(); i++)
if (ImGui::TableSetColumnIndex(i + 1))
Expand All @@ -77,7 +101,7 @@ void Overlay_DrawDistOverlay()
if (ImGui::Checkbox("", &excluded))
ObjectExclusions[objectIdx][nodeId] = excluded;

ImGui::SetItemTooltip("StageNum 0x%X, object 0x%X node 0x%X", cur_stage_num, objectIdx, nodeId);
ImGui::SetItemTooltip("Stage %d, object 0x%X, node 0x%X", cur_stage_num, objectIdx, nodeId);

ImGui::PopID();
}
Expand All @@ -95,22 +119,30 @@ void Overlay_DrawDistOverlay()
}
if (ImGui::Button("Copy exclusions to clipboard"))
{
std::string clipboard = "";
std::string clipboard = "";//
for (int objId = 0; objId < ObjectExclusions.size(); objId++)
{
std::string objLine = "";
for (int i = 0; i < ObjectExclusions[objId].size(); i++)
{
if (ObjectExclusions[objId][i])
{
clipboard += std::format("StageNum 0x{:X}, object 0x{:X} node 0x{:X}\r\n", cur_stage_num, objId, i);
objLine += std::format(", 0x{:X}", i);
}
}

if (objLine.length() > 2)
{
clipboard += std::format("\n0x{:X} = {}", objId, objLine.substr(2));
}
}
if (!clipboard.empty())
clipboard = std::format("[Stage {}]{}", cur_stage_num, clipboard);

HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, clipboard.length());
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, clipboard.length() + 1);
if (hMem)
{
memcpy(GlobalLock(hMem), clipboard.c_str(), clipboard.length());
memcpy(GlobalLock(hMem), clipboard.c_str(), clipboard.length() + 1);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
Expand Down Expand Up @@ -178,7 +210,7 @@ class DrawDistanceIncrease : public Hook
uint32_t* v11 = (uint32_t*)(v6 + 8);

uint32_t cur_stage_num = Game::GetStageUniqueNum(Game::GetNowStageNum(8));
if (ExclusionsStageNum != cur_stage_num)
if (Settings::OverlayEnabled && ExclusionsStageNum != cur_stage_num)
{
for (int i = 0; i < ObjectExclusions.size(); i++)
ObjectExclusions[i].reset();
Expand All @@ -205,7 +237,7 @@ class DrawDistanceIncrease : public Hook
}

// DEBUG: clear lastadds for this objectnum here
if (csOffset == Settings::DrawDistanceIncrease)
if (Settings::OverlayEnabled && csOffset == Settings::DrawDistanceIncrease)
{
ObjectNodes[ObjectNum].clear();
}
Expand All @@ -223,14 +255,14 @@ class DrawDistanceIncrease : public Hook

// DEBUG: check exclusions here before adding to *cur
// (if we're at csOffset = 0, exclusions are ignored, since that is what vanilla game would display)
if (!ObjectExclusions[ObjectNum][*sectionCollList] || csOffset == 0)
if (!Settings::OverlayEnabled || !ObjectExclusions[ObjectNum][*sectionCollList] || csOffset == 0)
{
*cur = *sectionCollList;
cur++;
}

// DEBUG: add *sectionCollList to lastadds list here
if (csOffset == Settings::DrawDistanceIncrease)
if (Settings::OverlayEnabled && csOffset == Settings::DrawDistanceIncrease)
ObjectNodes[ObjectNum].push_back(*sectionCollList);

num++;
Expand Down Expand Up @@ -269,6 +301,8 @@ class DrawDistanceIncrease : public Hook
for (int i = 0; i < ObjectNodes.size(); i++)
ObjectNodes[i].reserve(4096);

DrawDistanceIncreaseEnabled = true;

return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/hooks_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool show_demo_window = true;
bool f11_prev_state = false; // previously seen F11 state

bool overlay_visible = false; // user wants overlay to show?
bool overlay_active = false; // overlay is active?
bool overlay_showing = false;

bool Overlay_Update()
{
Expand Down Expand Up @@ -56,8 +56,8 @@ bool Overlay_Update()

void Overlay_Render()
{
overlay_active = Overlay_Update();
if (overlay_active)
overlay_showing = Overlay_Update();
if (overlay_showing)
{
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
Expand All @@ -80,6 +80,7 @@ class ImguiOverlay : public Hook
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.FontGlobalScale = Settings::OverlayFontScale;

// Setup Dear ImGui style
ImGui::StyleColorsDark();
Expand All @@ -89,7 +90,6 @@ class ImguiOverlay : public Hook
ImGui_ImplWin32_Init(Game::GameHwnd());
ImGui_ImplDX9_Init(Game::D3DDevice());

spdlog::info("Imgui inited!");
overlayInited = true;
}

Expand All @@ -108,7 +108,7 @@ class ImguiOverlay : public Hook

bool validate() override
{
return true;
return Settings::OverlayEnabled;
}

bool apply() override
Expand All @@ -135,7 +135,7 @@ class WndprocHook : public Hook
inline static SafetyHookInline dest_orig = {};
static LRESULT __stdcall destination(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (overlay_active)
if (overlay_showing)
{
if (ImGui_ImplWin32_WndProcHandler(hwnd, msg, wParam, lParam))
return 1;
Expand Down
3 changes: 3 additions & 0 deletions src/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ namespace Settings
inline bool RandomHighwayAnimSets = false;
inline std::string DemonwareServerOverride = "clarissa.port0.org";

inline bool OverlayEnabled = false;
inline float OverlayFontScale = 1.5f;

inline bool FixPegasusClopping = true;
inline bool FixRightSideBunkiAnimations = true;
inline bool FixC2CRankings = true;
Expand Down

0 comments on commit 6b6b224

Please sign in to comment.