Skip to content

Commit

Permalink
Update ControllerHook & Fix Control Bug on Toggle Hud/Freeze Cam
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Nov 1, 2019
1 parent 111ba10 commit 7344c59
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Submodules/Heroes.Controller.Hook.ReloadedII
Submodule Heroes.Controller.Hook.ReloadedII updated 44 files
+3 −0 .gitmodules
+3 −1 Heroes.Controller.Hook.Interfaces/Definitions/ButtonFlags.cs
+5 −1 Heroes.Controller.Hook.Interfaces/Heroes.Controller.Hook.Interfaces.csproj
+4 −5 Heroes.Controller.Hook.Interfaces/IControllerHook.cs
+16 −3 Heroes.Controller.Hook.Interfaces/IExtendedHeroesController.cs
+13 −13 Heroes.Controller.Hook.Interfaces/IInputs.cs
+2 −1 Heroes.Controller.Hook.PostProcess/Config.cs
+64 −0 Heroes.Controller.Hook.PostProcess/Configuration/Configurator.cs
+2 −2 Heroes.Controller.Hook.PostProcess/Heroes.Controller.Hook.PostProcess.csproj
+0 −19 Heroes.Controller.Hook.PostProcess/Json/ConfigReadWriter.cs
+2 −2 Heroes.Controller.Hook.PostProcess/ModConfig.json
+9 −5 Heroes.Controller.Hook.PostProcess/PostProcess.cs
+4 −3 Heroes.Controller.Hook.PostProcess/Program.cs
+2 −0 Heroes.Controller.Hook.PostProcess/Structures/StickDeadzone.cs
+4 −2 Heroes.Controller.Hook.PostProcess/Structures/TriggerDeadzone.cs
+71 −0 Heroes.Controller.Hook.Shared/Configuration/Configurable.cs
+3 −2 Heroes.Controller.Hook.Shared/Heroes.Controller.Hook.Shared.csproj
+0 −41 Heroes.Controller.Hook.Shared/JsonSerializable.cs
+5 −1 Heroes.Controller.Hook.XInput/Config.cs
+61 −0 Heroes.Controller.Hook.XInput/Configuration/Configurator.cs
+18 −0 Heroes.Controller.Hook.XInput/ControllerConfigTuple.cs
+3 −2 Heroes.Controller.Hook.XInput/Converter.cs
+0 −41 Heroes.Controller.Hook.XInput/Help/Buttons.cs
+2 −2 Heroes.Controller.Hook.XInput/Heroes.Controller.Hook.XInput.csproj
+0 −20 Heroes.Controller.Hook.XInput/Json/ConfigReadWriter.cs
+2 −2 Heroes.Controller.Hook.XInput/ModConfig.json
+4 −5 Heroes.Controller.Hook.XInput/Program.cs
+24 −19 Heroes.Controller.Hook.XInput/XInput.cs
+17 −6 Heroes.Controller.Hook.sln
+17 −0 Heroes.Controller.Hook/Config.cs
+64 −0 Heroes.Controller.Hook/Configuration/Configurator.cs
+35 −38 Heroes.Controller.Hook/ControllerHook.cs
+5 −14 Heroes.Controller.Hook/Heroes.Controller.Hook.csproj
+0 −121 Heroes.Controller.Hook/Heroes/HeroesController.cs
+0 −21 Heroes.Controller.Hook/Heroes/HeroesControllerFactory.cs
+0 −35 Heroes.Controller.Hook/Heroes/SkyPad.cs
+2 −2 Heroes.Controller.Hook/ModConfig.json
+9 −3 Heroes.Controller.Hook/Program.cs
+20 −18 Heroes.Controller.Hook/ReloadedController.cs
+8 −7 Heroes.Controller.Hook/Structs/ExtendedHeroesController.cs
+89 −0 Heroes.Controller.Hook/Structs/Inputs.cs
+0 −31 Heroes.Controller.Hook/Utility.cs
+1 −1 README.md
+1 −0 Submodules/Heroes.SDK
36 changes: 21 additions & 15 deletions sonicheroes.utils.freecam/Freecam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Runtime.CompilerServices;
using System.Text;
using Heroes.Controller.Hook.Interfaces;
using Heroes.Controller.Hook.Interfaces.Enums;
using Heroes.Controller.Hook.Interfaces.Definitions;
using Heroes.Controller.Hook.Interfaces.Structures;
using Heroes.Controller.Hook.Interfaces.Structures.Interfaces;
using Reloaded.Hooks.ReloadedII.Interfaces;
using SharpDX;

