Skip to content

Commit

Permalink
Almost SDK-agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Jun 1, 2024
1 parent 080da11 commit 474c721
Show file tree
Hide file tree
Showing 40 changed files with 783 additions and 372 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
path = vendor/filewatch/filewatch
url = https://github.com/ThomasMonkman/filewatch.git
[submodule "rangers-sdk"]
path = rangers-sdk
path = sdks/rangers-sdk
url = https://github.com/angryzor/rangers-sdk.git
[submodule "vendor/hedgelib/HedgeLib"]
path = vendor/hedgelib/HedgeLib
Expand All @@ -22,3 +22,6 @@
[submodule "vendor/implot/implot"]
path = vendor/implot/implot
url = https://github.com/epezent/implot.git
[submodule "sdks/wars-sdk"]
path = sdks/wars-sdk
url = https://github.com/angryzor/wars-sdk.git
110 changes: 66 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,77 @@ set(PROJECT_LONG_DESCRIPTION "In-engine development kit for Sonic Forces")
set(PROJECT_COPYRIGHT "Copyright (c) 2024 angryzor - Licensed under GPL3")
string(TIMESTAMP PROJECT_BUILD_DATE "%Y-%m-%d")

set(DEVTOOLS_GAME_FOLDER "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SonicForces" CACHE STRING "The location of your game folder.")
cmake_path(SET DEVTOOLS_GAME_FOLDER_NORMALIZED NORMALIZE ${DEVTOOLS_GAME_FOLDER})
cmake_path(APPEND DEVTOOLS_GAME_FOLDER_NORMALIZED "build/main/projects/exec/Sonic Forces.exe" OUTPUT_VARIABLE SONIC_FORCES_GAME_EXECUTABLE)

if(DEFINED ENV{SONIC_FORCES_SDK})
message("SONIC_FORCES_SDK environment variable found. Using this version instead of the local submodule.")
cmake_path(SET WARS_SDK_PATH NORMALIZE $ENV{SONIC_FORCES_SDK})
else()
set(WARS_SDK_PATH wars-sdk)
endif()

add_subdirectory(vendor EXCLUDE_FROM_ALL)
add_subdirectory(${WARS_SDK_PATH} wars-sdk EXCLUDE_FROM_ALL)

# DevTools
add_library(devtools SHARED)
target_compile_features(devtools PRIVATE cxx_std_17)
target_compile_options(devtools PRIVATE /ZI /permissive-)
target_compile_definitions(devtools
PRIVATE
DEVTOOLS_BINARY_FILENAME=$<TARGET_FILE_NAME:devtools>
DEVTOOLS_PROJECT_AUTHOR="${PROJECT_AUTHOR}"
DEVTOOLS_PROJECT_DESCRIPTION="${PROJECT_DESCRIPTION}"
DEVTOOLS_PROJECT_LONG_DESCRIPTION="${PROJECT_LONG_DESCRIPTION}"
DEVTOOLS_PROJECT_COPYRIGHT="${PROJECT_COPYRIGHT}"
DEVTOOLS_BUILD_DATE="${PROJECT_BUILD_DATE}"
DEVTOOLS_VERSION=${PROJECT_VERSION}
DEVTOOLS_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
DEVTOOLS_VERSION_MINOR=${PROJECT_VERSION_MINOR}
DEVTOOLS_VERSION_PATCH=${PROJECT_VERSION_PATCH}
)
set_target_properties(devtools
PROPERTIES
VS_DEBUGGER_COMMAND ${SONIC_FORCES_GAME_EXECUTABLE}
VS_DEBUGGER_WORKING_DIRECTORY "${DEVTOOLS_GAME_FOLDER_NORMALIZED}/build/main/projects/exec"
)

