Skip to content

Commit

Permalink
fix mickey wonder code
Browse files Browse the repository at this point in the history
31-4302
  • Loading branch information
Lightczx committed Oct 25, 2024
1 parent e2b7d12 commit 7a7f768
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Snap.Hutao.UnlockerIsland</id>
<version>1.1.14</version>
<version>1.1.15</version>
<authors>DGP Studio</authors>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
33 changes: 27 additions & 6 deletions src/UnlockerIsland/Snap.Hutao.UnlockerIsland/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
#include <string>

using namespace Snap::Hutao::UnlockerIsland;

HANDLE hThread = NULL;
BOOL bDllExit = FALSE;

void* klass;
std::string checksum;

struct IslandEnvironment* pEnvironment = NULL;
struct IslandStaging staging {};

static Il2CppArraySize* MickeyWonderEndpoint(INT32 type)
{
if (type == 0)
{
const size_t length = checksum.length();
Il2CppArraySize* const data = staging.MickeyWonderPartner(klass, length);
memcpy(&data->vector[0], checksum.data(), length);
return data;
}

return staging.MickeyWonderPartner(klass, 0);
}

static VOID SetFieldOfViewEndpoint(LPVOID pThis, FLOAT value)
{
value = std::floor(value);
Expand Down Expand Up @@ -58,12 +76,7 @@ static DWORD WINAPI IslandThread(LPVOID lpParam)
pEnvironment->State = IslandState::Started;

UINT64 base = (UINT64)GetModuleHandleW(NULL);

staging.SetFieldOfView = reinterpret_cast<SetFieldOfViewFunc>(base + pEnvironment->FunctionOffsetSetFieldOfView);
staging.SetEnableFogRendering = reinterpret_cast<SetEnableFogRenderingFunc>(base + pEnvironment->FunctionOffsetSetEnableFogRendering);
staging.SetTargetFrameRate = reinterpret_cast<SetTargetFrameRateFunc>(base + pEnvironment->FunctionOffsetSetTargetFrameRate);
staging.OpenTeam = reinterpret_cast<OpenTeamFunc>(base + pEnvironment->FunctionOffsetOpenTeam);
staging.OpenTeamPageAccordingly = reinterpret_cast<OpenTeamPageAccordinglyFunc>(base + pEnvironment->FunctionOffsetOpenTeamPageAccordingly);
InitializeIslandStaging(staging, base, pEnvironment);

if (pEnvironment->LoopAdjustFpsOnly)
{
Expand All @@ -75,6 +88,14 @@ static DWORD WINAPI IslandThread(LPVOID lpParam)
}
else
{
for (INT32 n = 0; n < 3; n++)
{
Il2CppArraySize* const result = staging.MickeyWonder(n);
checksum += std::string(reinterpret_cast<char*>(&result->vector[0]), result->max_length);
klass = result->klass;
}

Detours::Hook(&(LPVOID&)staging.MickeyWonder, MickeyWonderEndpoint);
Detours::Hook(&(LPVOID&)staging.SetFieldOfView, SetFieldOfViewEndpoint);
Detours::Hook(&(LPVOID&)staging.OpenTeam, OpenTeamEndpoint);

Expand Down
48 changes: 32 additions & 16 deletions src/UnlockerIsland/Snap.Hutao.UnlockerIsland/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ enum struct Snap::Hutao::UnlockerIsland::IslandState : int
Stopped = 3,
};

// Layout:
// 0 1 2 3 4 8
// ┌--------------------------------------------------------------------------┬---------------------------------------┐
// │ State │ LastError │
// ├--------------------------------------------------------------------------┼---------------------------------------┤ 8
// │ FieldOfView │ TargetFrameRate │
// ├------------┬----------------┬-------------------┬------------------------┼---------------------------------------┤ 16
// │ DisableFog │ FixLowFovScene │ LoopAdjustFpsOnly │ RemoveOpenTeamProgress │ FunctionOffsetSetFieldOfView │
// ├------------┴----------------┴-------------------┴------------------------┼---------------------------------------┤ 24
// │ FunctionOffsetSetEnableFogRendering │ FunctionOffsetSetTargetFrameRate │
// ├--------------------------------------------------------------------------┼---------------------------------------┤ 32
// | FunctionOffsetOpenTeam │ FunctionOffsetOpenTeamPageAccordingly |
// ├--------------------------------------------------------------------------┼---------------------------------------┤ 40
// │ DebugOriginalFieldOfView │ │
// └--------------------------------------------------------------------------┴---------------------------------------┘ 48
struct Snap::Hutao::UnlockerIsland::IslandEnvironment
{
enum IslandState State;
Expand All @@ -68,6 +53,8 @@ struct Snap::Hutao::UnlockerIsland::IslandEnvironment
bool RemoveOpenTeamProgress;
bool LoopAdjustFpsOnly;

UINT32 FunctionOffsetMickeyWonderMethod;
UINT32 FunctionOffsetMickeyWonderMethodPartner;
UINT32 FunctionOffsetSetFieldOfView;
UINT32 FunctionOffsetSetEnableFogRendering;
UINT32 FunctionOffsetSetTargetFrameRate;
Expand All @@ -78,6 +65,17 @@ struct Snap::Hutao::UnlockerIsland::IslandEnvironment
INT32 DebugOpenTeamCount;
};

typedef struct Il2CppArraySize
{
void* klass;
void* monitor;
void* bounds;
SIZE_T max_length;
UCHAR vector[32];
} Il2CppArraySize;

typedef Il2CppArraySize* (*MickeyWonderMethod)(INT32 value);
typedef Il2CppArraySize* (*MickeyWonderMethodPartner)(void* klass, UINT64 value);
typedef VOID (*SetFieldOfViewFunc)(LPVOID this__, FLOAT value);
typedef VOID (*SetEnableFogRenderingFunc)(bool value);
typedef VOID (*SetTargetFrameRateFunc)(INT32 value);
Expand All @@ -86,9 +84,27 @@ typedef VOID (*OpenTeamPageAccordinglyFunc)(bool value);

struct Snap::Hutao::UnlockerIsland::IslandStaging
{
MickeyWonderMethod MickeyWonder;
MickeyWonderMethodPartner MickeyWonderPartner;
SetFieldOfViewFunc SetFieldOfView;
SetEnableFogRenderingFunc SetEnableFogRendering;
SetTargetFrameRateFunc SetTargetFrameRate;
OpenTeamFunc OpenTeam;
OpenTeamPageAccordinglyFunc OpenTeamPageAccordingly;
};
};