namespace sonicheroes.utils.freecam
{
Expand Down Expand Up @@ -46,7 +48,7 @@ public void Resume()
}

/* Controller Handler */
private void OnInput(ExtendedHeroesController inputs, int port)
private void OnInput(IExtendedHeroesController inputs, int port)
{
// Only process inputs ingame.
if (port != _port)
Expand Down Expand Up @@ -78,15 +80,15 @@ private void OnInput(ExtendedHeroesController inputs, int port)
}
}

private void HandleFreeMode(ref ExtendedHeroesController inputs)
private void HandleFreeMode(ref IExtendedHeroesController inputs)
{
// Camera Movement Sticks
_heroesController.MoveForward(inputs.LeftStickY * -1);
_heroesController.MoveLeft(inputs.LeftStickX * -1);

// Camera Rotation Sticks
_heroesController.RotateUp(inputs.RightStickY * -1);
_heroesController.RotateRight(inputs.RightStickX * -1);
var vector = new Vector3(inputs.RightStickX * -1, inputs.RightStickY * -1, 0);
_heroesController.Rotate(ref vector);

// Camera Roll Triggers
// Note: The game sets Camera L/R button flags if the pressure is above 0.
Expand Down Expand Up @@ -127,19 +129,23 @@ private void HandleFreeMode(ref ExtendedHeroesController inputs)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.DpadLeft))
_heroesController.RotateSpeed -= (_heroesController.RotateSpeed * 0.011619440F);

// Reset Camera (X)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.Action))
_heroesController.ResetCamera();

// Toggle HUD (B)
if (ButtonPressed(inputs.OneFramePressButtonFlag, ButtonFlags.FormationR))
// Ignore if modifier key is held.
if (!ButtonPressed(inputs.ButtonFlags, ButtonFlags.TeamBlast))
{
_heroesController.EnableHud = !_heroesController.EnableHud;
// Toggle HUD (B)
if (ButtonPressed(inputs.OneFramePressButtonFlag, ButtonFlags.FormationR))
{
_heroesController.EnableHud = !_heroesController.EnableHud;
}

// Teleport Character (A)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.Jump))
_heroesController.TeleportCharacterToCamera();
}

// Teleport Character (A)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.Jump))
_heroesController.TeleportCharacterToCamera();
// Reset Camera (X)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.Action))
_heroesController.ResetCamera();

// Reset Roll (Y)
if (ButtonPressed(inputs.ButtonFlags, ButtonFlags.FormationL))
Expand Down
39 changes: 19 additions & 20 deletions sonicheroes.utils.freecam/HeroesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Reloaded.Hooks.Definitions;
using Reloaded.Hooks.Definitions.X86;
Expand All @@ -7,6 +8,7 @@
using sonicheroes.utils.freecam.Enums;
using sonicheroes.utils.freecam.Structs;
using sonicheroes.utils.freecam.Utilities;
using IReloadedHooks = Reloaded.Hooks.ReloadedII.Interfaces.IReloadedHooks;