foreach(LIB wars-sdk HedgeLib filewatch detours imgui imgui-backend-win32 imgui-backend-dx11 imgui-file-dialog imguizmo implot)
target_link_libraries(devtools PRIVATE ${LIB})
endforeach()
# Settings for target sdks
set(SDK_VAR_wars "SONIC_FORCES_SDK")
set(GAME_FOLDER_DEFAULT_wars "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SonicForces")
set(GAME_EXECUTABLE_wars "build/main/projects/exec/Sonic Forces.exe")
set(WORKING_DIRECTORY_wars "build/main/projects/exec")
set(MOD_SUBFOLDER_wars "build/main/projects/exec/Mods/devtools")

set(SDK_VAR_rangers "SONIC_FRONTIERS_SDK")
set(GAME_FOLDER_DEFAULT_rangers "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SonicFrontiers")
set(GAME_EXECUTABLE_rangers "Sonic Frontiers.exe")
set(WORKING_DIRECTORY_rangers "")
set(MOD_SUBFOLDER_rangers "Mods/devtools")

# The main target
foreach(DEVTOOLS_TARGET_SDK rangers wars)
set(GAME_FOLDER ${GAME_FOLDER_DEFAULT_${DEVTOOLS_TARGET_SDK}} CACHE STRING "The location of your ${DEVTOOLS_TARGET_SDK} game folder.")
set(DEVTOOLS_TARGET devtools-${DEVTOOLS_TARGET_SDK})
cmake_path(SET GAME_FOLDER_NORMALIZED NORMALIZE ${GAME_FOLDER})
cmake_path(APPEND GAME_FOLDER_NORMALIZED ${GAME_EXECUTABLE_${DEVTOOLS_TARGET_SDK}} OUTPUT_VARIABLE GAME_EXECUTABLE)
cmake_path(APPEND GAME_FOLDER_NORMALIZED ${WORKING_DIRECTORY_${DEVTOOLS_TARGET_SDK}} OUTPUT_VARIABLE WORKING_DIRECTORY)
cmake_path(APPEND GAME_FOLDER_NORMALIZED ${MOD_SUBFOLDER_${DEVTOOLS_TARGET_SDK}} OUTPUT_VARIABLE MOD_FOLDER)

add_subdirectory(src)
add_subdirectory(natvis)
configure_file(Mod.ini.in Mod.ini)
if(DEFINED ENV{${SDK_VAR_${DEVTOOLS_TARGET_SDK}}})
message("${SDK_VAR_${DEVTOOLS_TARGET_SDK}} environment variable found. Using this version instead of the local submodule.")
cmake_path(SET SDK_PATH NORMALIZE $ENV{${SDK_VAR_${DEVTOOLS_TARGET_SDK}}})
else()
set(SDK_PATH ${DEVTOOLS_TARGET_SDK}-sdk)
endif()

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT devtools)
add_subdirectory(${SDK_PATH} ${DEVTOOLS_TARGET_SDK}-sdk EXCLUDE_FROM_ALL)

cmake_path(APPEND DEVTOOLS_GAME_FOLDER_NORMALIZED "build/main/projects/exec/Mods/devtools" OUTPUT_VARIABLE MOD_FOLDER)
add_library(${DEVTOOLS_TARGET} SHARED)
target_compile_features(${DEVTOOLS_TARGET} PRIVATE cxx_std_17)
target_compile_options(${DEVTOOLS_TARGET} PRIVATE /ZI /permissive-)
target_compile_definitions(${DEVTOOLS_TARGET}
PRIVATE
DEVTOOLS_BINARY_FILENAME=$<TARGET_FILE_NAME:${DEVTOOLS_TARGET}>
DEVTOOLS_TARGET_SDK="${DEVTOOLS_TARGET_SDK}"
DEVTOOLS_TARGET_SDK_${DEVTOOLS_TARGET_SDK}=1
DEVTOOLS_PROJECT_AUTHOR="${PROJECT_AUTHOR}"
DEVTOOLS_PROJECT_DESCRIPTION="${PROJECT_DESCRIPTION}"
DEVTOOLS_PROJECT_LONG_DESCRIPTION="${PROJECT_LONG_DESCRIPTION}"
DEVTOOLS_PROJECT_COPYRIGHT="${PROJECT_COPYRIGHT}"
DEVTOOLS_BUILD_DATE="${PROJECT_BUILD_DATE}"
DEVTOOLS_VERSION=${PROJECT_VERSION}
DEVTOOLS_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
DEVTOOLS_VERSION_MINOR=${PROJECT_VERSION_MINOR}
DEVTOOLS_VERSION_PATCH=${PROJECT_VERSION_PATCH}
)
set_target_properties(${DEVTOOLS_TARGET}
PROPERTIES
OUTPUT_NAME "devtools"
VS_DEBUGGER_COMMAND ${GAME_EXECUTABLE}
VS_DEBUGGER_WORKING_DIRECTORY ${WORKING_DIRECTORY}
)

