Skip to content

Commit

Permalink
stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Deliay committed Jul 23, 2020
1 parent 8059d38 commit 411c9cd
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class MemoryReaderHandler :
IEventHandler<BeatmapInfo>,
IEventHandler<PlayingInfo>,
IEventHandler<MultiplayerBeatmapIdInfo>,
IEventHandler<GameModeInfo>
IEventHandler<GameModeInfo>,
IEventHandler<GlobalGameModeratorInfo>
{
private readonly ILogger<MemoryReaderHandler> _logger;
private readonly IPluginOptions<MyPlugin, MyPluginConfiguration> _pluginOptions;
Expand Down Expand Up @@ -80,5 +81,11 @@ public ValueTask Handle(GameModeInfo @event)
}
return default;
}

public ValueTask Handle(GlobalGameModeratorInfo @event)
{
_logger.LogInformation($"[Event] Current Moderator = {@event.GlobalRawModerator}");
return default;
}
}
}
3 changes: 3 additions & 0 deletions src/plugins/ExamplePlugin/MyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override ValueTask Initialize(ILifetimeScope scope)
scope.Subscription<PlayingInfo, MemoryReaderHandler>();
scope.Subscription<MultiplayerBeatmapIdInfo, MemoryReaderHandler>();
scope.Subscription<GameModeInfo, MemoryReaderHandler>();
scope.Subscription<GlobalGameModeratorInfo, MemoryReaderHandler>();
scope.RegisterUIModel<MyPlugin, MyPluginConfiguration>();
return default;
}
Expand All @@ -38,6 +39,8 @@ public override ValueTask Uninitialize(ILifetimeScope scope)
scope.Unsubscription<BeatmapInfo, MemoryReaderHandler>();
scope.Unsubscription<PlayingInfo, MemoryReaderHandler>();
scope.Unsubscription<MultiplayerBeatmapIdInfo, MemoryReaderHandler>();
scope.Unsubscription<GameModeInfo, MemoryReaderHandler>();
scope.Unsubscription<GlobalGameModeratorInfo, MemoryReaderHandler>();
scope.UnregisterUIModel<MyPlugin, MyPluginConfiguration>();
return default;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using EmberKernel.Services.EventBus;
using EmberMemory.Components.Collector;
using EmberMemory.Readers;
using System;

