Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 6, 2025
1 parent e8accb3 commit a7f9830
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 147 deletions.
7 changes: 3 additions & 4 deletions cpp/LunaHook/LunaHook/engine32/Debonosu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ namespace
}
void embed_fun(hook_context *s, TextBuffer buffer)
{
static std::string ts;
ts = buffer.viewA();
auto ts = allocateString(buffer.viewA());

if (_type == 1)
{
s->stack[1] = (DWORD)ts.c_str();
s->stack[1] = (DWORD)ts;
}
else
{
s->ecx = (DWORD)ts.c_str();
s->ecx = (DWORD)ts;
}
}
bool InsertDebonosuScenarioHook()
Expand Down
4 changes: 1 addition & 3 deletions cpp/LunaHook/LunaHook/engine32/Elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ namespace
char nameText[1]; // +4*10+4*3, could be bad address though
};

std::string data_;
TextArgument *scenarioArg_,
*nameArg_;
LPCSTR scenarioText_;
Expand Down Expand Up @@ -265,10 +264,9 @@ namespace
auto text = arg->scenarioText;
if (!Engine::isAddressReadable(text))
return;
data_ = newData;
scenarioArg_ = arg;
scenarioText_ = arg->scenarioText;
arg->scenarioText = (LPCSTR)data_.c_str();
arg->scenarioText = (LPCSTR)allocateString(newData);
}
else if (arg->nameFlag == 0)
{
Expand Down
5 changes: 2 additions & 3 deletions cpp/LunaHook/LunaHook/engine32/Escude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ namespace
}
void embed_fun(hook_context *s, TextBuffer buffer)
{
static std::string data_;
data_ = buffer.strA();
auto data_ = buffer.strA();
auto arg = (HookArgument *)s->stack[1];
if (trimmedText != arg->text)
data_.insert(0, std::string(arg->text, trimmedText - arg->text));
arg->text = data_.c_str();
arg->text = allocateString(data_);
}
} // unnamed namespace
bool InsertEscudeHook()
Expand Down
7 changes: 3 additions & 4 deletions cpp/LunaHook/LunaHook/engine32/LunaSoft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ namespace
}
void hookafter1(hook_context *s, TextBuffer buffer)
{
static std::string newData;
newData = buffer.strA();
newData = cache_.put(newData).first;
s->stack[1] = (ULONG)newData.c_str(); // arg1
auto newData = buffer.strA();
cache_.put(newData);
s->stack[1] = (ULONG)allocateString(newData); // arg1
}
} // namespace Private

Expand Down
5 changes: 1 addition & 4 deletions cpp/LunaHook/LunaHook/engine32/Malie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,6 @@ namespace
// I need a cache retainer here to make sure same text result in same result
void hookafter(hook_context *s, TextBuffer buffer)
{
static std::string data_;
static std::unordered_set<uint64_t> hashes_;
auto text = (LPCWSTR)s->stack[1];
if (!text || !*text || !(text[0] == 0x7 && text[1] == 0x8) && all_ascii(text))
Expand Down Expand Up @@ -1171,10 +1170,8 @@ namespace
data.push_back(0);
data.push_back(0);
data.push_back(0);
data_ = data;
text = (LPCWSTR)data_.c_str();

s->stack[1] = (ULONG)text;
s->stack[1] = (ULONG)allocateString(data);
}
}
void hookBefore(hook_context *s, HookParam *hp, TextBuffer *buffer, uintptr_t *role)
Expand Down
136 changes: 91 additions & 45 deletions cpp/LunaHook/LunaHook/engine32/Mink.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include"Mink.h"
#include "Mink.h"
/** 12/23/2014 jichi: Mink games (not sure the engine name)
* Sample game:
* - [130111] [Mink EGO] お�ちも�にはぜったい言えなぁ�ぁ�つなこと�-- /HB-4*0:64@45164A
Expand Down Expand Up @@ -103,7 +103,7 @@
* 004516dd 8a4c11 1d mov cl,byte ptr ds:[ecx+edx+0x1d]
*/

