Skip to content

Commit

Permalink
Merge pull request #1268 from AsgardXIV/timecontrol
Browse files Browse the repository at this point in the history
Allow Time Control in GPose
  • Loading branch information
Luminiari authored Jan 10, 2023
2 parents 1a5eb41 + 7c7118a commit bb4e001
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 79 deletions.
8 changes: 3 additions & 5 deletions Anamnesis/Core/Memory/AddressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AddressService : ServiceBase<AddressService>
public static IntPtr Territory { get; private set; }
public static IntPtr GPose { get; private set; }
public static IntPtr TimeAsm { get; private set; }
public static IntPtr TimeReal { get; set; }
public static IntPtr Framework { get; set; }
public static IntPtr PlayerTargetSystem { get; set; }
public static IntPtr AnimationSpeedPatch { get; set; }

Expand Down Expand Up @@ -153,15 +153,13 @@ private async Task Scan()
}));

tasks.Add(this.GetAddressFromTextSignature(
"Time",
"Framework",
"48 C7 05 ?? ?? ?? ?? 00 00 00 00 E8 ?? ?? ?? ?? 48 8D ?? ?? ?? 00 00 E8 ?? ?? ?? ?? 48 8D",
(p) =>
{
int frameworkOffset = MemoryService.Read<int>(p + 3);
IntPtr frameworkPtr = MemoryService.ReadPtr(p + 11 + frameworkOffset);
TimeReal = frameworkPtr + 0x1770;

// For reference, gpose time is at frameworkPtr + 0x1798 if it's ever needed
Framework = frameworkPtr;
}));

tasks.Add(this.GetAddressFromTextSignature("SkeletonFreezePhysics (1/2/3)", "0F 29 48 10 41 0F 28 44 24 20 0F 29 40 20 48 8B 46", (p) =>
Expand Down
16 changes: 16 additions & 0 deletions Anamnesis/Memory/FrameworkMemory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// © Anamnesis.
// Licensed under the MIT license.

namespace Anamnesis.Memory;

public class FrameworkMemory : MemoryBase
{
[Bind(0x1770)]
public long EorzeaTime { get; set; }

[Bind(0x1798)]
public long OverrideEorzeaTime { get; set; }

[Bind(0x17A0)]
public bool IsTimeOverridden { get; set; }
}
58 changes: 0 additions & 58 deletions Anamnesis/Memory/TimeMemory.cs

This file was deleted.

36 changes: 22 additions & 14 deletions Anamnesis/Services/TimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ namespace Anamnesis;
[AddINotifyPropertyChangedInterface]
public class TimeService : ServiceBase<TimeService>
{
private TimeMemory? timeMemory;
private FrameworkMemory? frameworkMemory;
private NopHookViewModel? timeAsmHook;
public string TimeString { get; private set; } = "00:00";
public long TimeOfDay { get; set; }
public byte DayOfMonth { get; set; }

public bool Freeze
{
get => this.timeMemory?.Freeze ?? false;
set => this.timeMemory?.SetFrozen(value);
get => this.timeAsmHook?.Enabled ?? false;
set => this.timeAsmHook?.SetEnabled(value);
}

public override Task Start()
{
this.timeMemory = new TimeMemory();
this.timeAsmHook = new NopHookViewModel(AddressService.TimeAsm, 0x07);

this.frameworkMemory = new FrameworkMemory();
this.frameworkMemory.SetAddress(AddressService.Framework);

_ = Task.Run(this.CheckTime);

Expand All @@ -48,29 +52,33 @@ private async Task CheckTime()

try
{
if (!MemoryService.IsProcessAlive || !GameService.Instance.IsSignedIn || AddressService.TimeReal == IntPtr.Zero)
if (!MemoryService.IsProcessAlive || !GameService.Instance.IsSignedIn || this.frameworkMemory == null)
{
if (this.Freeze)
this.Freeze = false;

continue;
}

this.frameworkMemory.Tick();

if (this.Freeze)
{
long newTime = (long)((this.TimeOfDay * 60) + (86400 * (this.DayOfMonth - 1)));
this.timeMemory?.SetTime(newTime);
}
else
{
long timeVal = this.timeMemory!.CurrentTime % 2764800;
long secondInDay = timeVal % 86400;
this.TimeOfDay = (long)(secondInDay / 60f);
this.DayOfMonth = (byte)(Math.Floor(timeVal / 86400f) + 1);

this.frameworkMemory.EorzeaTime = newTime;

if(this.frameworkMemory.IsTimeOverridden)
this.frameworkMemory.OverrideEorzeaTime = newTime;
}

var displayTime = TimeSpan.FromMinutes(this.TimeOfDay);
long currentTime = this.frameworkMemory.IsTimeOverridden ? this.frameworkMemory.OverrideEorzeaTime : this.frameworkMemory.EorzeaTime;
long timeVal = currentTime % 2764800;
long secondInDay = timeVal % 86400;
this.TimeOfDay = (long)(secondInDay / 60f);
this.DayOfMonth = (byte)(Math.Floor(timeVal / 86400f) + 1);

var displayTime = TimeSpan.FromMinutes(this.TimeOfDay);
this.TimeString = string.Format("{0:D2}:{1:D2}", displayTime.Hours, displayTime.Minutes);
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions Anamnesis/Tabs/HomeTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
Key="Scene_World_Time"
Style="{StaticResource Label}" />
<XivToolsWpf:NumberBox Minimum="0"
Maximum="1440"
Maximum="1439"
Grid.Column="2"
Value="{Binding TimeService.TimeOfDay}"
Margin="3"
Expand All @@ -123,7 +123,7 @@
Buttons="True"
Slider="Absolute"
Minimum="1"
Maximum="32" />
Maximum="31" />
</Grid>

<XivToolsWpf:TextBlock Grid.Row="1"
Expand Down

0 comments on commit bb4e001

Please sign in to comment.