Skip to content

Commit

Permalink
GameUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Apr 29, 2024
1 parent 20c0f3d commit ec823d2
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 58 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28)
# DevTools
project(devtools VERSION 0.1.15
project(devtools VERSION 0.1.16
DESCRIPTION "Sonic Frontiers DevTools"
LANGUAGES CXX)

Expand Down
2 changes: 1 addition & 1 deletion rangers-sdk
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ target_sources(devtools
ui/core-services/GraphicsContextInspector.cpp
ui/core-services/MemoryInspector.cpp
ui/Desktop.cpp
ui/game-modes/GameModeInspector.cpp
ui/game-services/GameServiceInspector.cpp
ui/operation-modes/LevelEditor/LevelEditor.cpp
ui/operation-modes/LevelEditor/ObjectDataInspector.cpp
Expand All @@ -33,6 +34,7 @@ target_sources(devtools
ui/operation-modes/ObjectInspection/ObjectInspection.cpp
ui/operation-modes/ObjectInspection/ObjectInspector.cpp
ui/operation-modes/ObjectInspection/ObjectList.cpp
ui/operation-modes/SurfRideEditor/SurfRideEditor.cpp
ui/operation-modes/OperationMode.cpp
ui/resources/editors/ResEffectEditor.cpp
ui/resources/editors/ResObjectWorldEditor.cpp
Expand Down Expand Up @@ -76,6 +78,7 @@ target_sources(devtools
ui/Desktop.h
ui/fonts/FiraCode.h
ui/fonts/Inter.h
ui/game-modes/GameModeInspector.h
ui/game-services/GameServiceInspector.h
ui/operation-modes/LevelEditor/LevelEditor.h
ui/operation-modes/LevelEditor/ObjectDataInspector.h
Expand All @@ -84,6 +87,7 @@ target_sources(devtools
ui/operation-modes/ObjectInspection/ObjectInspection.h
ui/operation-modes/ObjectInspection/ObjectInspector.h
ui/operation-modes/ObjectInspection/ObjectList.h
ui/operation-modes/SurfRideEditor/SurfRideEditor.h
ui/operation-modes/OperationMode.h
ui/resources/editors/ResEffectEditor.h
ui/resources/editors/ResObjectWorldEditor.h
Expand Down
6 changes: 4 additions & 2 deletions src/ui/Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ void Desktop::HandleMousePicking()
auto cameraMatrix{ camera->viewportData.projMatrix * camera->viewportData.viewMatrix };
auto inverseCameraMatrix{ cameraMatrix.inverse() };
auto* ivp = ImGui::GetMainViewport();
auto topLeft = ImGui::GetMousePos() - ImGui::GetMouseDragDelta();
auto botRight = ImGui::GetMousePos();
auto mouseStart = ImGui::GetMousePos() - ImGui::GetMouseDragDelta();
auto mouseEnd = ImGui::GetMousePos();
auto topLeft = ImVec2{ std::fminf(mouseStart.x, mouseEnd.x), std::fminf(mouseStart.y, mouseEnd.y) };
auto botRight = ImVec2{ std::fmaxf(mouseStart.x, mouseEnd.x), std::fmaxf(mouseStart.y, mouseEnd.y) };

ImGui::SetNextWindowSize(ivp->Size);
ImGui::SetNextWindowPos(ivp->Pos);
Expand Down
5 changes: 4 additions & 1 deletion src/ui/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Desktop.h"
#include "SettingsManager.h"
#include "resources/ResourceBrowser.h"
#include "game-modes/GameModeInspector.h"
#include "game-services/GameServiceInspector.h"
#include "core-services/GameUpdaterInspector.h"
#include "core-services/GraphicsContextInspector.h"
Expand Down Expand Up @@ -52,6 +53,8 @@ void ToolBar::Render() {
new (Desktop::instance->GetAllocator()) CameraManagerInspector(Desktop::instance->GetAllocator());
if (ImGui::MenuItem("Memory"))
new (Desktop::instance->GetAllocator()) MemoryInspector(Desktop::instance->GetAllocator());
if (ImGui::MenuItem("GameMode"))
new (Desktop::instance->GetAllocator()) GameModeInspector(Desktop::instance->GetAllocator());
ImGui::EndMenu();
}

Expand Down Expand Up @@ -94,7 +97,7 @@ void ToolBar::Render() {
ImGui::SetItemTooltip("Pauses (almost) every object layer. (Hotkey: F4)");
ImGui::SameLine();

gameUpdater.flags.m_dummy = static_cast<GameUpdater::Flags>(gameUpdaterFlags);
gameUpdater.flags.m_dummy = gameUpdaterFlags;

if (ImGui::Button("Step frame"))
gameUpdater.flags.set(GameUpdater::Flags::DEBUG_STEP_FRAME);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/common/ReflectionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ void ReflectionEditor::RenderPrimitiveEditor(const char* name, void* obj, const
RenderScalarRflParamEditor<uint32_t, uint32_t>(name, obj, member, ImGuiDataType_U32, 1);
break;
case RflClassMember::TYPE_SINT64:
RenderScalarRflParamEditor<int64_t>(name, obj, member, ImGuiDataType_S64, 1);
RenderScalarRflParamEditor<int64_t, int64_t>(name, obj, member, ImGuiDataType_S64, 1);
break;
case RflClassMember::TYPE_UINT64:
RenderScalarRflParamEditor<uint64_t>(name, obj, member, ImGuiDataType_U64, 1);
RenderScalarRflParamEditor<uint64_t, uint64_t>(name, obj, member, ImGuiDataType_U64, 1);
break;
case RflClassMember::TYPE_FLOAT:
RenderScalarRflParamEditor<float, float>(name, obj, member, ImGuiDataType_Float, 1);
Expand Down
12 changes: 10 additions & 2 deletions src/ui/common/ReflectionEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ class ReflectionEditor {
};
template<> class range_info<int32_t> {
public:
static constexpr const char* name = "RangeSInt32";
static constexpr const char* name = "RangeSint32";
};
template<> class range_info<uint32_t> {
public:
static constexpr const char* name = "RangeUInt32";
static constexpr const char* name = "RangeUint32";
};
template<> class range_info<int64_t> {
public:
static constexpr const char* name = "RangeSint64";
};
template<> class range_info<uint64_t> {
public:
static constexpr const char* name = "RangeUint64";
};
template<> class range_info<float> {
public:
Expand Down
16 changes: 8 additions & 8 deletions src/ui/common/SimpleWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ void InputText(const char* label, hh::needle::intrusive_ptr<hh::needle::CNameIDO
void InputObjectId(const char* label, hh::game::ObjectId* id);
void RsFlagMaskEditor(const char* label, hh::needle::RsFlagMask* mask);

template<typename T>
void CheckboxFlags(const char* label, csl::ut::Bitset<T>* v, T value) {
ImGui::CheckboxFlags(label, reinterpret_cast<std::underlying_type_t<T>*>(&v->m_dummy), static_cast<std::underlying_type_t<T>>(1) << static_cast<std::underlying_type_t<T>>(value));
template<typename T, typename U>
void CheckboxFlags(const char* label, csl::ut::Bitset<T, U>* v, T value) {
ImGui::CheckboxFlags(label, &v->m_dummy, static_cast<U>(1) << static_cast<U>(value));
}

template<typename T>
void CheckboxFlagsLT32(const char* label, csl::ut::Bitset<T>* v, T value) {
int v2 = static_cast<std::underlying_type_t<T>>(v->m_dummy);
ImGui::CheckboxFlags(label, &v2, static_cast<std::underlying_type_t<T>>(1) << static_cast<std::underlying_type_t<T>>(value));
*v = static_cast<T>(static_cast<std::underlying_type_t<T>>(v2));
template<typename T, typename U>
void CheckboxFlagsLT32(const char* label, csl::ut::Bitset<T, U>* v, T value) {
int v2 = v->m_dummy;
ImGui::CheckboxFlags(label, &v2, static_cast<U>(1) << static_cast<U>(value));
*v = static_cast<U>(v2);
}

template<typename T, size_t count>
Expand Down
90 changes: 53 additions & 37 deletions src/ui/core-services/GameUpdaterInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,62 @@ GameUpdaterInspector::GameUpdaterInspector(csl::fnd::IAllocator* allocator) : St
SetTitle("GameUpdater");
}

void GameUpdaterInspector::PreRender()
{
ImGui::SetNextWindowSize(ImVec2(800, 920), ImGuiCond_Once);
}

void GameUpdaterInspector::RenderContents()
{
auto& gameUpdater = hh::game::GameApplication::GetInstance()->GetGameUpdater();
//unsigned int flags = static_cast<unsigned int>(gameUpdater.flags.m_dummy);
//ImGui::CheckboxFlags("Unknown pause", &flags, 1);
//ImGui::CheckboxFlags("Full pause", &flags, 2);
//ImGui::CheckboxFlags("flag 2", &flags, 4);
//ImGui::CheckboxFlags("flag 3", &flags, 8);
//ImGui::CheckboxFlags("Step single frame", &flags, 16);
//ImGui::CheckboxFlags("Object pause", &flags, 32);
//ImGui::CheckboxFlags("flag 6", &flags, 64);
//ImGui::CheckboxFlags("flag 7", &flags, 128);
//gameUpdater.flags.m_dummy = static_cast<hh::game::GameUpdater::Flags>(flags);

//ImGui::Text("unk7.unk1.unk1: %x", gameUpdater.unk7.unk1.unk1);
//ImGui::Text("unk7.unk1.unk2: %x", gameUpdater.unk7.unk1.unk2);
//ImGui::Text("unk7.unk2.unk1: %x", gameUpdater.unk7.unk2.unk1);
//ImGui::Text("unk7.unk2.unk2: %x", gameUpdater.unk7.unk2.unk2);

ImGui::Text("layers active during normal operation: %x", gameUpdater.layersActiveDuringNormalOperation);
ImGui::Text("layers active during ingame pause: %x", gameUpdater.layersActiveDuringIngamePause);
ImGui::Text("layers active during debug pause: %x", gameUpdater.layersActiveDuringDebugPause);
ImGui::Text("layers active during object pause: %x", gameUpdater.layersActiveDuringObjectPause);

//ImGui::DragFloat("unkFloat5", &gameUpdater.unk5);
//ImGui::DragFloat("unkFloat6", &gameUpdater.unk6);

//for (int i = 0; i < 32; i++) {
// char name[100];
// snprintf(name, sizeof(name), "unk float for layer %d", i);
// ImGui::DragFloat(name, &gameUpdater.maybeFrameTimes[i]);
//}

for (int i = 0; i < 32; i++) {
ImGui::Text("updateInfo for layer %d: deltaTime (s): %f, total time (ms): %d, unk2: %x, unk3: %x", i, gameUpdater.updateInfos[i].deltaTime, gameUpdater.updateInfos[i].currentFrame, gameUpdater.updateInfos[i].unk2, gameUpdater.updateInfos[i].unk3);
}
auto* gameManager = hh::game::GameManager::GetInstance();

//float deltaTimes[32];
ImGui::DragFloat("FPS", (*reinterpret_cast<float**>(0x143D907A0) + 5));
ImGui::DragFloat("Timescale", &gameUpdater.timeScale, 0.01f);

//for (int i = 0; i < 32; i++) {
// deltaTimes[i] = gameUpdater.unk8[i].deltaTime;
//}
ImGui::SeparatorText("Per-layer information");
if (ImGui::BeginTable("Layer information", 10, ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollX)) {
ImGui::TableSetupColumn("Layer id");
ImGui::TableSetupColumn("Normal operation");
ImGui::TableSetupColumn("Ingame pause");
ImGui::TableSetupColumn("Debug pause");
ImGui::TableSetupColumn("Object pause");
ImGui::TableSetupColumn("Timescale");
ImGui::TableSetupColumn("DeltaTime");
ImGui::TableSetupColumn("Current frame");
ImGui::TableSetupColumn("Unk2");
ImGui::TableSetupColumn("Unk3");
ImGui::TableHeadersRow();

for (size_t i = 0; i < 32; i++) {
char name[20];
snprintf(name, sizeof(name), "Layer %zd", i);

ImGui::PushID(i);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%zd", i);
ImGui::TableNextColumn();
ImGui::CheckboxFlags("##layersActiveDuringNormalOperation", &gameUpdater.layersActiveDuringNormalOperation, 1 << i);
ImGui::TableNextColumn();
ImGui::CheckboxFlags("##layersActiveDuringIngamePause", &gameUpdater.layersActiveDuringIngamePause, 1 << i);
ImGui::TableNextColumn();
ImGui::CheckboxFlags("##layersActiveDuringDebugPause", &gameUpdater.layersActiveDuringDebugPause, 1 << i);
ImGui::TableNextColumn();
ImGui::CheckboxFlags("##layersActiveDuringObjectPause", &gameUpdater.layersActiveDuringObjectPause, 1 << i);
ImGui::TableNextColumn();
ImGui::DragFloat("##layerTimeScale", &gameUpdater.layerTimeScale[i], 0.01f);
ImGui::TableNextColumn();
ImGui::Text("%f", gameUpdater.updateInfos[i].deltaTime);
ImGui::TableNextColumn();
ImGui::Text("%d", gameUpdater.updateInfos[i].currentFrame);
ImGui::TableNextColumn();
ImGui::Text("%d", gameUpdater.updateInfos[i].unk2);
ImGui::TableNextColumn();
ImGui::Text("%x", gameUpdater.updateInfos[i].unk3);
ImGui::PopID();
}

ImGui::EndTable();
}
}
2 changes: 1 addition & 1 deletion src/ui/core-services/GameUpdaterInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class GameUpdaterInspector : public StandaloneWindow {
public:
GameUpdaterInspector(csl::fnd::IAllocator* allocator);

//virtual void PreRender() override;
virtual void PreRender() override;
virtual void RenderContents() override;
};
94 changes: 94 additions & 0 deletions src/ui/game-modes/GameModeInspector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "GameModeInspector.h"
#include <imgui_internal.h>
#include <ui/Desktop.h>
#include <ui/resources/editors/ResObjectWorldEditor.h>
#include <ui/common/ObjectDataEditor.h>
#include <ui/common/SimpleWidgets.h>

using namespace hh::game;

GameModeInspector::GameModeInspector(csl::fnd::IAllocator* allocator) : StandaloneWindow{ allocator } {
SetTitle("GameMode inspector");
}

void GameModeInspector::RenderContents() {
auto* seqExt = static_cast<app::MyApplication*>(app::MyApplication::GetInstance())->GetExtension<app::game::ApplicationSequenceExtension>();
if (!seqExt)
return;

auto* gameMode = seqExt->GetCurrentGameMode();
if (!gameMode)
return;

ImGui::SeparatorText("Extensions");
for (auto* extension : gameMode->extensions) {
if (extension->GetNameHash() == 0x42983F51) {
auto* ext = static_cast<app::game::GameModeLayerStatusExtension*>(extension);

if (ImGui::CollapsingHeader("Layer Status")) {
size_t i;
ImGui::SeparatorText("Active layers during normal operation override stack");
i = 0;
for (auto& d : ext->layersActiveDuringNormalOperation) {
if (ImGui::TreeNodeEx(&d, ImGuiTreeNodeFlags_None, "Stack item %d", i++)) {
for (size_t j = 0; j < 32; j++) {
char name[20];
snprintf(name, sizeof(name), "Layer %zd", j);

ImGui::CheckboxFlags(name, &d.unk3, 1 << j);
}
ImGui::TreePop();
}
}

ImGui::SeparatorText("Active layers during ingame pause override stack");
i = 0;
for (auto& d : ext->layersActiveDuringIngamePause) {
if (ImGui::TreeNodeEx(&d, ImGuiTreeNodeFlags_None, "Stack item %d", i++)) {
for (size_t j = 0; j < 32; j++) {
char name[20];
snprintf(name, sizeof(name), "Layer %zd", j);

ImGui::CheckboxFlags(name, &d.unk3, 1 << j);
}
ImGui::TreePop();
}
}

ImGui::SeparatorText("Global timescale interpolator stack");
ImGui::DragFloat("Timescale", &ext->globalInterpolator.timeScale);
i = 0;
for (auto& d : ext->globalInterpolator.unk1) {
if (ImGui::TreeNodeEx(&d, ImGuiTreeNodeFlags_None, "Interpolator %d", i++)) {
ImGui::DragFloat("Timescale", &d.timeScale, 0.01f);
ImGui::DragFloat("Current delta", &d.currentDelta, 0.01f);
ImGui::DragFloat("Increment per second", &d.incrementPerSecond, 0.01f);
ImGui::Text("Delegate count: %zd", d.unk3.functors.size());
ImGui::TreePop();
}
}

ImGui::SeparatorText("Per-layer timescale interpolator stacks");
i = 0;
for (auto& interpolator : ext->timeScaleInterpolators) {
if (ImGui::TreeNodeEx(&interpolator, ImGuiTreeNodeFlags_None, "Layer %d", i++)) {
ImGui::DragFloat("Timescale", &interpolator.timeScale);

size_t j = 0;
for (auto& d : interpolator.unk1) {
if (ImGui::TreeNodeEx(&d, ImGuiTreeNodeFlags_None, "Interpolator %d", j++)) {
ImGui::DragFloat("Timescale", &d.timeScale, 0.01f);
ImGui::DragFloat("Current delta", &d.currentDelta, 0.01f);
ImGui::DragFloat("Increment per second", &d.incrementPerSecond, 0.01f);
ImGui::Text("Delegate count: %zd", d.unk3.functors.size());
ImGui::TreePop();
}
}

ImGui::TreePop();
}
}
}
}
}
}
10 changes: 10 additions & 0 deletions src/ui/game-modes/GameModeInspector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <ui/common/StandaloneWindow.h>
#include <ui/common/ReflectionEditor.h>

class GameModeInspector : public StandaloneWindow
{
public:
GameModeInspector(csl::fnd::IAllocator* allocator);
virtual void RenderContents() override;
};
2 changes: 1 addition & 1 deletion src/ui/game-services/GameServiceInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void GameServiceInspector::RenderObjectWorldInspector(hh::game::ObjectWorld& obj
ImGui::CheckboxFlags("Started", &flags, 1 << static_cast<uint8_t>(WorldObjectStatus::Flag::STARTED));
ImGui::CheckboxFlags("No restart", &flags, 1 << static_cast<uint8_t>(WorldObjectStatus::Flag::NO_RESTART));

status.flags.m_dummy = static_cast<WorldObjectStatus::Flag>(flags);
status.flags.m_dummy = flags;

ImGui::InputInt("Spawn priority", &status.spawnPriority);

Expand Down
Loading

0 comments on commit ec823d2

Please sign in to comment.