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

Commit

Permalink
doors
Browse files Browse the repository at this point in the history
  • Loading branch information
cddjr committed Oct 27, 2023
1 parent 3fafe4b commit 9057687
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 55 deletions.
2 changes: 1 addition & 1 deletion NatvisFile.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<Type Name="app::Object_1__Array">
<AlternativeType Name="app::PlayerVoteArea__Array"/>
<AlternativeType Name="app::PlainShipRoom__Array"/>
<AlternativeType Name="app::PlainDoor__Array"/>
<AlternativeType Name="app::OpenableDoor__Array"/>
<AlternativeType Name="app::PlayerTask__Array"/>
<AlternativeType Name="app::PlayerControl__Array"/>
<AlternativeType Name="app::ClientData__Array"/>
Expand Down
2 changes: 2 additions & 0 deletions appdata/il2cpp-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,5 @@ DO_APP_FUNC(LogicOptions*, GameManager_get_LogicOptions, (GameManager* __this, M

// 2023.10.24e
DO_APP_FUNC(void, FungleShipStatus_OnEnable, (FungleShipStatus* __this, MethodInfo* method), "Assembly-CSharp, System.Void FungleShipStatus::OnEnable()");
DO_APP_FUNC(void, MushroomWallDoor_SetDoorway, (MushroomWallDoor* __this, bool open, MethodInfo* method), "Assembly-CSharp, System.Void MushroomWallDoor::SetDoorway(System.Boolean)");
DO_APP_FUNC(void, MushroomDoorSabotageMinigame_Begin, (MushroomDoorSabotageMinigame* __this, PlayerTask* task, MethodInfo* method), "Assembly-CSharp, System.Void MushroomDoorSabotageMinigame::Begin(PlayerTask)");
64 changes: 36 additions & 28 deletions appdata/il2cpp-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8419,6 +8419,27 @@ namespace app
};
#pragma endregion

#pragma region MushroomDoorSabotageMinigame
struct MushroomDoorSabotageMinigame__Fields {
struct Minigame__Fields _;
void* mushroomInvisibleSeconds;
void* mushroomVisibleSeconds;
struct TextMeshPro* counterText;
void* spawnPoints;
void* mushroomVariants;
struct OpenableDoor* myDoor;
int32_t mushroomWhackCount;
void* spawnPointBag;
void* mushrooms;
};

struct MushroomDoorSabotageMinigame {
Il2CppClass* klass;
MonitorData* monitor;
struct MushroomDoorSabotageMinigame__Fields fields;
};
#pragma endregion

#pragma region SabotageTask
struct SabotageTask__Fields
{
Expand Down Expand Up @@ -9769,39 +9790,26 @@ namespace app
float size;
};

struct PlainDoor
{
struct PlainDoor__Class* klass;
void* monitor;
struct PlainDoor {
Il2CppClass* klass;
MonitorData* monitor;
struct PlainDoor__Fields fields;
};

struct PlainDoor__VTable
{
VirtualInvokeData Equals;
VirtualInvokeData Finalize;
VirtualInvokeData GetHashCode;
VirtualInvokeData ToString;
VirtualInvokeData SetDoorway;
VirtualInvokeData get_IsOpen;
VirtualInvokeData Serialize;
VirtualInvokeData Deserialize;
VirtualInvokeData DoUpdate;
VirtualInvokeData Start;
};

struct PlainDoor__StaticFields
{
struct MushroomWallDoor__Fields {
struct OpenableDoor__Fields _;
void* wallCollider;
struct Collider2D* shadowColl;
void* mushrooms;
void* openSound;
void* closeSound;
bool open;
};

struct PlainDoor__Class
{
Il2CppClass_0 _0;
Il2CppRuntimeInterfaceOffsetPair* interfaceOffsets;
struct PlainDoor__StaticFields* static_fields;
const Il2CppRGCTXData* rgctx_data;
Il2CppClass_1 _1;
struct PlainDoor__VTable vtable;
struct MushroomWallDoor {
Il2CppClass* klass;
MonitorData* monitor;
struct MushroomWallDoor__Fields fields;
};
#pragma endregion

Expand Down
21 changes: 16 additions & 5 deletions gui/tabs/doors_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "state.hpp"
#include "utility.h"

using namespace std::string_view_literals;

namespace DoorsTab {
void Render() {
GameOptions options;
Expand All @@ -19,15 +21,25 @@ namespace DoorsTab {
|| systemType == SystemTypes__Enum::Decontamination3) {
continue;
}
auto plainDoor = GetPlainDoorByRoom(systemType);
bool isOpen;
auto openableDoor = GetOpenableDoorByRoom(systemType);
if ("PlainDoor"sv == openableDoor->klass->parent->name
|| "PlainDoor"sv == openableDoor->klass->name) {
isOpen = reinterpret_cast<PlainDoor*>(openableDoor)->fields.Open;
} else if ("MushroomWallDoor"sv == openableDoor->klass->name) {
isOpen = reinterpret_cast<MushroomWallDoor*>(openableDoor)->fields.open;
}
else {
continue;
}
if (!(std::find(State.pinnedDoors.begin(), State.pinnedDoors.end(), systemType) == State.pinnedDoors.end()))
{
ImGui::PushStyleColor(ImGuiCol_Text, { 0.9f, 0.1f, 0.25f, 1.f });
if (ImGui::Selectable(TranslateSystemTypes(systemType), State.selectedDoor == systemType))
State.selectedDoor = systemType;
ImGui::PopStyleColor(1);
}
else if (!plainDoor->fields.Open)
else if (!isOpen)
{
ImGui::PushStyleColor(ImGuiCol_Text, { 0.85f, 0.2f, 0.5f, 1.f });
if (ImGui::Selectable(TranslateSystemTypes(systemType), State.selectedDoor == systemType))
Expand Down Expand Up @@ -87,8 +99,6 @@ namespace DoorsTab {
}
ImGui::NewLine();
if (State.selectedDoor != SystemTypes__Enum::Hallway) {
auto plainDoor = GetPlainDoorByRoom(State.selectedDoor);

if (ImGui::Button("Close Door")) {
State.rpcQueue.push(new RpcCloseDoorsOfType(State.selectedDoor, false));
}
Expand All @@ -104,7 +114,8 @@ namespace DoorsTab {
}
}
}
if (State.mapType == Settings::MapType::Pb || State.mapType == Settings::MapType::Airship)
if (State.mapType == Settings::MapType::Pb || State.mapType == Settings::MapType::Airship
|| State.mapType == Settings::MapType::Fungle)
{
ImGui::Dummy(ImVec2(4, 4) * State.dpiScale);
if (ImGui::Checkbox("Auto Open Doors", &State.AutoOpenDoors)) {
Expand Down
2 changes: 1 addition & 1 deletion hooks/DirectX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool ImGuiInitialization(IDXGISwapChain* pSwapChain) {
maps.push_back({ D3D11Image(Resource(IDB_PNG2), pDevice), 115.F, 240.F, 9.25F });
maps.push_back({ D3D11Image(Resource(IDB_PNG3), pDevice), 8.F, 21.F, 10.F });
maps.push_back({ D3D11Image(Resource(IDB_PNG4), pDevice), 162.F, 107.F, 6.F });
maps.push_back({ D3D11Image(Resource(IDB_PNG15), pDevice), 252.F, 140.F, 9.F });
maps.push_back({ D3D11Image(Resource(IDB_PNG15), pDevice), 237.F, 140.F, 8.5F });

icons.insert({ ICON_TYPES::VENT_IN, { D3D11Image(Resource(IDB_PNG5), pDevice), 0.02f }});
icons.insert({ ICON_TYPES::VENT_OUT, { D3D11Image(Resource(IDB_PNG6), pDevice), 0.02f }});
Expand Down
7 changes: 7 additions & 0 deletions hooks/Doors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ void dPlainDoor_SetDoorway(PlainDoor* __this, bool open, MethodInfo* method) {
app::PlainDoor_SetDoorway(__this, open, method);
}

void dMushroomWallDoor_SetDoorway(MushroomWallDoor* __this, bool open, MethodInfo* method) {
if (open && (std::find(State.pinnedDoors.begin(), State.pinnedDoors.end(), __this->fields._.Room) != State.pinnedDoors.end())) {
State.rpcQueue.push(new RpcCloseDoorsOfType(__this->fields._.Room, false));
}
app::MushroomWallDoor_SetDoorway(__this, open, method);
}

bool dAutoOpenDoor_DoUpdate(AutoOpenDoor* __this, float dt, MethodInfo* method) {
if ((std::find(State.pinnedDoors.begin(), State.pinnedDoors.end(), __this->fields._._.Room) != State.pinnedDoors.end()) && __this->fields.ClosedTimer < 1.5f) {
State.rpcQueue.push(new RpcCloseDoorsOfType(__this->fields._._.Room, false));
Expand Down
44 changes: 31 additions & 13 deletions hooks/PlainDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,49 @@
#include "state.hpp"
#include <iostream>

using namespace std::string_view_literals;

static bool OpenDoor(OpenableDoor* door) {
if ("PlainDoor"sv == door->klass->name) {
app::PlainDoor_SetDoorway(reinterpret_cast<PlainDoor*>(door), true, {});
}
else if ("MushroomWallDoor"sv == door->klass->name) {
app::MushroomWallDoor_SetDoorway(reinterpret_cast<MushroomWallDoor*>(door), true, {});
}
else {
return false;
}
State.rpcQueue.push(new RpcRepairSystem(SystemTypes__Enum::Doors, door->fields.Id | 64));
return true;
}

void dMushroomDoorSabotageMinigame_Begin(MushroomDoorSabotageMinigame* __this, PlayerTask* task, MethodInfo* method) {
if (State.AutoOpenDoors) {
if (OpenDoor(__this->fields.myDoor)) {
Minigame_Close((Minigame*)__this, {});
return;
}
}
app::MushroomDoorSabotageMinigame_Begin(__this, task, method);
}

void dDoorBreakerGame_Start(DoorBreakerGame* __this, MethodInfo* method) {
if (State.AutoOpenDoors) {
static Il2CppClass* klassPlainDoor = get_class("Assembly-CSharp, PlainDoor");
if (il2cpp_class_is_assignable_from(klassPlainDoor, __this->fields.MyDoor->klass)) {
State.rpcQueue.push(new RpcRepairSystem(SystemTypes__Enum::Doors, __this->fields.MyDoor->fields.Id | 64));
PlainDoor_SetDoorway((PlainDoor*)__this->fields.MyDoor, true, NULL);
Minigame_Close((Minigame*)__this, NULL);
if (OpenDoor(__this->fields.MyDoor)) {
Minigame_Close((Minigame*)__this, {});
return;
}
// TODO 231024
}
DoorBreakerGame_Start(__this, method);
}

void dDoorCardSwipeGame_Begin(DoorCardSwipeGame* __this, PlayerTask* playerTask, MethodInfo* method) {
if (State.AutoOpenDoors) {
static Il2CppClass* klassPlainDoor = get_class("Assembly-CSharp, PlainDoor");
if (il2cpp_class_is_assignable_from(klassPlainDoor, __this->fields.MyDoor->klass)) {
__this->fields.State = DoorCardSwipeGame_TaskStages__Enum::Inserted;
State.rpcQueue.push(new RpcRepairSystem(SystemTypes__Enum::Doors, __this->fields.MyDoor->fields.Id | 64));
PlainDoor_SetDoorway((PlainDoor*)__this->fields.MyDoor, true, NULL);
Minigame_Close((Minigame*)__this, NULL);
__this->fields.State = DoorCardSwipeGame_TaskStages__Enum::Inserted;
if (OpenDoor(__this->fields.MyDoor)) {
Minigame_Close((Minigame*)__this, {});
return;
}
// TODO 231024
}
DoorCardSwipeGame_Begin(__this, playerTask, method);
}
5 changes: 5 additions & 0 deletions hooks/PlayerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ void dPlayerControl_RpcSyncSettings(PlayerControl* __this, Byte__Array* optionsB

void dPlayerControl_MurderPlayer(PlayerControl* __this, PlayerControl* target, MurderResultFlags__Enum resultFlags, MethodInfo* method)
{
if (static_cast<int32_t>(resultFlags) & static_cast<int32_t>(MurderResultFlags__Enum::FailedError)) {
app::PlayerControl_MurderPlayer(__this, target, resultFlags, method);
return;
}

if (PlayerIsImpostor(GetPlayerData(__this)) && PlayerIsImpostor(GetPlayerData(target))) {
synchronized(Replay::replayEventMutex) {
State.liveReplayEvents.emplace_back(std::make_unique<CheatDetectedEvent>(GetEventPlayerControl(__this).value(), CHEAT_ACTIONS::CHEAT_KILL_IMPOSTOR));
Expand Down
4 changes: 4 additions & 0 deletions hooks/_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void DetourInitilization() {
HOOKFUNC(ExileController_ReEnableGameplay);
HOOKFUNC(SabotageSystemType_SetInitialSabotageCooldown);
HOOKFUNC(FungleShipStatus_OnEnable);
HOOKFUNC(MushroomWallDoor_SetDoorway);
HOOKFUNC(MushroomDoorSabotageMinigame_Begin);


if (!HookFunction(&(PVOID&)oPresent, dPresent, "D3D_PRESENT_FUNCTION")) return;
Expand Down Expand Up @@ -239,6 +241,8 @@ void DetourUninitialization()
UNHOOKFUNC(ExileController_ReEnableGameplay);
UNHOOKFUNC(SabotageSystemType_SetInitialSabotageCooldown);
UNHOOKFUNC(FungleShipStatus_OnEnable);
UNHOOKFUNC(MushroomWallDoor_SetDoorway);
UNHOOKFUNC(MushroomDoorSabotageMinigame_Begin);

if (DetourDetach(&(PVOID&)oPresent, dPresent) != 0) return;

Expand Down
2 changes: 2 additions & 0 deletions hooks/_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ void dGameOptionsManager_set_CurrentGameOptions(GameOptionsManager* __this, IGam
void dExileController_ReEnableGameplay(ExileController* __this, MethodInfo* method);
void dSabotageSystemType_SetInitialSabotageCooldown(SabotageSystemType* __this, MethodInfo* method);
void dFungleShipStatus_OnEnable(FungleShipStatus* __this, MethodInfo* method);
void dMushroomWallDoor_SetDoorway(MushroomWallDoor* __this, bool open, MethodInfo* method);
void dMushroomDoorSabotageMinigame_Begin(MushroomDoorSabotageMinigame* __this, PlayerTask* task, MethodInfo* method);
3 changes: 3 additions & 0 deletions used_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,6 @@ FreeChatInputField__Fields
FreeChatInputField
MurderResultFlags__Enum
FungleShipStatus
OpenableDoor
MushroomWallDoor
MushroomDoorSabotageMinigame
9 changes: 4 additions & 5 deletions user/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,19 @@ PlayerControl* GetPlayerControlById(Game::PlayerId id) {
return NULL;
}

PlainDoor* GetPlainDoorByRoom(SystemTypes__Enum room) {
for (auto door : il2cpp::Array((*Game::pShipStatus)->fields.AllDoors))
OpenableDoor* GetOpenableDoorByRoom(SystemTypes__Enum room) {
for (auto door : GetAllOpenableDoors())
{
if (door->fields.Room == room)
{
// TODO 231024
return (PlainDoor*)door;
return door;
}
}

return nullptr;
}

il2cpp::Array<OpenableDoor__Array> GetAllPlainDoors() {
il2cpp::Array<OpenableDoor__Array> GetAllOpenableDoors() {
return (*Game::pShipStatus)->fields.AllDoors;
}

Expand Down
5 changes: 3 additions & 2 deletions user/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ GameData_PlayerInfo* GetPlayerData(PlayerControl* player);
Vector2 GetTrueAdjustedPosition(PlayerControl* player);
GameData_PlayerInfo* GetPlayerDataById(Game::PlayerId id);
PlayerControl* GetPlayerControlById(Game::PlayerId id);
PlainDoor* GetPlainDoorByRoom(SystemTypes__Enum room);
il2cpp::Array<OpenableDoor__Array> GetAllPlainDoors();
// MushroomWallDoor or PlainDoor
OpenableDoor* GetOpenableDoorByRoom(SystemTypes__Enum room);
il2cpp::Array<OpenableDoor__Array> GetAllOpenableDoors();
il2cpp::List<List_1_PlayerControl_> GetAllPlayerControl();
il2cpp::List<List_1_GameData_PlayerInfo_> GetAllPlayerData();
il2cpp::Array<DeadBody__Array> GetAllDeadBodies();
Expand Down

0 comments on commit 9057687

Please sign in to comment.