From 5bc53b4fa48ff0563bfda3b1d4e88baf9eff2ca4 Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Fri, 21 Apr 2023 14:31:09 +1000 Subject: [PATCH 1/7] cam detection stuff with debug included --- .gitignore | 1 + CamDetection.as | 164 ++++++++++++++++++++++++++++++++++++++++++++++++ Export.as | 6 ++ ExportShared.as | 21 +++++++ Impl.as | 5 ++ Main.as | 15 ++++- info.toml | 1 + 7 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 CamDetection.as create mode 100644 ExportShared.as diff --git a/.gitignore b/.gitignore index 4e54622..16cf513 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.sig +*.sh diff --git a/CamDetection.as b/CamDetection.as new file mode 100644 index 0000000..9bcd689 --- /dev/null +++ b/CamDetection.as @@ -0,0 +1,164 @@ +/** Render function called every frame intended only for menu items in the main menu of the `UI`. +*/ +void RenderMenuMain() { + UI::BeginDisabled(); + UI::MenuItem("Current Cam: " + tostring(g_activeCam)); + UI::EndDisabled(); +} + +const string JsonStatusFile = IO::FromStorageFolder("status.json"); + +void SetStatusRunning() { + auto j = Json::Object(); + j['running'] = true; + j['timestamp'] = Time::Stamp; + j['now'] = Time::Now; + Json::ToFile(JsonStatusFile, j); +} + +void SetStatusDone() { + auto j = Json::Object(); + j['running'] = false; + j['timestamp'] = Time::Stamp; + j['now'] = Time::Now; + Json::ToFile(JsonStatusFile, j); +} + +ActiveCam g_activeCam = ActiveCam::Loading; + +void UpdateActiveGameCam() +{ + g_activeCam = ActiveCam::None; + + const Reflection::MwClassInfo@ tmTy = Reflection::GetType("CTrackMania"); + const Reflection::MwMemberInfo@ gameSceneMember = tmTy.GetMember("GameScene"); + uint GameCameraNodOffset = gameSceneMember.Offset + 0x10; + + auto gameCameraNod = Dev::GetOffsetNod(GetApp(), GameCameraNodOffset); + + // This is null in the menu and when cameras aren't being used. + if (gameCameraNod is null) { + return; + } + + auto camModelNod = Dev::GetOffsetNod(gameCameraNod, 0x58); + auto camControlNod = Dev::GetOffsetNod(gameCameraNod, 0x68); + + // 0x2AC has a flag related to using internal cam (which is what the backwards cam is) + bool isBackwards = Dev::GetOffsetUint32(gameCameraNod, 0xB0) == 0x4; + + if (isBackwards) { + g_activeCam = ActiveCam::Backwards; + } else if (camModelNod !is null) { + auto ty = Reflection::TypeOf(camModelNod); + switch (ty.ID) { + // CPlugVehicleCameraRace2Model + case 0x90f6000: { + g_activeCam = TestCam1Alt(camModelNod) ? ActiveCam::Cam1Alt : ActiveCam::Cam1; + break; + } + // CPlugVehicleCameraRace3Model + case 0x90ef000: { + g_activeCam = TestCam2Alt(camModelNod) ? ActiveCam::Cam2Alt : ActiveCam::Cam2; + break; + } + // CPlugVehicleCameraInternalModel + case 0x90f7000: { + g_activeCam = TestCam3Alt(camModelNod) ? ActiveCam::Cam3Alt : ActiveCam::Cam3; + break; + } + default: { + trace('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + UI::ShowNotification('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + g_activeCam = ActiveCam::Other; + }; + } + } else if (camControlNod !is null) { + auto ty = Reflection::TypeOf(camControlNod); + switch (ty.ID) { + // CGameControlCameraFree + case 0x306d000: { + g_activeCam = ActiveCam::FreeCam; + break; + } + // CGameControlCameraEditorOrbital + case 0x3125000: { + g_activeCam = ActiveCam::EditorOrbital; + break; + } + // CGameControlCameraOrbital3d + case 0x306e000: { + g_activeCam = ActiveCam::Orbital3d; + break; + } + // CGameControlCameraHelico + case 0x32f0000: { + g_activeCam = ActiveCam::Helico; + break; + } + // CGameControlCameraHmdExternal + case 0x3277000: { + g_activeCam = ActiveCam::HmdExternal; + break; + } + // CGameControlCameraThirdPerson + case 0x3042000: { + g_activeCam = ActiveCam::ThirdPerson; + break; + } + // CGameControlCameraFirstPerson + case 0x3041000: { + g_activeCam = ActiveCam::FirstPerson; + break; + } + // CGameControlCameraTarget + case 0x3072000: { + g_activeCam = ActiveCam::Target; + break; + } + // CGameControlCameraTrackManiaRace + case 0x313d000: { + g_activeCam = ActiveCam::Cam0; + break; + } + // CGameControlCamera + case 0x306b000: { + // We probably won't ever end up here, but just in case. + g_activeCam = ActiveCam::Other; + break; + } + // CGameControlCameraTrackManiaRace2 + // 0x31cf000 + // CGameControlCameraTrackManiaRace3 + // 0x31ce000 + // CGameControlCameraVehicleInternal + // 0x3189000 + default: { + trace('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + UI::ShowNotification('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + g_activeCam = ActiveCam::Other; + }; + } + } else { + // initalizing editor, when in mediatracker + g_activeCam = ActiveCam::Loading; + } +} + +bool TestCam1Alt(CMwNod@ camNod) +{ + // alt 00 00 40 40, main: 00 00 a0 40 -- constant after restart + return Dev::GetOffsetUint32(camNod, 0x38) == 0x40400000; +} + +bool TestCam2Alt(CMwNod@ camNod) +{ + // alt: 00 00 8C 42, main: 00 00 96 42 -- constant after game restart + return Dev::GetOffsetUint32(camNod, 0x38) == 0x428c0000; +} + +bool TestCam3Alt(CMwNod@ camNod) +{ + // std: 0, alt: 1 + return Dev::GetOffsetUint32(camNod, 0x34) == 1; +} diff --git a/Export.as b/Export.as index 1d404e8..a27a848 100644 --- a/Export.as +++ b/Export.as @@ -20,6 +20,12 @@ namespace Camera // Gets the current camera position. import vec3 GetCurrentPosition() from "Camera"; + // Gets the current camera looking direction. + import vec3 GetCurrentLookingDirection() from "Camera"; + // In the editor, sets the currently focused camera position of the orbital camera. import void SetEditorOrbitalTarget(const vec3 &in pos) from "Camera"; + + // Gets the currently active game camera. + import ActiveCam GetCurrentGameCamera() from "Camera"; } diff --git a/ExportShared.as b/ExportShared.as new file mode 100644 index 0000000..cc687ff --- /dev/null +++ b/ExportShared.as @@ -0,0 +1,21 @@ +shared enum ActiveCam { + None = 0, + Cam1 = 1, + Cam2 = 2, + Cam3 = 3, + Cam1Alt = 4, + Cam2Alt = 5, + Cam3Alt = 6, + FreeCam = 7, + Backwards = 8, + EditorOrbital, + Orbital3d, + Helico, + HmdExternal, + ThirdPerson, + FirstPerson, + Target, + Cam0, + Other, + Loading +} diff --git a/Impl.as b/Impl.as index 7b9a3ed..f5da8fe 100644 --- a/Impl.as +++ b/Impl.as @@ -41,6 +41,11 @@ namespace Camera return g_position; } + vec3 GetCurrentLookingDirection() + { + return g_direction; + } + void SetEditorOrbitalTarget(const vec3 &in pos) { auto editor = cast(GetApp().Editor); diff --git a/Main.as b/Main.as index 252e890..22eedee 100644 --- a/Main.as +++ b/Main.as @@ -1,13 +1,21 @@ CHmsCamera@ g_currentCamera = null; mat4 g_projection = mat4::Identity(); +mat4 g_rotation = mat4::Identity(); vec3 g_position = vec3(); +vec3 g_direction = vec3(); vec2 g_displayPos; vec2 g_displaySize; void RenderEarly() { + // SetStatusRunning(); + UpdateActiveGameCam(); + // SetStatusDone(); + + auto t = float(Time::Now % 1000) / 1000.0; + // SetFreeCamPos(vec3(Math::Lerp(860.0, 880.0, t), Math::Lerp(16.0, 60.0, t), Math::Lerp(726.0, 780.0, t))); auto viewport = GetApp().Viewport; @g_currentCamera = null; @@ -28,6 +36,7 @@ void RenderEarly() if (g_currentCamera !is null) { iso4 camLoc = g_currentCamera.Location; + mat4 camLocMat = mat4(camLoc); float camFov = g_currentCamera.Fov; float camNearZ = g_currentCamera.NearZ; float camFarZ = g_currentCamera.FarZ; @@ -39,9 +48,10 @@ void RenderEarly() mat4 projection = mat4::Perspective(camFov, camAspect, camNearZ, camFarZ); mat4 translation = mat4::Translate(vec3(camLoc.tx, camLoc.ty, camLoc.tz)); - mat4 rotation = mat4::Inverse(mat4::Inverse(translation) * mat4(camLoc)); + mat4 inverseTranslation = mat4::Inverse(translation); + g_rotation = mat4::Inverse(inverseTranslation * camLocMat); - g_projection = projection * mat4::Inverse(translation * rotation); + g_projection = projection * mat4::Inverse(translation * g_rotation); g_position = vec3(camLoc.tx, camLoc.ty, camLoc.tz); vec2 topLeft = 1 - (g_currentCamera.DrawRectMax + 1) / 2; @@ -49,5 +59,6 @@ void RenderEarly() g_displaySize = vec2(Draw::GetWidth(), Draw::GetHeight()); g_displayPos = topLeft * g_displaySize; g_displaySize *= bottomRight - topLeft; + g_direction = vec3(camLoc.xz, camLoc.yz, camLoc.zz); } } diff --git a/info.toml b/info.toml index 4f3e7b8..c01709f 100644 --- a/info.toml +++ b/info.toml @@ -6,4 +6,5 @@ essential = true [script] exports = [ "Export.as" ] +shared_exports = [ "ExportShared.as" ] timeout = 0 From 32fa680848d070365fa97708aff364eeae56ec5b Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Fri, 21 Apr 2023 14:39:49 +1000 Subject: [PATCH 2/7] Polish for first review comments --- CamDetection.as | 32 +++++++------------------------- Impl.as | 4 ++++ Main.as | 6 ++---- Settings.as | 2 ++ 4 files changed, 15 insertions(+), 29 deletions(-) create mode 100644 Settings.as diff --git a/CamDetection.as b/CamDetection.as index 9bcd689..04e9d56 100644 --- a/CamDetection.as +++ b/CamDetection.as @@ -1,31 +1,13 @@ -/** Render function called every frame intended only for menu items in the main menu of the `UI`. -*/ -void RenderMenuMain() { +void RenderMenuMain() +{ + if (!Setting_DebugShowActiveCamInMenu) { + return; + } UI::BeginDisabled(); - UI::MenuItem("Current Cam: " + tostring(g_activeCam)); + UI::MenuItem("Active Cam: " + tostring(g_activeCam)); UI::EndDisabled(); } -const string JsonStatusFile = IO::FromStorageFolder("status.json"); - -void SetStatusRunning() { - auto j = Json::Object(); - j['running'] = true; - j['timestamp'] = Time::Stamp; - j['now'] = Time::Now; - Json::ToFile(JsonStatusFile, j); -} - -void SetStatusDone() { - auto j = Json::Object(); - j['running'] = false; - j['timestamp'] = Time::Stamp; - j['now'] = Time::Now; - Json::ToFile(JsonStatusFile, j); -} - -ActiveCam g_activeCam = ActiveCam::Loading; - void UpdateActiveGameCam() { g_activeCam = ActiveCam::None; @@ -44,7 +26,7 @@ void UpdateActiveGameCam() auto camModelNod = Dev::GetOffsetNod(gameCameraNod, 0x58); auto camControlNod = Dev::GetOffsetNod(gameCameraNod, 0x68); - // 0x2AC has a flag related to using internal cam (which is what the backwards cam is) + // Always 4 when backwards, and seemingly always 0 otherwise bool isBackwards = Dev::GetOffsetUint32(gameCameraNod, 0xB0) == 0x4; if (isBackwards) { diff --git a/Impl.as b/Impl.as index f5da8fe..edbb608 100644 --- a/Impl.as +++ b/Impl.as @@ -77,4 +77,8 @@ namespace Camera Dev::SetOffset(orbital, 0x44, newCameraPos); #endif } + + ActiveCam GetCurrentGameCamera() { + return g_activeCam; + } } diff --git a/Main.as b/Main.as index 22eedee..af17901 100644 --- a/Main.as +++ b/Main.as @@ -8,14 +8,12 @@ vec3 g_direction = vec3(); vec2 g_displayPos; vec2 g_displaySize; +ActiveCam g_activeCam = ActiveCam::None; + void RenderEarly() { - // SetStatusRunning(); UpdateActiveGameCam(); - // SetStatusDone(); - auto t = float(Time::Now % 1000) / 1000.0; - // SetFreeCamPos(vec3(Math::Lerp(860.0, 880.0, t), Math::Lerp(16.0, 60.0, t), Math::Lerp(726.0, 780.0, t))); auto viewport = GetApp().Viewport; @g_currentCamera = null; diff --git a/Settings.as b/Settings.as new file mode 100644 index 0000000..f5b4af8 --- /dev/null +++ b/Settings.as @@ -0,0 +1,2 @@ +[Setting category="Debug" name="Debug: Show Active Cam in the Menu Bar"] +bool Setting_DebugShowActiveCamInMenu = false; From 66ac200de27aa07c40e365c32bb71abce071bd4a Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Sun, 23 Jul 2023 15:20:18 +1000 Subject: [PATCH 3/7] get class ids each time + better alt cam check --- CamDetection.as | 170 +++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 88 deletions(-) diff --git a/CamDetection.as b/CamDetection.as index 04e9d56..e74cad3 100644 --- a/CamDetection.as +++ b/CamDetection.as @@ -1,3 +1,5 @@ +#if TMNEXT + void RenderMenuMain() { if (!Setting_DebugShowActiveCamInMenu) { @@ -8,14 +10,14 @@ void RenderMenuMain() UI::EndDisabled(); } +const Reflection::MwClassInfo@ tmTy = Reflection::GetType("CTrackMania"); +const Reflection::MwMemberInfo@ gameSceneMember = tmTy.GetMember("GameScene"); +const uint GameCameraNodOffset = gameSceneMember.Offset + 0x10; + void UpdateActiveGameCam() { g_activeCam = ActiveCam::None; - const Reflection::MwClassInfo@ tmTy = Reflection::GetType("CTrackMania"); - const Reflection::MwMemberInfo@ gameSceneMember = tmTy.GetMember("GameScene"); - uint GameCameraNodOffset = gameSceneMember.Offset + 0x10; - auto gameCameraNod = Dev::GetOffsetNod(GetApp(), GameCameraNodOffset); // This is null in the menu and when cameras aren't being used. @@ -25,6 +27,10 @@ void UpdateActiveGameCam() auto camModelNod = Dev::GetOffsetNod(gameCameraNod, 0x58); auto camControlNod = Dev::GetOffsetNod(gameCameraNod, 0x68); + // 0x1 for std, 0x2 for alt. + bool cam1Alt = Dev::GetOffsetUint8(gameCameraNod, 0x24) == 0x2; + bool cam2Alt = Dev::GetOffsetUint8(gameCameraNod, 0x25) == 0x2; + bool cam3Alt = Dev::GetOffsetUint8(gameCameraNod, 0x26) == 0x2; // Always 4 when backwards, and seemingly always 0 otherwise bool isBackwards = Dev::GetOffsetUint32(gameCameraNod, 0xB0) == 0x4; @@ -33,93 +39,53 @@ void UpdateActiveGameCam() g_activeCam = ActiveCam::Backwards; } else if (camModelNod !is null) { auto ty = Reflection::TypeOf(camModelNod); - switch (ty.ID) { - // CPlugVehicleCameraRace2Model - case 0x90f6000: { - g_activeCam = TestCam1Alt(camModelNod) ? ActiveCam::Cam1Alt : ActiveCam::Cam1; - break; - } - // CPlugVehicleCameraRace3Model - case 0x90ef000: { - g_activeCam = TestCam2Alt(camModelNod) ? ActiveCam::Cam2Alt : ActiveCam::Cam2; - break; - } - // CPlugVehicleCameraInternalModel - case 0x90f7000: { - g_activeCam = TestCam3Alt(camModelNod) ? ActiveCam::Cam3Alt : ActiveCam::Cam3; - break; - } - default: { - trace('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); - UI::ShowNotification('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); - g_activeCam = ActiveCam::Other; - }; + if (ty.ID == ClsId_CPlugVehicleCameraRace2Model) { + g_activeCam = cam1Alt ? ActiveCam::Cam1Alt : ActiveCam::Cam1; + } else if (ty.ID == ClsId_CPlugVehicleCameraRace3Model) { + g_activeCam = cam2Alt ? ActiveCam::Cam2Alt : ActiveCam::Cam2; + } else if (ty.ID == ClsId_CPlugVehicleCameraInternalModel) { + g_activeCam = cam3Alt ? ActiveCam::Cam3Alt : ActiveCam::Cam3; + } else if (ty.ID == ClsId_CPlugVehicleCameraHelicoModel) { + // this happens with CharacterPilot maps + g_activeCam = ActiveCam::Helico; + } else { + trace('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + UI::ShowNotification('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + g_activeCam = ActiveCam::Other; } } else if (camControlNod !is null) { auto ty = Reflection::TypeOf(camControlNod); - switch (ty.ID) { - // CGameControlCameraFree - case 0x306d000: { - g_activeCam = ActiveCam::FreeCam; - break; - } - // CGameControlCameraEditorOrbital - case 0x3125000: { - g_activeCam = ActiveCam::EditorOrbital; - break; - } - // CGameControlCameraOrbital3d - case 0x306e000: { - g_activeCam = ActiveCam::Orbital3d; - break; - } - // CGameControlCameraHelico - case 0x32f0000: { - g_activeCam = ActiveCam::Helico; - break; - } - // CGameControlCameraHmdExternal - case 0x3277000: { - g_activeCam = ActiveCam::HmdExternal; - break; - } - // CGameControlCameraThirdPerson - case 0x3042000: { - g_activeCam = ActiveCam::ThirdPerson; - break; - } - // CGameControlCameraFirstPerson - case 0x3041000: { - g_activeCam = ActiveCam::FirstPerson; - break; - } - // CGameControlCameraTarget - case 0x3072000: { - g_activeCam = ActiveCam::Target; - break; - } - // CGameControlCameraTrackManiaRace - case 0x313d000: { - g_activeCam = ActiveCam::Cam0; - break; - } - // CGameControlCamera - case 0x306b000: { - // We probably won't ever end up here, but just in case. - g_activeCam = ActiveCam::Other; - break; - } - // CGameControlCameraTrackManiaRace2 - // 0x31cf000 - // CGameControlCameraTrackManiaRace3 - // 0x31ce000 - // CGameControlCameraVehicleInternal - // 0x3189000 - default: { - trace('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); - UI::ShowNotification('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); - g_activeCam = ActiveCam::Other; - }; + if (ty.ID == ClsId_CGameControlCameraFree) { + g_activeCam = ActiveCam::FreeCam; + } else if (ty.ID == ClsId_CGameControlCameraEditorOrbital) { + g_activeCam = ActiveCam::EditorOrbital; + } else if (ty.ID == ClsId_CGameControlCameraOrbital3d) { + g_activeCam = ActiveCam::Orbital3d; + } else if (ty.ID == ClsId_CGameControlCameraHelico) { + g_activeCam = ActiveCam::Helico; + } else if (ty.ID == ClsId_CGameControlCameraHmdExternal) { + g_activeCam = ActiveCam::HmdExternal; + } else if (ty.ID == ClsId_CGameControlCameraThirdPerson) { + g_activeCam = ActiveCam::ThirdPerson; + } else if (ty.ID == ClsId_CGameControlCameraFirstPerson) { + g_activeCam = ActiveCam::FirstPerson; + } else if (ty.ID == ClsId_CGameControlCameraTarget) { + g_activeCam = ActiveCam::Target; + } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace) { + g_activeCam = ActiveCam::Cam0; + } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace2) { + g_activeCam = ActiveCam::Cam1; + } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace3) { + g_activeCam = ActiveCam::Cam2; + } else if (ty.ID == ClsId_CGameControlCameraVehicleInternal) { + g_activeCam = ActiveCam::Cam3; + } else if (ty.ID == ClsId_CGameControlCamera) { + // We probably won't ever end up here, but just in case. + g_activeCam = ActiveCam::Other; + } else { + trace('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + UI::ShowNotification('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); + g_activeCam = ActiveCam::Other; } } else { // initalizing editor, when in mediatracker @@ -144,3 +110,31 @@ bool TestCam3Alt(CMwNod@ camNod) // std: 0, alt: 1 return Dev::GetOffsetUint32(camNod, 0x34) == 1; } + +const uint ClsId_CPlugVehicleCameraRace2Model = Reflection::GetType("CPlugVehicleCameraRace2Model").ID; +const uint ClsId_CPlugVehicleCameraRace3Model = Reflection::GetType("CPlugVehicleCameraRace3Model").ID; +const uint ClsId_CPlugVehicleCameraInternalModel = Reflection::GetType("CPlugVehicleCameraInternalModel").ID; +const uint ClsId_CPlugVehicleCameraHelicoModel = Reflection::GetType("CPlugVehicleCameraHelicoModel").ID; + +const uint ClsId_CGameControlCameraFree = Reflection::GetType("CGameControlCameraFree").ID; +const uint ClsId_CGameControlCameraEditorOrbital = Reflection::GetType("CGameControlCameraEditorOrbital").ID; +const uint ClsId_CGameControlCameraOrbital3d = Reflection::GetType("CGameControlCameraOrbital3d").ID; +const uint ClsId_CGameControlCameraHelico = Reflection::GetType("CGameControlCameraHelico").ID; +const uint ClsId_CGameControlCameraHmdExternal = Reflection::GetType("CGameControlCameraHmdExternal").ID; +const uint ClsId_CGameControlCameraThirdPerson = Reflection::GetType("CGameControlCameraThirdPerson").ID; +const uint ClsId_CGameControlCameraFirstPerson = Reflection::GetType("CGameControlCameraFirstPerson").ID; +const uint ClsId_CGameControlCameraTarget = Reflection::GetType("CGameControlCameraTarget").ID; +const uint ClsId_CGameControlCameraTrackManiaRace = Reflection::GetType("CGameControlCameraTrackManiaRace").ID; +const uint ClsId_CGameControlCamera = Reflection::GetType("CGameControlCamera").ID; +const uint ClsId_CGameControlCameraTrackManiaRace2 = Reflection::GetType("CGameControlCameraTrackManiaRace2").ID; +const uint ClsId_CGameControlCameraTrackManiaRace3 = Reflection::GetType("CGameControlCameraTrackManiaRace3").ID; +const uint ClsId_CGameControlCameraVehicleInternal = Reflection::GetType("CGameControlCameraVehicleInternal").ID; + +#else + +void UpdateActiveGameCam() +{ + // not supported in MP4 / Turbo +} + +#endif From 83b2a6903160a46e91be67e128b8f3cc4f194c72 Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Sun, 23 Jul 2023 15:25:30 +1000 Subject: [PATCH 4/7] condense code --- Main.as | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Main.as b/Main.as index af17901..7601619 100644 --- a/Main.as +++ b/Main.as @@ -46,8 +46,7 @@ void RenderEarly() mat4 projection = mat4::Perspective(camFov, camAspect, camNearZ, camFarZ); mat4 translation = mat4::Translate(vec3(camLoc.tx, camLoc.ty, camLoc.tz)); - mat4 inverseTranslation = mat4::Inverse(translation); - g_rotation = mat4::Inverse(inverseTranslation * camLocMat); + g_rotation = mat4::Inverse(mat4::Inverse(translation) * camLocMat); g_projection = projection * mat4::Inverse(translation * g_rotation); g_position = vec3(camLoc.tx, camLoc.ty, camLoc.tz); From f8bb3da21a54399625c22618bd6da371efbfe65e Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Sun, 23 Jul 2023 15:29:58 +1000 Subject: [PATCH 5/7] text disabled instead of disabled menu item --- CamDetection.as | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CamDetection.as b/CamDetection.as index e74cad3..dc9d02b 100644 --- a/CamDetection.as +++ b/CamDetection.as @@ -5,9 +5,7 @@ void RenderMenuMain() if (!Setting_DebugShowActiveCamInMenu) { return; } - UI::BeginDisabled(); - UI::MenuItem("Active Cam: " + tostring(g_activeCam)); - UI::EndDisabled(); + UI::TextDisabled("Active Cam: " + tostring(g_activeCam)); } const Reflection::MwClassInfo@ tmTy = Reflection::GetType("CTrackMania"); From dc1f4c9020a90bdcd1b5630be90037680a7f5e7a Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Sun, 23 Jul 2023 15:51:48 +1000 Subject: [PATCH 6/7] tidy up some things and add sig_dev around unknown camera type alerts --- CamDetection.as | 25 ++++++------------------- Impl.as | 3 ++- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/CamDetection.as b/CamDetection.as index dc9d02b..8586f26 100644 --- a/CamDetection.as +++ b/CamDetection.as @@ -47,8 +47,10 @@ void UpdateActiveGameCam() // this happens with CharacterPilot maps g_activeCam = ActiveCam::Helico; } else { +#if SIG_DEVELOPER trace('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); UI::ShowNotification('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); +#endif g_activeCam = ActiveCam::Other; } } else if (camControlNod !is null) { @@ -81,8 +83,11 @@ void UpdateActiveGameCam() // We probably won't ever end up here, but just in case. g_activeCam = ActiveCam::Other; } else { + // debug so we know that a cam is unknown +#if SIG_DEVELOPER trace('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); UI::ShowNotification('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); +#endif g_activeCam = ActiveCam::Other; } } else { @@ -91,24 +96,6 @@ void UpdateActiveGameCam() } } -bool TestCam1Alt(CMwNod@ camNod) -{ - // alt 00 00 40 40, main: 00 00 a0 40 -- constant after restart - return Dev::GetOffsetUint32(camNod, 0x38) == 0x40400000; -} - -bool TestCam2Alt(CMwNod@ camNod) -{ - // alt: 00 00 8C 42, main: 00 00 96 42 -- constant after game restart - return Dev::GetOffsetUint32(camNod, 0x38) == 0x428c0000; -} - -bool TestCam3Alt(CMwNod@ camNod) -{ - // std: 0, alt: 1 - return Dev::GetOffsetUint32(camNod, 0x34) == 1; -} - const uint ClsId_CPlugVehicleCameraRace2Model = Reflection::GetType("CPlugVehicleCameraRace2Model").ID; const uint ClsId_CPlugVehicleCameraRace3Model = Reflection::GetType("CPlugVehicleCameraRace3Model").ID; const uint ClsId_CPlugVehicleCameraInternalModel = Reflection::GetType("CPlugVehicleCameraInternalModel").ID; @@ -132,7 +119,7 @@ const uint ClsId_CGameControlCameraVehicleInternal = Reflection::GetType("CGameC void UpdateActiveGameCam() { - // not supported in MP4 / Turbo + // not supported yet in MP4 / Turbo } #endif diff --git a/Impl.as b/Impl.as index edbb608..45c8cb6 100644 --- a/Impl.as +++ b/Impl.as @@ -78,7 +78,8 @@ namespace Camera #endif } - ActiveCam GetCurrentGameCamera() { + ActiveCam GetCurrentGameCamera() + { return g_activeCam; } } From 5dfd76562536cfe29165c320bffdcf07d0bf4092 Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Sun, 23 Jul 2023 15:53:15 +1000 Subject: [PATCH 7/7] change g_activeCamera to g_activeCameraType --- CamDetection.as | 46 +++++++++++++++++++++++----------------------- Impl.as | 2 +- Main.as | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CamDetection.as b/CamDetection.as index 8586f26..b457273 100644 --- a/CamDetection.as +++ b/CamDetection.as @@ -5,7 +5,7 @@ void RenderMenuMain() if (!Setting_DebugShowActiveCamInMenu) { return; } - UI::TextDisabled("Active Cam: " + tostring(g_activeCam)); + UI::TextDisabled("Active Cam: " + tostring(g_activeCameraType)); } const Reflection::MwClassInfo@ tmTy = Reflection::GetType("CTrackMania"); @@ -14,7 +14,7 @@ const uint GameCameraNodOffset = gameSceneMember.Offset + 0x10; void UpdateActiveGameCam() { - g_activeCam = ActiveCam::None; + g_activeCameraType = ActiveCam::None; auto gameCameraNod = Dev::GetOffsetNod(GetApp(), GameCameraNodOffset); @@ -34,65 +34,65 @@ void UpdateActiveGameCam() bool isBackwards = Dev::GetOffsetUint32(gameCameraNod, 0xB0) == 0x4; if (isBackwards) { - g_activeCam = ActiveCam::Backwards; + g_activeCameraType = ActiveCam::Backwards; } else if (camModelNod !is null) { auto ty = Reflection::TypeOf(camModelNod); if (ty.ID == ClsId_CPlugVehicleCameraRace2Model) { - g_activeCam = cam1Alt ? ActiveCam::Cam1Alt : ActiveCam::Cam1; + g_activeCameraType = cam1Alt ? ActiveCam::Cam1Alt : ActiveCam::Cam1; } else if (ty.ID == ClsId_CPlugVehicleCameraRace3Model) { - g_activeCam = cam2Alt ? ActiveCam::Cam2Alt : ActiveCam::Cam2; + g_activeCameraType = cam2Alt ? ActiveCam::Cam2Alt : ActiveCam::Cam2; } else if (ty.ID == ClsId_CPlugVehicleCameraInternalModel) { - g_activeCam = cam3Alt ? ActiveCam::Cam3Alt : ActiveCam::Cam3; + g_activeCameraType = cam3Alt ? ActiveCam::Cam3Alt : ActiveCam::Cam3; } else if (ty.ID == ClsId_CPlugVehicleCameraHelicoModel) { // this happens with CharacterPilot maps - g_activeCam = ActiveCam::Helico; + g_activeCameraType = ActiveCam::Helico; } else { #if SIG_DEVELOPER trace('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); UI::ShowNotification('1 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); #endif - g_activeCam = ActiveCam::Other; + g_activeCameraType = ActiveCam::Other; } } else if (camControlNod !is null) { auto ty = Reflection::TypeOf(camControlNod); if (ty.ID == ClsId_CGameControlCameraFree) { - g_activeCam = ActiveCam::FreeCam; + g_activeCameraType = ActiveCam::FreeCam; } else if (ty.ID == ClsId_CGameControlCameraEditorOrbital) { - g_activeCam = ActiveCam::EditorOrbital; + g_activeCameraType = ActiveCam::EditorOrbital; } else if (ty.ID == ClsId_CGameControlCameraOrbital3d) { - g_activeCam = ActiveCam::Orbital3d; + g_activeCameraType = ActiveCam::Orbital3d; } else if (ty.ID == ClsId_CGameControlCameraHelico) { - g_activeCam = ActiveCam::Helico; + g_activeCameraType = ActiveCam::Helico; } else if (ty.ID == ClsId_CGameControlCameraHmdExternal) { - g_activeCam = ActiveCam::HmdExternal; + g_activeCameraType = ActiveCam::HmdExternal; } else if (ty.ID == ClsId_CGameControlCameraThirdPerson) { - g_activeCam = ActiveCam::ThirdPerson; + g_activeCameraType = ActiveCam::ThirdPerson; } else if (ty.ID == ClsId_CGameControlCameraFirstPerson) { - g_activeCam = ActiveCam::FirstPerson; + g_activeCameraType = ActiveCam::FirstPerson; } else if (ty.ID == ClsId_CGameControlCameraTarget) { - g_activeCam = ActiveCam::Target; + g_activeCameraType = ActiveCam::Target; } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace) { - g_activeCam = ActiveCam::Cam0; + g_activeCameraType = ActiveCam::Cam0; } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace2) { - g_activeCam = ActiveCam::Cam1; + g_activeCameraType = ActiveCam::Cam1; } else if (ty.ID == ClsId_CGameControlCameraTrackManiaRace3) { - g_activeCam = ActiveCam::Cam2; + g_activeCameraType = ActiveCam::Cam2; } else if (ty.ID == ClsId_CGameControlCameraVehicleInternal) { - g_activeCam = ActiveCam::Cam3; + g_activeCameraType = ActiveCam::Cam3; } else if (ty.ID == ClsId_CGameControlCamera) { // We probably won't ever end up here, but just in case. - g_activeCam = ActiveCam::Other; + g_activeCameraType = ActiveCam::Other; } else { // debug so we know that a cam is unknown #if SIG_DEVELOPER trace('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); UI::ShowNotification('2 Got cam of unknown type: ' + ty.ID + ', ' + ty.Name); #endif - g_activeCam = ActiveCam::Other; + g_activeCameraType = ActiveCam::Other; } } else { // initalizing editor, when in mediatracker - g_activeCam = ActiveCam::Loading; + g_activeCameraType = ActiveCam::Loading; } } diff --git a/Impl.as b/Impl.as index 45c8cb6..069a04e 100644 --- a/Impl.as +++ b/Impl.as @@ -80,6 +80,6 @@ namespace Camera ActiveCam GetCurrentGameCamera() { - return g_activeCam; + return g_activeCameraType; } } diff --git a/Main.as b/Main.as index 7601619..6256035 100644 --- a/Main.as +++ b/Main.as @@ -8,7 +8,7 @@ vec3 g_direction = vec3(); vec2 g_displayPos; vec2 g_displaySize; -ActiveCam g_activeCam = ActiveCam::None; +ActiveCam g_activeCameraType = ActiveCam::None; void RenderEarly() {