#if 0 // hook to the caller of dynamic GetGlyphOutlineA
#if 0 // hook to the caller of dynamic GetGlyphOutlineA
/**
* @param addr function address
* @param frame real address of the function, supposed to be the same as addr
Expand Down Expand Up @@ -136,7 +136,7 @@ static bool InsertMinkDynamicHook(LPVOID fun, DWORD frame, DWORD stack)

static void SpecialHookMink(hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{
//DWORD addr = *(DWORD *)(esp_base + hp->offset); // default value
// DWORD addr = *(DWORD *)(esp_base + hp->offset); // default value
DWORD addr = context->eax;
if (!IthGetMemoryRange((LPVOID)(addr), 0, 0))
return;
Expand All @@ -154,64 +154,110 @@ static void SpecialHookMink(hook_context *context, HookParam *hp, TextBuffer *bu
bool InsertMinkHook()
{
const BYTE bytes[] = {
0x38,0x18, // 00451648 3818 cmp byte ptr ds:[eax],bl
0x75, 0x14, // 0045164a 75 14 jnz short .00451660 ; jichi: hook here
0x38,0x5d, 0xf4, // 0045164c 385d f4 cmp byte ptr ss:[ebp-0xc],bl
0x74, 0x07, // 0045164f 74 07 je short .00451658
0x8b,0x45, 0xf0, // 00451651 8b45 f0 mov eax,dword ptr ss:[ebp-0x10]
0x83,0x60, 0x70, 0xfd, // 00451654 8360 70 fd and dword ptr ds:[eax+0x70],0xfffffffd
0x8b,0x45, 0x08 // 00451658 8b45 08 mov eax,dword ptr ss:[ebp+0x8]
0x38, 0x18, // 00451648 3818 cmp byte ptr ds:[eax],bl
0x75, 0x14, // 0045164a 75 14 jnz short .00451660 ; jichi: hook here
0x38, 0x5d, 0xf4, // 0045164c 385d f4 cmp byte ptr ss:[ebp-0xc],bl
0x74, 0x07, // 0045164f 74 07 je short .00451658
0x8b, 0x45, 0xf0, // 00451651 8b45 f0 mov eax,dword ptr ss:[ebp-0x10]
0x83, 0x60, 0x70, 0xfd, // 00451654 8360 70 fd and dword ptr ds:[eax+0x70],0xfffffffd
0x8b, 0x45, 0x08 // 00451658 8b45 08 mov eax,dword ptr ss:[ebp+0x8]
};
enum
{
addr_offset = 2
};
enum { addr_offset = 2 };
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress);
//ULONG addr = 0x45164a;
//ULONG addr = 0x451648;
//ULONG addr = 0x4521a8;
//GROWL_DWORD(addr);
if (!addr) {
// ULONG addr = 0x45164a;
// ULONG addr = 0x451648;
// ULONG addr = 0x4521a8;
// GROWL_DWORD(addr);
if (!addr)
{
ConsoleOutput("Mink: pattern not found");
return false;
}

HookParam hp;
hp.address = addr + addr_offset;
hp.offset=regoffset(eax); // -8
hp.offset = regoffset(eax); // -8
hp.split = 0x64;
hp.type = USING_SPLIT|DATA_INDIRECT|USING_CHAR; // 0x18
hp.type = USING_SPLIT | DATA_INDIRECT | USING_CHAR; // 0x18
hp.text_fun = SpecialHookMink;
ConsoleOutput("INSERT Mink");
return NewHook(hp, "Mink");

//ConsoleOutput("Mink: disable GDI hooks");
// ConsoleOutput("Mink: disable GDI hooks");
//
}

bool Mink2::attach_function() {
bool Mink2::attach_function()
{
const BYTE pattern[] = {
//破談屋
//https://vndb.org/v2719
0xF7,0xC7,0x03,0x00,0x00,0x00,
0x75,XX,
0xC1,0xE9,0x02,
0x83,0xE2,0x03,
0x83,0xF9,0x08,
0x72,XX
};
bool found=false;
// 破談屋
// https://vndb.org/v2719
0xF7, 0xC7, 0x03, 0x00, 0x00, 0x00,
0x75, XX,
0xC1, 0xE9, 0x02,
0x83, 0xE2, 0x03,
0x83, 0xF9, 0x08,
0x72, XX};
bool found = false;
for (auto addr : Util::SearchMemory(pattern, sizeof(pattern), PAGE_EXECUTE, processStartAddress, processStopAddress))
{
addr = MemDbg::findEnclosingAlignedFunction(addr,0x100);
if (addr == 0)return false;
HookParam hp;
hp.address = addr;
hp.offset=stackoffset(2);
hp.length_offset=3;
hp.type = USING_STRING;
found|=NewHook(hp, "Mink");
}
return found;
}
bool Mink::attach_function() {

return InsertMinkHook();
}
addr = MemDbg::findEnclosingAlignedFunction(addr, 0x100);
if (addr == 0)
return false;
HookParam hp;
hp.address = addr;
hp.offset = stackoffset(2);
hp.length_offset = 3;
hp.type = USING_STRING;
found |= NewHook(hp, "Mink");
}
return found;
}
bool Mink::attach_function()
{

return InsertMinkHook();
}

bool Mink3::attach_function()
{
const BYTE pattern[] = {
// 夜勤病棟 復刻版+
0xff, 0x15, XX4,
0x33, 0xdb,
0x89, 0x44, 0x24, XX,
0x85, 0xc0,
0x7e, XX,
0x8a, 0x07,
0x8d, 0x4c, 0x24, 0x10,
0x50,
0xe8, XX4,
0x83, 0xf8, 0x02,
0x75, 0x08,
0x03, 0xd8,
0x03, 0xf8,
0x03, 0xf0,
0xeb, XX,
0x57,
0x8b, 0xcd,
0xe8, XX4,
0x25, 0xff, 0x00, 0x00, 0x00,
0x83, 0xe8, 0x00};
auto addr = MemDbg::findBytes(pattern, sizeof(pattern), processStartAddress, processStopAddress);
if (!addr)
return false;
addr = MemDbg::findEnclosingAlignedFunction(addr, 0x100);
if (!addr)
return false;
HookParam hp;
hp.address = addr;
hp.offset = stackoffset(1);
hp.type = USING_STRING | EMBED_ABLE | EMBED_AFTER_OVERWRITE | EMBED_DYNA_SJIS;
hp.embed_hook_font = F_TextOutA;
hp.lineSeparator = L"\\n";
PcHooks::hookGDIFunctions(TextOutA);
return NewHook(hp, "Mink");
}
46 changes: 31 additions & 15 deletions cpp/LunaHook/LunaHook/engine32/Mink.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@


class Mink:public ENGINE{
public:
Mink(){

check_by=CHECK_BY::FILE;
check_by_target=L"*.at2";//Mink, sample files: voice.at2, voice.det, voice.nme
class Mink : public ENGINE
{
public:
Mink()
{

check_by = CHECK_BY::FILE;
check_by_target = L"*.at2"; // Mink, sample files: voice.at2, voice.det, voice.nme
};
bool attach_function();
bool attach_function();
};

class Mink2:public ENGINE{
public:
Mink2(){

check_by=CHECK_BY::FILE;
check_by_target=L"Scr\\*.sc";
is_engine_certain=false;
class Mink2 : public ENGINE
{
public:
Mink2()
{

check_by = CHECK_BY::FILE;
check_by_target = L"Scr\\*.sc";
is_engine_certain = false;
};
bool attach_function();
};
class Mink3 : public ENGINE
{
public:
Mink3()
{
// 夜勤病棟 復刻版+
check_by = CHECK_BY::FILE_ALL;
check_by_target = check_by_list{L"voice*.dat", L"tpd.dat", L"tms.dat", L"thm.dat", L"se.dat", L"scr.dat", L"rec.dat", L"bgm.dat", L"cgm.dat", L"gpd.dat", L"gpdtp.dat", L"mov.dat", L"msk.dat", L"msktp.dat", L"read.dat"};
is_engine_certain = false;
};
bool attach_function();
bool attach_function();
};
6 changes: 2 additions & 4 deletions cpp/LunaHook/LunaHook/engine32/QLIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,8 @@ namespace
newData = newData + "[n]";
else if (endtype == 2)
newData = newData + "[c]";
static std::string data_;
data_ = newData;
s->edx = (ULONG)data_.c_str(); // reset arg1
*(DWORD *)(s->edx - 4) = data_.size();
s->edx = (ULONG)allocateString(newData); // reset arg1
*(DWORD *)(s->edx - 4) = newData.size();
// arg->size = data_.size(); // no idea why this will crash ...

//*(DWORD *)(s->edx - 4) = newData.size() + trimmedText - text;
Expand Down
8 changes: 0 additions & 8 deletions cpp/LunaHook/LunaHook/engine32/Siglus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,11 +1764,7 @@ namespace
void hookafter(hook_context *s, TextBuffer buffer)
{
auto arg = (TextUnionW *)(type_ == Type1 ? s->ecx : s->stack[1]);
auto argValue = *arg;
arg->setText(buffer.viewW());

// Restoring is indispensible, and as a result, the default hook does not work
//*arg = argValue;
}
}
bool attach(ULONG startAddress, ULONG stopAddress) // attach scenario
Expand All @@ -1794,8 +1790,6 @@ namespace OtherHook
namespace Private
{

TextUnionW *arg_,
argValue_;
void hookBefore(hook_context *s, HookParam *hp, TextBuffer *buffer, uintptr_t *role)
{
static std::wstring text_;
Expand Down Expand Up @@ -1833,8 +1827,6 @@ namespace OtherHook
void hookafter2(hook_context *s, TextBuffer buffer)
{
auto arg = (TextUnionW *)s->stack[0];
arg_ = arg;
argValue_ = *arg;
arg->setText(buffer.viewW());
}

Expand Down
8 changes: 3 additions & 5 deletions cpp/LunaHook/LunaHook/engine32/Taskforce2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,11 @@ namespace
}
void hookafter(hook_context *s, TextBuffer buffer)
{
static std::string data_;
std::string newData = buffer.strA();
data_ = newData;
int capacity = s->stack[1]; // arg 2, should always be 0x1000
if (data_.size() >= capacity)
data_ = data_.substr(0, capacity - 1);
s->stack[2] = (ULONG)data_.c_str(); // arg 3
if (newData.size() >= capacity)
newData = newData.substr(0, capacity - 1);
s->stack[2] = (ULONG)allocateString(newData); // arg 3
}
} // namespace Private

Expand Down
5 changes: 2 additions & 3 deletions cpp/LunaHook/LunaHook/engine32/Unicorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,8 @@ namespace

void hookafter(hook_context *s, TextBuffer buffer)
{
static std::string data_;
data_ = buffer.strA();
s->stack[1] = (ULONG)data_.c_str();
auto data_ = buffer.strA();
s->stack[1] = (ULONG)allocateString(data_);
s->stack[2] = data_.size();
}
} // namespace Private
Expand Down
Loading

0 comments on commit a7f9830

Please sign in to comment.