namespace sonicheroes.utils.freecam
{
Expand Down Expand Up @@ -174,29 +176,26 @@ public void MoveUp(float speed)
// B. Rotate the said direction by the current roll.
// C. Apply rotation.

public void RotateUp(float speed)
public void Rotate(ref Vector3 rotation)
{
Vector3 upVector = new Vector3(0, speed * RotateSpeed, 0);
upVector = RotateVectorAboutZ(ref upVector, -1 * _camera[0].RotationRoll);
Vector3 rotationVector = new Vector3(rotation.X * RotateSpeed, rotation.Y * RotateSpeed, 0);
rotationVector = RotateVectorAboutZ(ref rotationVector, -1 * _camera[0].RotationRoll);

_camera[0].RotationVertical += upVector.Y;
_camera[0].RotationHorizontal += upVector.X;
if (IsUpsideDown(_camera[0].RotationVertical))
rotationVector.X *= -1;

_camera[0].RotationVertical += rotationVector.Y;
_camera[0].RotationHorizontal += rotationVector.X;
}

public void RotateRight(float speed)
private bool IsUpsideDown(float rotationVerticalDegrees)
{
// "CAST" If the vertical angle is between 90 and 270 degrees, reverse direction.
if (_camera[0].RotationVertical > 90F && _camera[0].RotationVertical < 270F ||
_camera[0].RotationVertical < -90F && _camera[0].RotationVertical > -270F)
{
speed *= -1;
}

Vector3 rightVector = new Vector3(speed * RotateSpeed, 0, 0);
rightVector = RotateVectorAboutZ(ref rightVector, -1 * _camera[0].RotationRoll);
return IsBetween(90F, 270F, rotationVerticalDegrees);
}

_camera[0].RotationVertical += rightVector.Y;
_camera[0].RotationHorizontal += rightVector.X;
private bool IsBetween(float x, float y, float value)
{
return (x <= value && value <= y);
}

public void RotateRoll(float speed)
Expand All @@ -206,9 +205,9 @@ public void RotateRoll(float speed)

public void TeleportCharacterToCamera()
{
(*_characters).LeaderCharacter->positionX = _camera[0].CameraX;
(*_characters).LeaderCharacter->positionY = _camera[0].CameraY;
(*_characters).LeaderCharacter->positionZ = _camera[0].CameraZ;
(*_characters).LeaderCharacter->PositionX = _camera[0].CameraX;
(*_characters).LeaderCharacter->PositionY = _camera[0].CameraY;
(*_characters).LeaderCharacter->PositionZ = _camera[0].CameraZ;
}

// Scales camera vectors to set move speed.
Expand Down
2 changes: 1 addition & 1 deletion sonicheroes.utils.freecam/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ModId": "sonicheroes.utils.freecam",
"ModName": "Heroes Freecam",
"ModAuthor": "Sewer56",
"ModVersion": "1.0.4",
"ModVersion": "1.0.5",
"ModDescription": "A free camera for the PC version of Sonic Heroes. Provides additional utilities like freezing world, teleporting and removing HUD.",
"ModDll": "sonicheroes.utils.freecam.dll",
"ModIcon": "Preview.png",
Expand Down
67 changes: 38 additions & 29 deletions sonicheroes.utils.freecam/Structs/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace sonicheroes.utils.freecam.Structs
{
public struct Character
/// <summary>
/// Note: This is not one big structs but a series of smaller structs accessed via both pointer to this and structs inside.
/// </summary>
public unsafe struct Character
{
public int field_0;
public int field_4;
public int field_8;
public int field_C;
public int velocityXPlus10;
public int field_10;
public int field_14;
public int field_18;
Expand All @@ -29,27 +32,32 @@ public struct Character
public int field_50;
public int field_54;
public int field_58;
public int field_5C;
public int field_60;
public int field_64;
public float PositionXCopyAnother;
public float PositionYCopyAnother;
public float PositionZCopyAnother;
public int field_68;
public int field_6C;
public int field_70;
public int field_74;
public int field_78;
public int field_7C;
public int field_80;
public int field_84;
public int field_88;
public int RotationXCopy;
public int RotationYCopy;

/// <summary>
/// Index of the character in the playerTOp array.
/// </summary>
public int PlayerTopIndex;

public float PositionXCopy;
public float PositionYCopy;
public float PositionZCopy;
public int* PointerSomeFilesMaybe;
public int field_8C;
public int field_90;
public int field_94;
public int field_98;
public int field_9C;
public int field_A0;
public int PointerSomeDataMaybe;
public int field_A4;
public int field_A8;
public int field_AC;
public int FramesInAir;
public int FramesIdle;
public int field_B0;
public int field_B4;
public int field_B8;
Expand All @@ -62,20 +70,21 @@ public struct Character
public int field_D0;
public int field_D4;
public int field_D8;
public float velocityX;
public float velocityY;
public float velocityZ;
public float positionX;
public float positionY;
public float positionZ;
public float VelocityX;
public float VelocityY;
public float VelocityZ;
public float PositionX;
public float PositionY;
public float PositionZ;
public int field_F4;
public float rotationX;
public float rotationY;
public float rotationZ;
public float thicknessX;
public float thicknessY;
public float teamMateFollowingSomething1;
public float teamMateFollowingSomething2;
public float teamMateFollowingSomething3;
public float RotationX;
public float RotationY;
public float RotationZ;
public float ThicknessY;
public float ThicknessZ;
public float TeamMateFollowingSomething1;
public float TeamMateFollowingSomething2;
public float TeamMateFollowingSomething3;
}
}

38 changes: 18 additions & 20 deletions sonicheroes.utils.freecam/Structs/HeroesCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace sonicheroes.utils.freecam.Structs
{
[StructLayout(LayoutKind.Sequential, Size = 0x2324)]
public struct HeroesCamera
{
/* Camera Location */
Expand All @@ -15,9 +16,9 @@ public struct HeroesCamera
private float _cameraZ;

/* Range 0 - 65535 */
private int _angleVerticalBams;
private int _angleHorizontalBams;
private int _angleRollBams;
public uint AngleVerticalBams;
public uint AngleHorizontalBams;
public uint AngleRollBams;

private int _float18;
private int _float1C;
Expand Down Expand Up @@ -47,23 +48,20 @@ public float CameraZ

public float RotationHorizontal
{
get => BAMSToDegrees(_angleHorizontalBams);
set => _angleHorizontalBams = DegreesToBAMS(value % 360F);
get => BAMSToDegrees(AngleHorizontalBams);
set => AngleHorizontalBams = DegreesToBAMS(value);
}

public float RotationVertical
{
// Do not allow camera to go beyond 90 degrees.
// We have roll if we want to go up-side down.

get => BAMSToDegrees(_angleVerticalBams);
set => _angleVerticalBams = DegreesToBAMS(value % 360);
get => BAMSToDegrees(AngleVerticalBams);
set => AngleVerticalBams = DegreesToBAMS(value);
}

public float RotationRoll
{
get => BAMSToDegrees(_angleRollBams);
set => _angleRollBams = DegreesToBAMS(value % 360F);
get => BAMSToDegrees(AngleRollBams);
set => AngleRollBams = DegreesToBAMS(value);
}

public float LookAtX
Expand All @@ -89,12 +87,12 @@ public float LookAtZ
// Rotation/Direction Methods
public CameraVectors GetCameraVectors()
{
return CameraVectors.FromYawPitchRoll(BAMSToRadians(_angleHorizontalBams), BAMSToRadians(_angleVerticalBams), BAMSToRadians(_angleRollBams));
return CameraVectors.FromYawPitchRoll(BAMSToRadians(AngleHorizontalBams), BAMSToRadians(AngleVerticalBams), BAMSToRadians(AngleRollBams));
}

public Vector3 GetYawPitchRollRadians()
{
return new Vector3(BAMSToRadians(_angleHorizontalBams), BAMSToRadians(_angleVerticalBams), BAMSToRadians(_angleRollBams));
return new Vector3(BAMSToRadians(AngleHorizontalBams), BAMSToRadians(AngleVerticalBams), BAMSToRadians(AngleRollBams));
}

// Move/Rotate Methods
Expand Down Expand Up @@ -126,19 +124,19 @@ public void RotateCameraRadians(ref Vector3 vector)
}

/* BAMS To Degrees Conversion */
private int DegreesToBAMS(float degrees)
private uint DegreesToBAMS(float degrees)
{
return (int)((degrees / 360F) * 65535F);
return (uint)(((degrees % 360F) / 360F) * 65535F);
}

private float BAMSToDegrees(int bams)
private float BAMSToDegrees(uint bams)
{
return (bams / 65535F) * 360F;
return ((bams % 65535F) / 65535F) * 360F;
}

private float BAMSToRadians(int bams)
private float BAMSToRadians(uint bams)
{
return (float) ((bams / 65535F) * (Math.PI * 2));
return (float) (((bams % 65535F) / 65535F) * (Math.PI * 2));
}
}
}
6 changes: 3 additions & 3 deletions sonicheroes.utils.freecam/sonicheroes.utils.freecam.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down Expand Up @@ -33,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Mod.Interfaces" Version="1.3.0" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.0.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="1.5.0" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
</ItemGroup>

Expand Down

0 comments on commit 7344c59

Please sign in to comment.