Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix build after game update #49

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if ($Help)
exit 0
}

$Projects = "Core", "TreasureSolver";
$Projects = @("Core");

echo "> Packing projects: $Projects"
echo "> Output path: $Output"
Expand Down Expand Up @@ -46,11 +46,6 @@ foreach ($Project in $Projects)
continue;
}

if ( $OtherProjectsDll.Contains($Filename))
{
continue;
}

echo "Copying $File to $Dir..."
copy $File $Dir
}
Expand Down
22 changes: 20 additions & 2 deletions src/Core/DBIPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using Com.Ankama.Dofus.Server.Connection.Protocol;
using Com.Ankama.Dofus.Server.Game.Protocol.Common;
using DofusBatteriesIncluded.Plugins.Core.Player;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -42,3 +40,23 @@ internal void SetCurrentCharacter(Character character)

internal void OnPlayerChangeCompleted() => CurrentCharacterChangeCompleted?.Invoke(this, CurrentCharacter);
}

public class IdentificationResponse
{
public ResultOneofCase ResultCase { get; set; }
public Types.Success Success { get; set; }

public enum ResultOneofCase
{
Success
}

public class Types
{
public class Success
{
public long AccountId { get; set; }
public string AccountNickname { get; set; }
}
}
}
35 changes: 35 additions & 0 deletions src/Core/Deobfuscation/Protocol/ObfuscatedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Reflection;

namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