install(TARGETS devtools RUNTIME DESTINATION "${MOD_FOLDER}")
install(DIRECTORY resources/ DESTINATION "${MOD_FOLDER}")
install(FILES LICENSE.txt "${CMAKE_CURRENT_BINARY_DIR}/Mod.ini" DESTINATION "${MOD_FOLDER}")
foreach(LIB ${DEVTOOLS_TARGET_SDK}-sdk HedgeLib filewatch detours imgui imgui-backend-win32 imgui-backend-dx11 imgui-file-dialog imguizmo implot)
target_link_libraries(${DEVTOOLS_TARGET} PRIVATE ${LIB})
endforeach()

add_subdirectory(src ${DEVTOOLS_TARGET}/src)
add_subdirectory(natvis ${DEVTOOLS_TARGET}/natvis)
configure_file(Mod.ini.in Mod.ini)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${DEVTOOLS_TARGET})

install(TARGETS ${DEVTOOLS_TARGET} RUNTIME DESTINATION "${MOD_FOLDER}")
install(DIRECTORY resources/ DESTINATION "${MOD_FOLDER}")
install(FILES LICENSE.txt "${CMAKE_CURRENT_BINARY_DIR}/Mod.ini" DESTINATION "${MOD_FOLDER}")
endforeach()
2 changes: 1 addition & 1 deletion natvis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target_sources(devtools
target_sources(${DEVTOOLS_TARGET}
PRIVATE
Eigen.natvis
)
1 change: 0 additions & 1 deletion rangers-sdk
Submodule rangers-sdk deleted from 2f0df2
1 change: 1 addition & 0 deletions sdks/rangers-sdk
Submodule rangers-sdk added at b7122f
1 change: 1 addition & 0 deletions sdks/wars-sdk
Submodule wars-sdk added at a96ea5
22 changes: 14 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
target_precompile_headers(devtools
target_precompile_headers(${DEVTOOLS_TARGET}
PRIVATE
Pch.h
)
target_sources(devtools
target_sources(${DEVTOOLS_TARGET}
PRIVATE
devtools.rc
DllMain.cpp
Expand All @@ -17,8 +17,8 @@ target_sources(devtools
# ui/common/editors/Camera.cpp
ui/common/editors/ObjectData.cpp
ui/common/editors/Reflection.cpp
# ui/common/editors/GraphicsContext.cpp
# ui/common/editors/LevelInfo.cpp
ui/common/editors/GraphicsContext.cpp
ui/common/editors/${DEVTOOLS_TARGET_SDK}/LevelInfo.cpp
# ui/common/editors/Needle.cpp
# ui/common/editors/SurfRide.cpp
ui/common/viewers/Basic.cpp
Expand All @@ -38,14 +38,17 @@ target_sources(devtools
# ui/core-services/MemoryInspector.cpp
ui/Desktop.cpp
# ui/game-modes/GameModeInspector.cpp
ui/game-services/game-service-inspectors/FxParamManager.cpp
ui/game-services/game-service-inspectors/${DEVTOOLS_TARGET_SDK}/FxParamManager.cpp
ui/game-services/game-service-inspectors/ObjectWorld.cpp
ui/game-services/game-service-inspectors/StageInfo.cpp
ui/game-services/game-service-inspectors/CameraManager.cpp
ui/game-services/GameServiceInspector.cpp
ui/operation-modes/LevelEditor/LevelEditor.cpp
ui/operation-modes/LevelEditor/ObjectDataInspector.cpp
ui/operation-modes/LevelEditor/ObjectLibrary.cpp
ui/operation-modes/LevelEditor/SetObjectList.cpp
ui/operation-modes/ObjectInspection/component-inspectors/GOCTransform.cpp
ui/operation-modes/ObjectInspection/component-inspectors/wars/GOCPlayerParameter.cpp
ui/operation-modes/ObjectInspection/component-inspectors/${DEVTOOLS_TARGET_SDK}/GOCPlayerParameter.cpp
ui/operation-modes/ObjectInspection/ObjectInspection.cpp
ui/operation-modes/ObjectInspection/ObjectInspector.cpp
ui/operation-modes/ObjectInspection/ObjectList.cpp
Expand All @@ -55,7 +58,7 @@ target_sources(devtools
# ui/operation-modes/SurfRideEditor/SurfRideEditor.cpp
ui/operation-modes/OperationMode.cpp
# ui/resources/editors/ResEffectEditor.cpp
# ui/resources/editors/ResObjectWorldEditor.cpp
ui/resources/editors/ResObjectWorldEditor.cpp
# ui/resources/editors/ResMaterialEditor.cpp
ui/resources/editors/ResReflectionEditor.cpp
# ui/resources/editors/ResSurfRideProjectEditor.cpp
Expand Down Expand Up @@ -112,13 +115,16 @@ target_sources(devtools
ui/fonts/Inter.h
ui/game-modes/GameModeInspector.h
ui/game-services/game-service-inspectors/FxParamManager.h
ui/game-services/game-service-inspectors/ObjectWorld.h
ui/game-services/game-service-inspectors/StageInfo.h
ui/game-services/game-service-inspectors/CameraManager.h
ui/game-services/GameServiceInspector.h
ui/operation-modes/LevelEditor/LevelEditor.h
ui/operation-modes/LevelEditor/ObjectDataInspector.h
ui/operation-modes/LevelEditor/ObjectLibrary.h
ui/operation-modes/LevelEditor/SetObjectList.h
ui/operation-modes/ObjectInspection/component-inspectors/GOCTransform.h
ui/operation-modes/ObjectInspection/component-inspectors/wars/GOCPlayerParameter.h
ui/operation-modes/ObjectInspection/component-inspectors/${DEVTOOLS_TARGET_SDK}/GOCPlayerParameter.h
ui/operation-modes/ObjectInspection/ObjectInspection.h
ui/operation-modes/ObjectInspection/ObjectInspector.h
ui/operation-modes/ObjectInspection/ObjectList.h
Expand Down
7 changes: 7 additions & 0 deletions src/Pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@

#include <d3d11.h>
#include <random>

#ifdef DEVTOOLS_TARGET_SDK_wars
#include <wars-sdk.h>
#endif

#ifdef DEVTOOLS_TARGET_SDK_rangers
#include <rangers-sdk.h>
#endif

#include <imgui.h>
#include <backends/imgui_impl_win32.h>
Expand Down
7 changes: 3 additions & 4 deletions src/debug-rendering/GOCVisualDebugDrawRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ HOOK(bool, __fastcall, VisualDebugDrawSetup, 0x140682D50, GOCMyVisualDebugDraw*
csl::ut::Color8 fillColor{ setupInfo.color };
//fillColor.a = 80;
fillColor.a = GOCVisualDebugDrawRenderer::gocVisualDebugDrawOpacity;
gocVisual->fillGeometry->Initialize(GOCVisualDebugDrawRenderer::instance->drawContext, *setupInfo.geometry, {});
gocVisual->fillGeometry->Initialize(GOCVisualDebugDrawRenderer::instance->drawContext, *setupInfo.geometry);
gocVisual->fillGeometry->SetColor(fillColor);

gocVisual->hasGeometry = true;
Expand Down Expand Up @@ -124,8 +124,7 @@ void GOCVisualDebugDrawRenderer::Renderable::Render(const hh::gfnd::RenderablePa
continue;

//goc->geometry->Render(renderer->drawContext, goc->worldMatrix);
goc->fillGeometry->SetTransform(goc->worldMatrix);
goc->fillGeometry->Render(renderer->drawContext);
goc->fillGeometry->Render(renderer->drawContext, goc->worldMatrix);
}

if (renderer->enabled) {
Expand Down Expand Up @@ -169,7 +168,7 @@ void GOCVisualDebugDrawRenderer::Renderable::Render(const hh::gfnd::RenderablePa

Eigen::Affine3f affine;
affine.fromPositionOrientationScale(cGoc->worldPos.m_Position, cGoc->worldPos.m_Rotation, cGoc->scale);
renderer->drawContext->DrawSphereFixed({ TransformToAffine3f(cGoc->frame->fullTransform) * affine }, 1, { 255, 0, 255, 255 });
renderer->drawContext->DrawSphere({ TransformToAffine3f(cGoc->frame->fullTransform) * affine }, 1, { 255, 0, 255, 255 });
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/hot-reload/ReloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void ReloadManager::Reload(void* buffer, size_t fileSize, hh::game::ResObjectWor
auto* allocator = layer->GetAllocator();
bool wasEnabled = layer->IsEnable();

//if (auto* levelEditor = dynamic_cast<LevelEditor*>(&*Desktop::instance->operationMode))
// levelEditor->Deselect();
if (auto* levelEditor = dynamic_cast<LevelEditor*>(&*Desktop::instance->operationMode))
levelEditor->Deselect();

{
Reference<hh::game::ObjectWorldChunkLayer> l{ layer };
Expand All @@ -140,8 +140,8 @@ void ReloadManager::Reload(void* buffer, size_t fileSize, hh::game::ResObjectWor
chunk->AddLayer(hh::game::ObjectWorldChunkLayer::Create(allocator, resource));
chunk->SetLayerEnabled(resource->GetName(), wasEnabled);

//if (auto* levelEditor = dynamic_cast<LevelEditor*>(&*Desktop::instance->operationMode))
// levelEditor->ReloadObjectWorldData();
if (auto* levelEditor = dynamic_cast<LevelEditor*>(&*Desktop::instance->operationMode))
levelEditor->ReloadObjectWorldData();

success = true;
break;
Expand Down
37 changes: 18 additions & 19 deletions src/ui/common/editors/Basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@ static bool Editor(const char* label, T& obj) {
return DragScalar(label, obj);
}

template<typename T, size_t Len>
static bool Editor(const char* label, T(&arr)[Len]) {
bool edited{};
char name[200];
snprintf(name, sizeof(name), "%s[0..%zd]", label, Len);

if (ImGui::TreeNode(name)) {
for (size_t i = 0; i < Len; i++) {
snprintf(name, sizeof(name), "%s[%zd]", label, i);
edited |= Editor(name, arr[i]);
}

ImGui::TreePop();
}

return edited;
}


template<typename T, int Rows, int Cols>
static bool Editor(const char* label, Eigen::Matrix<T, Rows, Cols>& mat) {
bool edited{};
Expand Down Expand Up @@ -68,3 +49,21 @@ template<typename T, std::enable_if_t<std::is_base_of_v<hh::game::GameObject, T>
static bool Editor(const char* label, T*& gameObject) {
return Editor(label, reinterpret_cast<hh::game::GameObject*&>(gameObject));
}

template<typename T, size_t Len>
static bool Editor(const char* label, T(&arr)[Len]) {
bool edited{};
char name[200];
snprintf(name, sizeof(name), "%s[0..%zd]", label, Len);

if (ImGui::TreeNode(name)) {
for (size_t i = 0; i < Len; i++) {
snprintf(name, sizeof(name), "%s[%zd]", label, i);
edited |= Editor(name, arr[i]);
}

ImGui::TreePop();
}

return edited;
}
41 changes: 29 additions & 12 deletions src/ui/common/editors/GraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ui/common/editors/Basic.h>
#include <ui/common/viewers/Basic.h>

const char* projectionTypeNames[]{ "Perspective (FOV)", "Perspective (frustum)", "Orthogonal" };
bool Editor(const char* label, hh::gfnd::ViewportData& viewport)
{
bool edited{};
Expand All @@ -13,29 +14,45 @@ bool Editor(const char* label, hh::gfnd::ViewportData& viewport)
edited |= Editor("Y", viewport.viewportDimensions.y);
edited |= Editor("Width", viewport.viewportDimensions.width);
edited |= Editor("Height", viewport.viewportDimensions.height);
Viewer("Render width", viewport.viewportDimensions.maybeRenderWidth);
Viewer("Render height", viewport.viewportDimensions.maybeRenderHeight);
// Viewer("Render width", viewport.viewportDimensions.maybeRenderWidth);
// Viewer("Render height", viewport.viewportDimensions.maybeRenderHeight);
ImGui::EndGroup();

ImGui::SeparatorText("View settings");
if (BeginVectorViewerTable("LookAt position", false)) {
Viewer("LookAt position", viewport.lookAtPos);
EndVectorViewerTable();
}

ImGui::SeparatorText("Projection settings");
Viewer("Aspect ratio", viewport.aspectRatio);
Viewer("FOV", viewport.fov);
Viewer("Near clipping plane", viewport.nearClip);
Viewer("Far clipping plane", viewport.farClip);
Viewer("Projection type", projectionTypeNames[static_cast<uint8_t>(viewport.projectionType)]);

switch (viewport.projectionType) {
case hh::gfnd::ViewportData::ProjectionType::PERSPECTIVE_FOV:
Viewer("Aspect ratio", viewport.projectionParameters.fov.aspectRatio);
Viewer("FOV", viewport.projectionParameters.fov.fov);
Viewer("Near clipping plane", viewport.projectionParameters.fov.nearClip);
Viewer("Far clipping plane", viewport.projectionParameters.fov.farClip);
break;
default:
Viewer("Top", viewport.projectionParameters.frustum.top);
Viewer("Bottom", viewport.projectionParameters.frustum.bottom);
Viewer("Left", viewport.projectionParameters.frustum.left);
Viewer("Right", viewport.projectionParameters.frustum.right);
Viewer("Near clipping plane", viewport.projectionParameters.frustum.nearClip);
Viewer("Far clipping plane", viewport.projectionParameters.frustum.farClip);
break;
}

ImGui::SeparatorText("View matrix");
Viewer("View matrix", viewport.viewMatrix);

ImGui::SeparatorText("Inverse view matrix");
Viewer("Inverse view matrix", viewport.inverseViewMatrix);
//ImGui::SeparatorText("Inverse view matrix");
//Viewer("Inverse view matrix", viewport.inverseViewMatrix);

ImGui::SeparatorText("Projection matrix");
Viewer("Projection matrix", viewport.projMatrix);

if (BeginVectorViewerTable("LookAt position", false)) {
Viewer("LookAt position", viewport.lookAtPos);
EndVectorViewerTable();
}
//Editor("Unk5", viewport.unk5);
//Editor("Unk7", viewport.unk7);
//Editor("Unk8", viewport.unk8);
Expand Down
Loading

0 comments on commit 474c721

Please sign in to comment.