Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Oct 22, 2022
2 parents b43c88d + cd649e5 commit be929f5
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="MessagePack" Version="2.3.85" />
<PackageReference Include="MessagePackAnalyzer" Version="2.3.85" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="Reloaded.Memory" Version="4.1.1" />
<PackageReference Include="Reloaded.Memory" Version="5.1.0" />
<PackageReference Include="Reloaded.WPF.Animations" Version="1.2.3" />
<PackageReference Include="StructLinq" Version="0.27.1" />
<PackageReference Include="ToString.Fody" Version="1.11.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,11 @@ public unsafe void ToGame(in int index)
player.MaybeAttackLastState = PlayerState.None;

// Game removes floor flag
if (player.PlayerState == PlayerState.Running || player.PlayerState == PlayerState.RunningAfterStart || player.PlayerState == PlayerState.NormalOnBoard)
if (player.PlayerState is PlayerState.Running or PlayerState.RunningAfterStart or PlayerState.NormalOnBoard)
{
player.PlayerControlFlags |= PlayerControlFlags.IsFloored;
player.FallingMode = FallingMode.Ground;
}

// TODO: The flag below can cause the game to crash for unexpected reasons; we're removing it for now.
// player.PlayerControlFlags &= ~PlayerControlFlags.TurbulenceHairpinTurnSymbol;
}

public bool IsDefault() => this.Equals(new UnreliablePacketPlayer());
Expand Down
2 changes: 1 addition & 1 deletion Riders.Tweakbox.Interfaces/Structs/DashPanelProperties.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.InteropServices;
namespace Riders.Tweakbox.Interfaces.Structs;

// TODO: Remove this when removing legacy physics config support
// TODO: Remove this (structlayout) when removing legacy physics config support
[StructLayout(LayoutKind.Explicit, Size = 0x40)]
public struct DashPanelProperties
{
Expand Down
2 changes: 1 addition & 1 deletion Riders.Tweakbox.Interfaces/Structs/DecelProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
namespace Riders.Tweakbox.Interfaces.Structs;

// TODO: Remove this when removing legacy physics config support
// TODO: Remove this (structlayout) when removing legacy physics config support
[StructLayout(LayoutKind.Explicit, Size = 0x40)]
public struct DecelProperties
{
Expand Down
2 changes: 1 addition & 1 deletion Riders.Tweakbox.Interfaces/Structs/SpeedShoeProperties.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.InteropServices;
namespace Riders.Tweakbox.Interfaces.Structs;

// TODO: Remove this when removing legacy physics config support
// TODO: Remove this (structlayout) when removing legacy physics config support
[StructLayout(LayoutKind.Explicit, Size = 0x40)]
public struct SpeedShoeProperties
{
Expand Down
7 changes: 4 additions & 3 deletions Riders.Tweakbox/Components/Editors/Layout/LayoutEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public unsafe class LayoutEditor : ComponentBase, IComponent
private NetplayController _netplayController = IoC.Get<NetplayController>();
private int _currentAutosaveFrames = 0;
private Autosaver _autoSaver;
private bool _importBigEndian;

public LayoutEditor(MiscPatchController patchController, ObjectLayoutController layoutController, IO io)
{
Expand Down Expand Up @@ -97,7 +98,6 @@ private void RenderInternal(float contentRegionWidth)
}

// Create Headers
// TODO: Re-add Type when they become relevant.
ImGui.TableSetupColumn("Name", 0, 0, 0);
ImGui.TableSetupScrollFreeze(1, 1);

Expand Down Expand Up @@ -317,6 +317,8 @@ private void RenderObject(SetObject* item, float availableWidth)
});
}

ImGui.SameLine(0, Constants.Spacing);
ImGui.Checkbox("Import Big Endian (GCN)", ref _importBigEndian);
ImGui.SameLine(0, Constants.Spacing);
if (ImGui.Button("Import from File & Restart", Constants.Zero))
{
Expand All @@ -325,14 +327,13 @@ private void RenderObject(SetObject* item, float availableWidth)
saveFileDialog.FileName = "00000.bin";
var result = saveFileDialog.ShowDialog();
if (result == true && !string.IsNullOrEmpty(saveFileDialog.FileName))
_layoutController.ImportAndRestart(File.ReadAllBytes(saveFileDialog.FileName));
_layoutController.ImportAndRestart(File.ReadAllBytes(saveFileDialog.FileName), _importBigEndian);
}

ImGui.SameLine(0, Constants.Spacing);
if (ImGui.Button("Fast Restart", Constants.Zero))
_layoutController.FastRestart();

ImGui.SameLine(0, Constants.Spacing);
ImGui.Checkbox("Safe Mode", ref _safeMode);
Tooltip.TextOnHover("Prevents from writing to object data when moving objects.\n" +
"Use this to avoid potential crashes, at expense of no real time render position update.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ public class AntiIntegrity : INetplayComponent
public Socket Socket { get; set; }

/// <inheritdoc />
public void Dispose()
{
throw new NotImplementedException();
}
public void Dispose() => throw new NotImplementedException();

/// <inheritdoc />
public void HandleReliablePacket(ref ReliablePacket packet, NetPeer source)
{
throw new NotImplementedException();
}
public void HandleReliablePacket(ref ReliablePacket packet, NetPeer source) => throw new NotImplementedException();

/// <inheritdoc />
public void HandleUnreliablePacket(ref UnreliablePacket packet, NetPeer source)
{
throw new NotImplementedException();
}
public void HandleUnreliablePacket(ref UnreliablePacket packet, NetPeer source) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ public class AntiPlayerStats : INetplayComponent
public Socket Socket { get; set; }

/// <inheritdoc />
public void Dispose()
{
throw new NotImplementedException();
}
public void Dispose() => throw new NotImplementedException();

/// <inheritdoc />
public void HandleReliablePacket(ref ReliablePacket packet, NetPeer source)
{
throw new NotImplementedException();
}
public void HandleReliablePacket(ref ReliablePacket packet, NetPeer source) => throw new NotImplementedException();

/// <inheritdoc />
public void HandleUnreliablePacket(ref UnreliablePacket packet, NetPeer source)
{
throw new NotImplementedException();
}
public void HandleUnreliablePacket(ref UnreliablePacket packet, NetPeer source) => throw new NotImplementedException();
}
3 changes: 0 additions & 3 deletions Riders.Tweakbox/Components/Netplay/Components/Misc/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ private void HostOnSeedRandom(uint seed, IHook<Functions.SRandFnPtr> hook)
_itemPickupRandom = new System.Random((int)seed);
IFileService.SeedAll((int)seed);