public class ObfuscatedMessage
{
readonly object _message;
readonly PropertyInfo _contentOneofCaseProperty;
readonly PropertyInfo _contentProperty;
readonly PropertyInfo _contentPointerProperty;

public ObfuscatedMessage(object message, PropertyInfo contentOneofCaseProperty, PropertyInfo contentProperty, PropertyInfo contentPointerProperty)
{
_message = message;
_contentOneofCaseProperty = contentOneofCaseProperty;
_contentProperty = contentProperty;
_contentPointerProperty = contentPointerProperty;
}

public ObfuscatedMessageContentOneOfCase ContentOneOfCase {
get {
object result = _contentOneofCaseProperty.GetValue(_message);
string resultString = result?.ToString();
return resultString == null ? ObfuscatedMessageContentOneOfCase.None : Enum.Parse<ObfuscatedMessageContentOneOfCase>(resultString);
}
}
public IntPtr? ContentPointer {
get {
object content = _contentProperty.GetValue(_message);
object contentPointer = _contentPointerProperty?.GetValue(content);
return (IntPtr?)contentPointer;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

public enum ObfuscatedMessageContentOneOfCase
{
None,
Event,
Response,
Request
}
51 changes: 51 additions & 0 deletions src/Core/Deobfuscation/Protocol/ObfuscatedMessageReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Linq;
using System.Reflection;
using DofusBatteriesIncluded.Plugins.Core.Extensions;
using Google.Protobuf;
using Il2CppSystem.Threading;
using Object = Il2CppSystem.Object;

namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

class ObfuscatedMessageReader
{
const string GameProtocolAssemblyName = "Ankama.Dofus.Protocol.Game";
const string GameProtocolAssemblyPath = $"BepInEx/interop/{GameProtocolAssemblyName}.dll";

readonly Type _obfuscatedMessageType;
readonly PropertyInfo _contentOneofCaseProperty;
readonly PropertyInfo _contentProperty;
readonly PropertyInfo _contentPointerProperty;

public ObfuscatedMessageReader()
{
Thread.Sleep(5000);

Assembly gameAssembly = AppDomain.CurrentDomain.LoadAssemblyIfNotLoaded(GameProtocolAssemblyName, GameProtocolAssemblyPath);

Type contentOneOfCaseNestedInMessageType = FindContentOneOfCaseTypeNestedInMessageType(gameAssembly);
_obfuscatedMessageType = contentOneOfCaseNestedInMessageType.DeclaringType!;
_contentOneofCaseProperty = _obfuscatedMessageType.GetProperties().First(p => p.PropertyType == contentOneOfCaseNestedInMessageType);
_contentProperty = _obfuscatedMessageType.GetProperties().First(p => p.PropertyType == typeof(Object));
_contentPointerProperty = _contentProperty.PropertyType.GetProperty("Pointer");
}

public ObfuscatedMessage GetMessage(IMessage message)
{
object messageInstance = Activator.CreateInstance(_obfuscatedMessageType, message.Pointer);
return new ObfuscatedMessage(messageInstance, _contentOneofCaseProperty, _contentProperty, _contentPointerProperty);
}

static Type FindContentOneOfCaseTypeNestedInMessageType(Assembly assembly) =>
assembly.GetTypes()
.Where(t => t.IsEnum && t.DeclaringType != null)
.Single(
t =>
{
// Find the enum containing values None, Event, Request, Response: it is the ObfuscatedMessageContentOneofCase enum defined by the Message class
string[] values = t.GetEnumValues().Cast<object>().Select(e => e.ToString()).ToArray();
return values.Length == 4 && values.Contains("None") && values.Contains("Event") && values.Contains("Response") && values.Contains("Request");
}
);
}
37 changes: 37 additions & 0 deletions src/Core/Deobfuscation/Protocol/ObfuscatedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

public class ObfuscatedResponse
{
readonly object _response;
readonly PropertyInfo _contentOneofCaseProperty;
readonly IReadOnlyCollection<PropertyInfo> _contentProperties;

public ObfuscatedResponse(object response, PropertyInfo contentOneofCaseProperty, IReadOnlyCollection<PropertyInfo> contentProperties)
{
_response = response;
_contentOneofCaseProperty = contentOneofCaseProperty;
_contentProperties = contentProperties;
}

public ObfuscatedResponseContentOneOfCase GetContentOneOfCaseInResponse {
get {
object result = _contentOneofCaseProperty.GetValue(_response);
string resultString = result?.ToString();
return resultString == null ? ObfuscatedResponseContentOneOfCase.None : Enum.Parse<ObfuscatedResponseContentOneOfCase>(resultString);
}
}

public object Identification => GetNonNullContentProperty();
public object Pong => GetNonNullContentProperty();
public object SelectServer => GetNonNullContentProperty();
public object ForceAccount => GetNonNullContentProperty();
public object FriendList => GetNonNullContentProperty();
public object AcquaintanceServersResponse => GetNonNullContentProperty();

object GetNonNullContentProperty() => _contentProperties.Select(p => p.GetValue(_response)).FirstOrDefault(r => r != null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

public enum ObfuscatedResponseContentOneOfCase
{
None,
Identification,
Pong,
SelectServer,
ForceAccount,
FriendList,
AcquaintanceServersResponse
}
54 changes: 54 additions & 0 deletions src/Core/Deobfuscation/Protocol/ObfuscatedResponseReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DofusBatteriesIncluded.Plugins.Core.Extensions;

namespace DofusBatteriesIncluded.Plugins.Core.Deobfuscation.Protocol;

class ObfuscatedResponseReader
{
const string ConnectionProtocolAssemblyName = "Ankama.Dofus.Protocol.Connection";
const string ConnectionProtocolAssemblyPath = $"BepInEx/interop/{ConnectionProtocolAssemblyName}.dll";

readonly Type _obfuscatedResponseType;
readonly PropertyInfo _contentOneofCaseProperty;
readonly IReadOnlyCollection<PropertyInfo> _contentProperties;

public ObfuscatedResponseReader()
{
Assembly connectionAssembly = AppDomain.CurrentDomain.LoadAssemblyIfNotLoaded(ConnectionProtocolAssemblyName, ConnectionProtocolAssemblyPath);

Type contentOneOfCaseNestedInResponseType = FindContentOneOfCaseTypeNestedInResponseType(connectionAssembly);
_obfuscatedResponseType = contentOneOfCaseNestedInResponseType.DeclaringType!;
_contentOneofCaseProperty = _obfuscatedResponseType.GetProperties().First(p => p.PropertyType == contentOneOfCaseNestedInResponseType);
_contentProperties = _obfuscatedResponseType.GetProperties()
.Where(p => p.PropertyType.Assembly == connectionAssembly && p.PropertyType != contentOneOfCaseNestedInResponseType)
.ToArray();
}

public ObfuscatedResponse GetResponse(IntPtr pointer)
{
object responseInstance = Activator.CreateInstance(_obfuscatedResponseType, pointer);
return new ObfuscatedResponse(responseInstance, _contentOneofCaseProperty, _contentProperties);
}

static Type FindContentOneOfCaseTypeNestedInResponseType(Assembly assembly) =>
assembly.GetTypes()
.Where(t => t.IsEnum && t.DeclaringType != null)
.Single(
t =>
{
// Find the enum containing values None, Event, Request, Response: it is the ObfuscatedMessageContentOneofCase enum defined by the Message class
string[] values = t.GetEnumValues().Cast<object>().Select(e => e.ToString()).ToArray();
return values.Length == 7
&& values.Contains("None")
&& values.Contains("Identification")
&& values.Contains("Pong")
&& values.Contains("SelectServer")
&& values.Contains("ForceAccount")
&& values.Contains("FriendList")
&& values.Contains("AcquaintanceServersResponse");
}
);
}
21 changes: 21 additions & 0 deletions src/Core/Extensions/AppDomainExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Linq;
using System.Reflection;

namespace DofusBatteriesIncluded.Plugins.Core.Extensions;

static class AppDomainExtensions
{
public static Assembly LoadAssemblyIfNotLoaded(this AppDomain appDomain, string assemblyName, string assemblyPath)
{
Assembly assembly = appDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == assemblyName);

if (assembly == null)
{
// assembly not loaded
assembly = Assembly.LoadFrom(assemblyPath);
}

return assembly;
}
}
8 changes: 8 additions & 0 deletions src/Core/Player/Character.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DofusBatteriesIncluded.Plugins.Core.Player;

public class Character
{
public long Id { get; set; }
public string Name { get; set; }
public int Level { get; set; }
}
4 changes: 1 addition & 3 deletions src/Core/Player/CurrentAccountState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Com.Ankama.Dofus.Server.Connection.Protocol;

namespace DofusBatteriesIncluded.Plugins.Core.Player;
namespace DofusBatteriesIncluded.Plugins.Core.Player;

public class CurrentAccountState
{
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Player/CurrentPlayerState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Com.Ankama.Dofus.Server.Game.Protocol.Common;
using Core.DataCenter;
using Core.DataCenter.Metadata.World;
using DofusBatteriesIncluded.Plugins.Core.Maps;
Expand All @@ -14,8 +13,8 @@ public class CurrentPlayerState
public CurrentPlayerState(Character character)
{
CharacterId = character.Id;
Name = character.CharacterBasicInformation.Name;
Level = character.CharacterBasicInformation.Level;
Name = character.Name;
Level = character.Level;
}

public long CharacterId { get; }
Expand Down
1 change: 0 additions & 1 deletion src/Core/Player/UpdateCurrentAccount.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Com.Ankama.Dofus.Server.Connection.Protocol;
using DofusBatteriesIncluded.Plugins.Core.Protocol;

namespace DofusBatteriesIncluded.Plugins.Core.Player;
Expand Down
24 changes: 23 additions & 1 deletion src/Core/Player/UpdateCurrentPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Com.Ankama.Dofus.Server.Game.Protocol.Character.Management;
using DofusBatteriesIncluded.Plugins.Core.Protocol;

namespace DofusBatteriesIncluded.Plugins.Core.Player;
Expand All @@ -23,3 +22,26 @@ public Task HandleAsync(CharacterLoadingCompleteEvent message)
return Task.CompletedTask;
}
}

public class CharacterLoadingCompleteEvent
{
}

public class CharacterSelectionEvent
{
public ResultOneofCase ResultCase { get; set; }
public Types.Success Success { get; set; }

public enum ResultOneofCase
{
Success
}

public class Types
{
public class Success
{
public Character Character { get; set; }
}
}
}
17 changes: 14 additions & 3 deletions src/Core/Player/UpdateCurrentPlayerMap.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Com.Ankama.Dofus.Server.Game.Protocol.Gamemap;
using DofusBatteriesIncluded.Plugins.Core.Protocol;

namespace DofusBatteriesIncluded.Plugins.Core.Player;
Expand All @@ -26,11 +26,22 @@ public Task HandleAsync(MapMovementEvent message)
return Task.CompletedTask;
}

DBI.Player.CurrentCharacter.SetCurrentCellId(message.Cells.array.Last(c => c != default));
DBI.Player.CurrentCharacter.SetCurrentCellId(message.Cells.Last(c => c != default));

return Task.CompletedTask;
}

static bool IsMessageForCurrentPlayer(MapCurrentEvent message) => DBI.Player.CurrentCharacter != null;
static bool IsMessageForCurrentPlayer(MapMovementEvent message) => DBI.Player.CurrentCharacter != null && DBI.Player.CurrentCharacter.CharacterId == message.CharacterId;
}

public class MapMovementEvent
{
public IReadOnlyList<long> Cells { get; set; }
public long CharacterId { get; set; }
}

public class MapCurrentEvent
{
public long MapId { get; set; }
}
Loading
Loading