VOID InitializeIslandStaging(Snap::Hutao::UnlockerIsland::IslandStaging& const staging, UINT64 base, Snap::Hutao::UnlockerIsland::IslandEnvironment* pEnvironment)
{
// Magic
staging.MickeyWonder = reinterpret_cast<MickeyWonderMethod>(base + pEnvironment->FunctionOffsetMickeyWonderMethod);
staging.MickeyWonderPartner = reinterpret_cast<MickeyWonderMethodPartner>(base + pEnvironment->FunctionOffsetMickeyWonderMethodPartner);

// Basic functions
staging.SetFieldOfView = reinterpret_cast<SetFieldOfViewFunc>(base + pEnvironment->FunctionOffsetSetFieldOfView);
staging.SetEnableFogRendering = reinterpret_cast<SetEnableFogRenderingFunc>(base + pEnvironment->FunctionOffsetSetEnableFogRendering);
staging.SetTargetFrameRate = reinterpret_cast<SetTargetFrameRateFunc>(base + pEnvironment->FunctionOffsetSetTargetFrameRate);

// Team functions
staging.OpenTeam = reinterpret_cast<OpenTeamFunc>(base + pEnvironment->FunctionOffsetOpenTeam);
staging.OpenTeamPageAccordingly = reinterpret_cast<OpenTeamPageAccordinglyFunc>(base + pEnvironment->FunctionOffsetOpenTeamPageAccordingly);
}
1 change: 1 addition & 0 deletions src/UnlockerIsland/Snap.Hutao.UnlockerIsland/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PCH_H

// 添加要在此处预编译的标头

#include "framework.h"
#include "ntprivate.h"
#include "hook.h"
Expand Down

0 comments on commit 7a7f768

Please sign in to comment.