// TODO: Handle error when time component is not available.

// Multiply the highest recently recorded Round Trip Time and multiply by 2 in case of spike.
// Should be good enough as long as RecentLatencies is a list long enough.
if (Socket.HostState.ClientInfo.Length > 0)
Expand All @@ -176,7 +174,6 @@ private void ClientOnSeedRandom(uint seed, IHook<Functions.SRandFnPtr> hook)
return;
}

// TODO: Handle error when time component is not available.
var srand = _currentSync.Value;
_currentSync = null;

Expand Down
9 changes: 4 additions & 5 deletions Riders.Tweakbox/Components/Netplay/Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ public void DisconnectWithMessage(NetPeer peer, string message)
/// <param name="spinTime">The amount of time in milliseconds before event expired to start spinning.</param>
public void WaitWithSpin(DateTime waitUntil, string eventName = "", LogCategory eventCategory = LogCategory.Socket, int spinTime = 100)
{
// TODO: Negotiation between multiple clients on current time so WaitUntil matches.
Log.WriteLine($"[Socket] Waiting for event ({eventName}).", eventCategory);
Log.WriteLine($"[Socket] Time: {DateTime.UtcNow}", eventCategory);
Log.WriteLine($"[Socket] Start Time: {waitUntil}:{waitUntil.TimeOfDay.Milliseconds:000}", eventCategory);
Expand All @@ -451,12 +450,12 @@ public void WaitWithSpin(DateTime waitUntil, string eventName = "", LogCategory
if (timeLeft.Milliseconds < 0)
return true;

// Check if should sleep.
if (timeLeft.Milliseconds > spinTime)
// Check if should sleep.
if (timeLeft.Milliseconds > spinTime)
return false;

// Spin for remaining time.
do { timeLeft = waitUntil - DateTime.UtcNow; }
// Spin for remaining time.
do { timeLeft = waitUntil - DateTime.UtcNow; }
while (timeLeft.Ticks > 0);

return true;
Expand Down
1 change: 0 additions & 1 deletion Riders.Tweakbox/Components/Tweaks/TextureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ private unsafe void ShowTextureMenu()
if (ImGui.__Internal.BeginTable("texture_table", 1, tableFlags, textureTableSize, 0))
{
// Create Headers
// TODO: Re-add Type when they become relevant.
ImGui.TableSetupColumn("Texture", 0, 0, 0);
ImGui.TableSetupScrollFreeze(1, 1);

Expand Down
1 change: 0 additions & 1 deletion Riders.Tweakbox/Controllers/NetplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public async Task<bool> ConnectAsync(string address, int port, bool hasPassword)
// Get Password if Lobby Defines one is Needed.
if (hasPassword)
{
// TODO: Query for Password
var inputData = new TextInputData(NetplayEditorConfig.TextLength);
await Shell.AddDialogAsync("Enter Password", (ref bool opened) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ public byte[] Export(bool bigEndian = false)
/// Disposes of all layouts and imports a new layout from file.
/// Then restarts the stage.
/// </summary>
public void ImportAndRestart(byte[] data)
public void ImportAndRestart(byte[] data, bool bigEndian)
{
var loadedLayout = new LoadedLayoutFile(data);
var loadedLayout = new LoadedLayoutFile(data, bigEndian);

// Kill all existing layouts.
DisposeAllLayouts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private LoadedLayoutFile ReplaceStageLayout(int stageid)
{
var layout = _layoutService.GetRandomLayoutForStage(stageid, true);
if (!string.IsNullOrEmpty(layout))
return new LoadedLayoutFile(File.ReadAllBytes(layout));
return new LoadedLayoutFile(File.ReadAllBytes(layout), false);

return _objectLayoutController.OriginalLayout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public unsafe class LoadedLayoutFile : IDisposable

public LoadedLayoutFile(InMemoryLayoutFile layoutFile, bool ownsMemory = false) { Init(layoutFile, ownsMemory); }

public LoadedLayoutFile(byte[] data)
public LoadedLayoutFile(byte[] data, bool bigEndian)
{
// Copy layout data.
var alloc = Marshal.AllocHGlobal(data.Length);
fixed (byte* dataPtr = &data[0])
Unsafe.CopyBlockUnaligned((void*)alloc, dataPtr, (uint)data.Length);

// Open layout data
Init(new InMemoryLayoutFile((void*)alloc), true);
Init(new InMemoryLayoutFile((void*)alloc, bigEndian), true);
LayoutFile.Header->Magic = 0; // Loaded.
}

Expand Down
Loading

0 comments on commit be929f5

Please sign in to comment.