namespace EmberMemoryReader.Abstract.Data
{
public class GlobalGameModerator : IComparableCollector<GlobalGameModeratorInfo>
{

private static readonly string GlobalModsPattern = "\x8B\xF1\xA1\x00\x00\x00\x00\x25\x00\x00\x40\x00\x85\xC0";
private static readonly string GlobalModsMask = "xxx????xxxxxxx";

public int ReadInterval { get; set; } = 500;
public int RetryLimit { get; set; } = int.MaxValue;

private DirectMemoryReader Reader { get; }
public GlobalGameModerator(DirectMemoryReader reader)
{
Reader = reader;
}

private IntPtr ModAddress;
public bool TryInitialize()
{
try
{
Reader.Reload();
Reader.TryFindPattern(GlobalModsPattern.ToBytes(), GlobalModsMask, 3, out ModAddress);
if (!Reader.TryReadIntPtr(ModAddress, out ModAddress)) return false;
return true;
}
finally
{
Reader.ResetRegion();
}
}

public bool TryRead(out Event result)
{
if (Reader.TryReadInt(ModAddress, out var listeningMods))
{
result = new GlobalGameModeratorInfo() { GlobalRawModerator = listeningMods };
return true;
}
result = null;
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using EmberKernel.Services.EventBus;
using System;

namespace EmberMemoryReader.Abstract.Data
{
public class GlobalGameModeratorInfo : Event<GlobalGameModeratorInfo>, IComparable<GlobalGameModeratorInfo>, IEquatable<GlobalGameModeratorInfo>
{
public int GlobalRawModerator { get; set; }
public int CompareTo(GlobalGameModeratorInfo other)
{
return GlobalRawModerator - other.GlobalRawModerator;
}

public bool Equals(GlobalGameModeratorInfo other)
{
return GlobalRawModerator == other.GlobalRawModerator;
}
}
}
25 changes: 7 additions & 18 deletions src/plugins/osu/EmberMemoryReader.Abstract/Data/Playing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ public class Playing : IComparableCollector<PlayingInfo>
private static readonly string TimePattern = "\x5e\x5f\x5d\xc3\xa1\x0\x0\x0\x0\x89\x0\x04";
private static readonly string TimeMask = "xxxxx????x?x";

private static readonly string GlobalModsPattern = "\x8B\xF1\xA1\x00\x00\x00\x00\x25\x00\x00\x40\x00\x85\xC0";
private static readonly string GlobalModsMask = "xxx????xxxxxxx";


public int ReadInterval { get; set; } = 120;
public int RetryLimit { get; set; } = int.MaxValue;

private IntPtr AccuracyAddress;
private IntPtr TimeAddress;
private IntPtr ModAddress;

private DirectMemoryReader Reader { get; }
public Playing(DirectMemoryReader reader)
Expand All @@ -39,9 +35,6 @@ public Playing(DirectMemoryReader reader)
public bool TryInitialize()
{
Reader.Reload();
Reader.TryFindPattern(GlobalModsPattern.ToBytes(), GlobalModsMask, 3, out ModAddress);
if (!Reader.TryReadIntPtr(ModAddress, out ModAddress)) return false;

Reader.TryFindPattern(AccuracyPattern.ToBytes(), AccuracyMask, 1, out AccuracyAddress);
if (!Reader.TryReadIntPtr(AccuracyAddress, out AccuracyAddress))
{
Expand Down Expand Up @@ -81,10 +74,6 @@ public bool TryRead(out Event result)
{
info.RawModInfo = mods ^ modSalt;
}
if (Reader.TryReadInt(ModAddress, out var listeningMods))
{
info.RawListeningModInfo = listeningMods;
}
if (Reader.TryReadString(scoreAddress + 0x28, out var playerName))
{
info.CurrentPlayerName = playerName;
Expand All @@ -93,31 +82,31 @@ public bool TryRead(out Event result)
//{
// info.RawUnstableRate = rawUnstableList;
//}
if (Reader.TryReadShort(scoreAddress + 0x8c, out var katu))
if (Reader.TryReadShort(scoreAddress + 0x90, out var katu))
{
info.GameStatistic.Katu = katu;
}
if (Reader.TryReadShort(scoreAddress + 0x8a, out var geki))
if (Reader.TryReadShort(scoreAddress + 0x8e, out var geki))
{
info.GameStatistic.Geki = geki;
}
if (Reader.TryReadShort(scoreAddress + 0x88, out var bad))
if (Reader.TryReadShort(scoreAddress + 0x8c, out var bad))
{
info.GameStatistic.Bad = bad;
}
if (Reader.TryReadShort(scoreAddress + 0x84, out var good))
if (Reader.TryReadShort(scoreAddress + 0x88, out var good))
{
info.GameStatistic.Good = good;
}
if (Reader.TryReadShort(scoreAddress + 0x86, out var best))
if (Reader.TryReadShort(scoreAddress + 0x8a, out var best))
{
info.GameStatistic.Best = best;
}
if (Reader.TryReadShort(scoreAddress + 0x8e, out var missing))
if (Reader.TryReadShort(scoreAddress + 0x92, out var missing))
{
info.GameStatistic.Missing = missing;
}
if (Reader.TryReadShort(scoreAddress + 0x90, out var combo))
if (Reader.TryReadShort(scoreAddress + 0x94, out var combo))
{
info.GameStatistic.Combo = combo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected override bool BuildCollectScope(CollectorBuilder builder, OsuProcessMa
.Collect<Beatmap>()
.Collect<GameMode>()
.Collect<GameStatus>()
.Collect<GlobalGameModerator>()
.Collect<Playing>()
.Collect<MultiplayerBeatmapId>()
)
Expand Down
15 changes: 13 additions & 2 deletions src/plugins/osu/PpCalculator/PpCalculator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\EmberKernel\EmberKernel.csproj" />
<ItemGroup>
<PackageReference Include="SimpleOsuPerformanceCalculator" Version="0.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\EmberKernel\EmberKernel.csproj">
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</ProjectReference>
<ProjectReference Include="..\EmberMemoryReader.Abstract\EmberMemoryReader.Abstract.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="move $(OutDir)\$(TargetFileName) $(OutDir)\$(TargetName).dll&#xD;&#xA;mkdir $(SolutionDir)build\$(ConfigurationName)\plugins\$(ProjectName)&#xD;&#xA;copy $(OutDir)\* $(SolutionDir)build\$(ConfigurationName)\plugins\$(ProjectName)" />
</Target>
</Project>
23 changes: 20 additions & 3 deletions src/plugins/osu/PpCalculator/PpCalculatorPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Autofac;
using EmberKernel;
using EmberKernel.Plugins;
using EmberKernel.Plugins.Attributes;
using EmberKernel.Plugins.Components;
using EmberMemoryReader.Abstract.Data;
using EmberMemoryReader.Abstract.Events;
using System.Threading.Tasks;

namespace PpCalculator
Expand All @@ -11,17 +14,31 @@ public class PpCalculatorPlugin : Plugin
{
public override void BuildComponents(IComponentBuilder builder)
{
throw new System.NotImplementedException();
builder.ConfigureComponent<PpCalculatorService>().SingleInstance();
}

public override ValueTask Initialize(ILifetimeScope scope)
{
throw new System.NotImplementedException();
scope.Subscription<GameModeInfo, PpCalculatorService>();
scope.Subscription<BeatmapInfo, PpCalculatorService>();
scope.Subscription<PlayingInfo, PpCalculatorService>();
scope.Subscription<GameStatusInfo, PpCalculatorService>();
scope.Subscription<GlobalGameModeratorInfo, PpCalculatorService>();
scope.Subscription<OsuProcessMatchedEvent, PpCalculatorService>();

return default;
}

public override ValueTask Uninitialize(ILifetimeScope scope)
{
throw new System.NotImplementedException();
scope.Unsubscription<GameModeInfo, PpCalculatorService>();
scope.Unsubscription<BeatmapInfo, PpCalculatorService>();
scope.Unsubscription<PlayingInfo, PpCalculatorService>();
scope.Unsubscription<GameStatusInfo, PpCalculatorService>();
scope.Unsubscription<GlobalGameModeratorInfo, PpCalculatorService>();
scope.Unsubscription<OsuProcessMatchedEvent, PpCalculatorService>();

return default;
}
}
}
Loading

0 comments on commit 411c9cd

Please sign in to comment.