Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Steam/Epic Achievements Unlock (#468)
Browse files Browse the repository at this point in the history
* Steam/Epic Achievements Unlock

* cleaning
  • Loading branch information
cddjr authored Dec 12, 2022
1 parent 3f7f561 commit dd66542
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 52 deletions.
1 change: 1 addition & 0 deletions AmongUsMenu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="rpc\RpcPlayerAppearance.cpp" />
<ClCompile Include="rpc\RpcSetRole.cpp" />
<ClCompile Include="rpc\RpcUsePlatform.cpp" />
<ClCompile Include="user\achievements.cpp" />
<ClCompile Include="user\keybinds.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
5 changes: 4 additions & 1 deletion AmongUsMenu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<ClCompile Include="hooks\Doors.cpp">
<Filter>hooks</Filter>
</ClCompile>
<ClCompile Include="hooks\LogicOptions.cpp">
<ClCompile Include="hooks\GameOptionsManager.cpp">
<Filter>hooks</Filter>
</ClCompile>
<ClCompile Include="hooks\HudManager.cpp">
Expand Down Expand Up @@ -301,6 +301,9 @@
<ClCompile Include="gui\aum-chat.cpp">
<Filter>gui</Filter>
</ClCompile>
<ClCompile Include="user\achievements.cpp">
<Filter>user</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="appdata\il2cpp-api-functions.h">
Expand Down
2 changes: 2 additions & 0 deletions appdata/il2cpp-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ DO_APP_FUNC(String*, GameData_PlayerInfo_get_PlayerName, (GameData_PlayerInfo* _
DO_APP_FUNC(void, AccountManager_UpdateKidAccountDisplay, (AccountManager* __this, MethodInfo* method), "Assembly-CSharp, System.Void AccountManager::UpdateKidAccountDisplay()");
DO_APP_FUNC(void, PlayerStorageManager_OnReadPlayerPrefsComplete, (PlayerStorageManager* __this, void* data, MethodInfo* method), "Assembly-CSharp, System.Void PlayerStorageManager::OnReadPlayerPrefsComplete(Epic.OnlineServices.PlayerDataStorage.ReadFileCallbackInfo)");

DO_APP_FUNC(void, AchievementManager_1_UnlockAchievement, (AchievementManager_1* __this, String* key, MethodInfo* method), "Assembly-CSharp, System.Void AchievementManager::UnlockAchievement(System.String)");

// 2022.10.25s
DO_APP_FUNC(PlayerData*, DataManager_get_Player, (MethodInfo* method), "Assembly-CSharp, AmongUs.Data.Player.PlayerData AmongUs.Data.DataManager::get_Player()");
DO_APP_FUNC(String*, PlayerCustomizationData_get_Name, (PlayerCustomizationData* __this, MethodInfo* method), "Assembly-CSharp, System.String AmongUs.Data.Player.PlayerCustomizationData::get_Name()");
Expand Down
86 changes: 86 additions & 0 deletions appdata/il2cpp-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12579,6 +12579,92 @@ namespace app
};
#pragma endregion

#pragma region AchievementManager
struct GameModes__Enum__Array {
void* klass;
MonitorData* monitor;
Il2CppArrayBounds* bounds;
il2cpp_array_size_t max_length;
GameModes__Enum vector[32];
};

struct __declspec(align(4)) List_1_AmongUs_GameOptions_GameModes___Fields {
struct GameModes__Enum__Array* _items;
int32_t _size;
int32_t _version;
struct Object* _syncRoot;
};

struct List_1_AmongUs_GameOptions_GameModes_ {
void* klass;
MonitorData* monitor;
struct List_1_AmongUs_GameOptions_GameModes___Fields fields;
};

struct __declspec(align(4)) Dictionary_2_System_String_List_1_AmongUs_GameOptions_GameModes___Fields {
struct Int32__Array* buckets;
struct Dictionary_2_TKey_TValue_Entry_System_String_List_1_AmongUs_GameOptions_GameModes___Array* entries;
int32_t count;
int32_t version;
int32_t freeList;
int32_t freeCount;
void* comparer;
void* keys;
void* values;
struct Object* _syncRoot;
};

struct Dictionary_2_System_String_List_1_AmongUs_GameOptions_GameModes_ {
void* klass;
MonitorData* monitor;
struct Dictionary_2_System_String_List_1_AmongUs_GameOptions_GameModes___Fields fields;
};

struct Dictionary_2_TKey_TValue_Entry_System_String_List_1_AmongUs_GameOptions_GameModes_ {
int32_t hashCode;
int32_t next;
struct String* key;
struct List_1_AmongUs_GameOptions_GameModes_* value;
};

struct Dictionary_2_TKey_TValue_Entry_System_String_List_1_AmongUs_GameOptions_GameModes___Array {
void* klass;
MonitorData* monitor;
Il2CppArrayBounds* bounds;
il2cpp_array_size_t max_length;
struct Dictionary_2_TKey_TValue_Entry_System_String_List_1_AmongUs_GameOptions_GameModes_ vector[32];
};

struct AchievementManager_1 {
struct AchievementManager_1__Class* klass;
MonitorData* monitor;
//struct AchievementManager_1__Fields fields;
};

struct AchievementManager_1__VTable {
VirtualInvokeData Equals;
VirtualInvokeData Finalize;
VirtualInvokeData GetHashCode;
VirtualInvokeData ToString;
VirtualInvokeData Awake;
VirtualInvokeData OnDestroy;
};

struct AchievementManager_1__StaticFields {
struct Dictionary_2_System_String_List_1_AmongUs_GameOptions_GameModes_* AchievementGameModeKey;
struct Dictionary_2_System_String_List_1_AmongUs_GameOptions_GameModes_* StatsGameModeKey;
};

struct AchievementManager_1__Class {
Il2CppClass_0 _0;
Il2CppRuntimeInterfaceOffsetPair* interfaceOffsets;
struct AchievementManager_1__StaticFields* static_fields;
const Il2CppRGCTXData* rgctx_data;
Il2CppClass_1 _1;
struct AchievementManager_1__VTable vtable;
};
#pragma endregion

typedef Il2CppObject PlayerData;
typedef Il2CppObject PlayerCustomizationData;
typedef Il2CppObject PlayerPurchasesData;
Expand Down
11 changes: 11 additions & 0 deletions framework/il2cpp-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace app {
class List {
public:
using iterator = decltype(&E::fields._items->vector[0]);
using value_type = std::remove_cvref_t<decltype(E::fields._items->vector[0])>;
constexpr List(E* list) : _Ptr(list) {}
constexpr size_t size() const {
if (!_Ptr) return 0;
Expand All @@ -91,6 +92,16 @@ namespace app {
auto pList = (List_1_PlayerTask_*)_Ptr;
((void(*)(void*, size_t, const void*))(pList->klass->vtable.RemoveAt.methodPtr))(pList, _Pos, pList->klass->vtable.RemoveAt.method);
}
constexpr void add(value_type item) {
if (!_Ptr) return;
auto pList = (List_1_PlayerTask_*)_Ptr;
((void(*)(void*, value_type, const void*))(pList->klass->vtable.Add.methodPtr))(pList, item, pList->klass->vtable.Add.method);
}
constexpr bool contains(value_type item) const {
if (!_Ptr) return false;
auto pList = (List_1_PlayerTask_*)_Ptr;
return ((bool(*)(void*, value_type, const void*))(pList->klass->vtable.Contains.methodPtr))(pList, item, pList->klass->vtable.Contains.method);
}
constexpr iterator begin() const {
if (!_Ptr) return nullptr;
return _Ptr->fields._items->vector;
Expand Down
15 changes: 6 additions & 9 deletions gui/tabs/settings_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,16 @@ namespace SettingsTab {
State.userName = std::string(*nameBuffer);
}
}
/*

ImGui::Dummy(ImVec2(7, 7) * State.dpiScale);
ImGui::Separator();
ImGui::Dummy(ImVec2(7, 7) * State.dpiScale);
if (ImGui::Button("Unlock all Steam achievements"))

if (Achievements::IsSupported()
&& ImGui::Button("Unlock all achievements"))
{
for (const char* achievement : steamAchievements)
{
Game::SteamUserStats_SetAchievement(convert_to_string(std::string(achievement)));
}
Game::SteamUserStats_StoreStats();
}*/
Achievements::UnlockAll();
}

ImGui::EndTabItem();
}
Expand Down
55 changes: 55 additions & 0 deletions user/achievements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "pch-il2cpp.h"
#include "utility.h"
#include "achievements.hpp"
#include "logger.h"

namespace Achievements {

_Ret_maybenull_ AchievementManager_1* GetAchievementManager() {
static AchievementManager_1* manager = nullptr;
if (!manager) {
static AccountManager* accountManager = nullptr;
if (!accountManager) {
Type* AccountManagerType = app::Type_GetType(convert_to_string(translate_type_name("AccountManager, Assembly-CSharp")), NULL);
LOG_ASSERT(AccountManagerType != nullptr);
il2cpp::Array results = app::Object_1_FindObjectsOfType(AccountManagerType, NULL);
if (results.size() == 0)
return nullptr;
accountManager = reinterpret_cast<AccountManager*>(results[0]);
}

if (accountManager->fields.prevLoggedInStatus == EOSManager_AccountLoginStatus__Enum::Offline)
return nullptr;

Type* AchievementManagerType = app::Type_GetType(convert_to_string(translate_type_name("AchievementManager, Assembly-CSharp")), NULL);
LOG_ASSERT(AchievementManagerType != nullptr);
il2cpp::Array results = app::Object_1_FindObjectsOfType(AchievementManagerType, NULL);
if (results.size() == 0)
return nullptr;
manager = reinterpret_cast<AchievementManager_1*>(results[0]);
}
return manager;
}

bool IsSupported() {
return GetAchievementManager() != nullptr;
}

void UnlockAll() {
auto manager = GetAchievementManager();
if (!manager) return;

ScopedThreadAttacher managedThreadAttached;
il2cpp::Dictionary achievementGameModeKey = manager->klass->static_fields->AchievementGameModeKey;
for (auto pair : achievementGameModeKey) {
il2cpp::List list = pair.value;
if (!list.contains(app::GameModes__Enum::Normal)) {
list.add(app::GameModes__Enum::Normal);
}
if (!list.contains(app::GameModes__Enum::HideNSeek)) {
list.add(app::GameModes__Enum::HideNSeek);
}
app::AchievementManager_1_UnlockAchievement(manager, pair.key, nullptr);
}
}
}
38 changes: 4 additions & 34 deletions user/achievements.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
#pragma once
#include <vector>

std::vector<const char*> steamAchievements = {
"task_complete_easy",
"task_complete_medium",
"task_complete_hard",
"card_first_try",
"kill_during_lights",
"no_vents_impostor_win",
"kills_first",
"kills_easy",
"kills_medium",
"kills_hard",
"wins_skeld",
"wins_mira",
"wins_polus",
"wins_airship",
"survive_two_impostors",
"win_all_tasks",
"win_sabotage",
"win_kills",
"win_impostor_vote",
"survive_crewmate",
"die_during_medscan",
"fix_own_sabotage",
"three_kills_before_meeting",
"win_always_correct_votes",
"impostorKills",
"tasksCompleted",
"MapWinsSkeld",
"MapWinsPolus",
"MapWinsMira",
"MapWinsAirship"
};
namespace Achievements {
bool IsSupported();
void UnlockAll();
}
8 changes: 4 additions & 4 deletions user/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace Game {
LobbyBehaviour** pLobbyBehaviour = nullptr;
RoleManager** pRoleManager = nullptr;

STEAMUSERSTATS_SETACHIEVEMENT* SteamUserStats_SetAchievement = nullptr;
STEAMUSERSTATS_STORESTATS* SteamUserStats_StoreStats = nullptr;
//STEAMUSERSTATS_SETACHIEVEMENT* SteamUserStats_SetAchievement = nullptr;
//STEAMUSERSTATS_STORESTATS* SteamUserStats_StoreStats = nullptr;

void scanGameFunctions()
{
SteamUserStats_SetAchievement = SignatureScan<STEAMUSERSTATS_SETACHIEVEMENT*>("E8 ? ? ? ? 6A 00 E8 ? ? ? ? 83 C4 0C 5D C3 A1 ? ? ? ? F6 80 ? ? ? ? ? 74 0F 83 78 74 00 75 09 50 E8 ? ? ? ? 83 C4 04 6A 00 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 08 5D C3 CC", GetModuleHandleA("GameAssembly.dll")).ResolveCall();
SteamUserStats_StoreStats = SignatureScan<STEAMUSERSTATS_STORESTATS*>("E8 ? ? ? ? 83 C4 0C 5D C3 A1 ? ? ? ? F6 80 ? ? ? ? ? 74 0F 83 78 74 00 75 09 50 E8 ? ? ? ? 83 C4 04 6A 00 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 08 5D C3 CC", GetModuleHandleA("GameAssembly.dll")).ResolveCall();
//SteamUserStats_SetAchievement = SignatureScan<STEAMUSERSTATS_SETACHIEVEMENT*>("E8 ? ? ? ? 6A 00 E8 ? ? ? ? 83 C4 0C 5D C3 A1 ? ? ? ? F6 80 ? ? ? ? ? 74 0F 83 78 74 00 75 09 50 E8 ? ? ? ? 83 C4 04 6A 00 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 08 5D C3 CC", GetModuleHandleA("GameAssembly.dll")).ResolveCall();
//SteamUserStats_StoreStats = SignatureScan<STEAMUSERSTATS_STORESTATS*>("E8 ? ? ? ? 83 C4 0C 5D C3 A1 ? ? ? ? F6 80 ? ? ? ? ? 74 0F 83 78 74 00 75 09 50 E8 ? ? ? ? 83 C4 04 6A 00 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 08 5D C3 CC", GetModuleHandleA("GameAssembly.dll")).ResolveCall();
}
}
8 changes: 4 additions & 4 deletions user/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace Game {
extern LobbyBehaviour** pLobbyBehaviour;
extern RoleManager** pRoleManager;

typedef bool STEAMUSERSTATS_SETACHIEVEMENT(String* pchName);
typedef bool STEAMUSERSTATS_STORESTATS();
//typedef bool STEAMUSERSTATS_SETACHIEVEMENT(String* pchName);
//typedef bool STEAMUSERSTATS_STORESTATS();

extern STEAMUSERSTATS_SETACHIEVEMENT* SteamUserStats_SetAchievement;
extern STEAMUSERSTATS_STORESTATS* SteamUserStats_StoreStats;
//extern STEAMUSERSTATS_SETACHIEVEMENT* SteamUserStats_SetAchievement;
//extern STEAMUSERSTATS_STORESTATS* SteamUserStats_StoreStats;

extern void scanGameFunctions();
}

0 comments on commit dd66542

Please sign in to comment.