Skip to content

Commit d090723

Browse files
author
makipl
committed
fixed jp + recreated nulled debug function
1 parent c7c6888 commit d090723

4 files changed

Lines changed: 75 additions & 31 deletions

File tree

ff8_demaster/coreHeader.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88
#include <vector>
99
#include <Windows.h>
10+
#include <Psapi.h>
1011
#include <StackWalker.h>
1112
#include <INIReader.h>
1213
#include "renderer.h"
@@ -75,7 +76,7 @@ extern DWORD* langIdent_ESI;
7576

7677
extern int currentStage;
7778

78-
extern std::unique_ptr<FILE,decltype(&fclose)> logFile;
79+
extern std::unique_ptr<FILE, decltype(&fclose)> logFile;
7980
void OutputDebug(const char* fmt, ...);
8081
bool DDSorPNG(char* buffer, size_t size, const char* fmt, ...);
8182

@@ -87,15 +88,15 @@ void RenderCompressedTexture(bimg::ImageContainer* img, TextureFormatInfo& texIn
8788
class DemasteredStackWalker : public StackWalker
8889
{
8990
public:
90-
DemasteredStackWalker() : StackWalker() {}
91+
DemasteredStackWalker() : StackWalker() {}
9192
protected:
92-
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
93-
{
94-
// Silence is golden.
95-
}
96-
97-
virtual void OnOutput(LPCSTR szText)
98-
{
99-
OutputDebug(szText);
100-
}
93+
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
94+
{
95+
// Silence is golden.
96+
}
97+
98+
virtual void OnOutput(LPCSTR szText)
99+
{
100+
OutputDebug(szText);
101+
}
101102
};

ff8_demaster/dllmain.cpp

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@
55
/*
66
KURSE ALL SEEDS!
77
Fushururu
8-
Do you know demaster is going to be reborn?
8+
Are you with the Garden Master or Cid?
9+
>be non-human
10+
>pay a lot of money to build BalambGarden
11+
>after that some useless guy is the boss
12+
>no one knows about you
13+
>you are living in the basement
14+
>alone
15+
16+
Yeah... So looks like money can't buy
17+
umm... well.. life? Hey, you are student
18+
in the garden built from my money
19+
and you were trained to be missionary
20+
and then you just walk in and kill me
21+
NICE JOB
922
*/
1023

1124
/*
1225
*
1326
*
1427
*/
1528
DWORD IMAGE_BASE = 0;
29+
DWORD IMAGE_SIZE = 0;
30+
DWORD THIS_BASE = 0;
31+
DWORD THIS_SIZE = 0;
1632
DWORD OPENGL_HANDLE = 0;
1733
const char* DIRECT_IO_EXPORT_DIR = "DEMASTER_EXP\\";
1834
std::unique_ptr<FILE, decltype(&fclose)> logFile{ nullptr, fclose };
@@ -34,21 +50,37 @@ BOOL BATTLE_STAGE_FORCE_RELOAD;
3450

3551
void OutputDebug(const char* fmt, ...)
3652
{
37-
#if _DEBUG
38-
va_list args;
39-
char tmp_str[1024];
53+
54+
#if _DEBUG && !JAPANESE_PATCH
55+
//DWORD fmtPtr = (DWORD)fmt;
56+
//if (
57+
// IMAGE_BASE <= fmtPtr && fmtPtr <= IMAGE_BASE + IMAGE_SIZE
58+
// ||
59+
// THIS_BASE <= fmtPtr && fmtPtr <= THIS_BASE + THIS_SIZE
60+
// )
61+
//{
62+
// return;
63+
//}
64+
//static StackWalker sw;
65+
// sw.ShowCallstack();
66+
if (IsBadReadPtr(fmt, 4)) return;
67+
std::string fmtString = std::string(fmt);
68+
if (fmtString.substr(0, 7) == std::string("GLERROR"))
69+
return;
70+
va_list args;
71+
char tmp_str[1024];
4072

41-
va_start(args, fmt);
42-
vsnprintf(tmp_str, sizeof(tmp_str), fmt, args);
43-
va_end(args);
73+
va_start(args, fmt);
74+
vsnprintf(tmp_str, sizeof(tmp_str), fmt, args);
75+
va_end(args);
4476

45-
printf(tmp_str);
77+
printf(tmp_str);
4678

47-
if (logFile)
48-
{
49-
fwrite(tmp_str, sizeof(char), strlen(tmp_str), logFile.get());
50-
fflush(logFile.get());
51-
}
79+
if (logFile)
80+
{
81+
fwrite(tmp_str, sizeof(char), strlen(tmp_str), logFile.get());
82+
fflush(logFile.get());
83+
}
5284
#endif
5385
}
5486

@@ -149,6 +181,7 @@ void ReadConfigFile()
149181
WORLD_TEXTURES = conf.GetInteger("", "WORLD_TEXTURES", 0);
150182
TEXTURE_PATCH = conf.GetInteger("", "TEXTURE_PATCH", 1); //this one lacks actual demaster.conf so default to 1
151183
LINEAR_PATCH = conf.GetInteger("", "LINEAR_PATCH", 1);
184+
DEBUG_PATCH = conf.GetInteger("", "DEBUG_PATCH", 0);
152185
OPENGL_HOOK = conf.GetInteger("", "OPENGL_HOOK", 0);
153186
BATTLE_STAGE_ANIMATION_DELAY = conf.GetInteger("", "BATTLE_STAGE_ANIMATION_DELAY", 100);
154187
BATTLE_STAGE_FORCE_RELOAD = conf.GetInteger("", "BATTLE_STAGE_FORCE_RELOAD", 0);
@@ -327,9 +360,16 @@ BOOL WINAPI DllMain(
327360
HMODULE IMG_BASE = GetModuleHandleA("FFVIII_EFIGS");
328361
#endif
329362
IMAGE_BASE = (long long)IMG_BASE;
330-
OPENGL_HANDLE = (long long)GetModuleHandleA("OPENGL32");
331-
OutputDebug("IMAGE_BASE at: %lX; OPENGL at: %lX\n", IMAGE_BASE, OPENGL_HANDLE);
332363

364+
MODULEINFO modinfo = {};
365+
K32GetModuleInformation(GetCurrentProcess(), IMG_BASE, &modinfo, sizeof(MODULEINFO));
366+
IMAGE_SIZE = modinfo.SizeOfImage;
367+
368+
THIS_BASE = (DWORD)hinstDLL;
369+
K32GetModuleInformation(GetCurrentProcess(), hinstDLL, &modinfo, sizeof(MODULEINFO));
370+
THIS_SIZE = modinfo.SizeOfImage;
371+
372+
OutputDebug("IMAGE_BASE at: %lX; OPENGL at: %lX\n", IMAGE_BASE, OPENGL_HANDLE);
333373
GetWindow();
334374

335375
//LET'S GET THE HACKING DONE
@@ -339,13 +379,14 @@ BOOL WINAPI DllMain(
339379
ApplyUVPatch();
340380
if (TEXTURE_PATCH && DIRECT_IO)
341381
ReplaceTextureFunction();
342-
//if (DEBUG_PATCH) //it's just one func ;-;
343-
// ApplyDebugOutputPatchV2();
382+
if (DEBUG_PATCH) //it's just one func ;-;
383+
InjectJMP(IMAGE_BASE + GetAddress(NULLSUB_DEBUG), (DWORD)OutputDebug);
344384
if (LINEAR_PATCH)
345385
ApplyFilteringPatch();
346386
if (OPENGL_HOOK)
347387
HookOpenGL();
348388

389+
349390
return 1; //all success
350391
}
351392
#undef CRASHLOG

ff8_demaster/ff8_demaster.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<LinkIncremental>true</LinkIncremental>
5454
<IncludePath>vendor\include\;vendor\include\compat\msvc;$(IncludePath)</IncludePath>
5555
<LibraryPath>vendor\lib\;vendor\lib\bgfx;$(LibraryPath)</LibraryPath>
56-
<OutDir>$(SolutionDir).dist\$(Configuration)\</OutDir>
56+
<OutDir>$(SolutionDir).dist\debug\</OutDir>
5757
<IntDir>$(SolutionDir).build\$(Configuration)\</IntDir>
5858
</PropertyGroup>
5959
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

ff8_demaster/mymemory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum ADDRESS_NAME
1414
BGFILENAME1, BGFILENAME2, CHECKTEXREPAVAIL, _ASM_FIELDBGRETADDR3, DISABLETPAGELIMIT, _ASM_FIELDBGRETADDR2, DS_FREE, DS_TEXIMG,
1515
_BSPBACKADD1, _BSPBACKADD2, BATTLEJMPPATCH1, BATTLEJMPPATCH2, BTLMON0, BTLMON1, BTLMON2, BTLMON3, BTLMON4, BTLMON5, BTLMON6, BHP,
1616
_BHPBACKADD1, _BHPBACKADD2, NEWGLTEX_CHARA, BCPBACKADD1, BCPBACKADD2, BCPBACKADD3, CLTBACKADD1, CLTBACKADD2, UPLOADVRAM, IOFUNC1,
17-
IOFUNC2, IOFUNC3, IOFUNC4, IOFUNC5, IOFUNC6, FILTERPATCH1, FILTERPATCH2, FILTERPATCH3, FILTERPATCH4, WINDOWTITLE
17+
IOFUNC2, IOFUNC3, IOFUNC4, IOFUNC5, IOFUNC6, FILTERPATCH1, FILTERPATCH2, FILTERPATCH3, FILTERPATCH4, WINDOWTITLE, NULLSUB_DEBUG
1818
};
1919

2020
void InitTable();
@@ -91,7 +91,8 @@ const std::map<ADDRESS_NAME, std::vector<unsigned int>> PATCHADDRESS =
9191
{FILTERPATCH2 , std::vector<unsigned int>{ 0x0 , 0x1569409 , 0x1569899 }},
9292
{FILTERPATCH3 , std::vector<unsigned int>{ 0x0 , 0x156A348 , 0x156a7d8 }},
9393
{FILTERPATCH4 , std::vector<unsigned int>{ 0x0 , 0x156A359 , 0x156a7e9 }},
94-
{WINDOWTITLE , std::vector<unsigned int>{ 0x0 , 0x1601065 , 0x1601935 }}
94+
{WINDOWTITLE , std::vector<unsigned int>{ 0x0 , 0x1601065 , 0x1601935 }},
95+
{NULLSUB_DEBUG , std::vector<unsigned int>{ 0x0 , 0x0 , 0x33DC0 }}
9596
#else
9697
{IOFUNC1 , std::vector<unsigned int>{ 0x0 , 0x0 , 0x3649C }},
9798
{IOFUNC6 , std::vector<unsigned int>{ 0x0 , 0x0 , 0x3653A }},
@@ -154,5 +155,6 @@ const std::map<ADDRESS_NAME, std::vector<unsigned int>> PATCHADDRESS =
154155
{CHECKTEXREPAVAIL , std::vector<unsigned int>{ 0x0 , 0x0 , 0x1793BA8 }},
155156
{BGFILENAME1 , std::vector<unsigned int>{ 0x0 , 0x0 , 0x1793C94 }},
156157
{BGFILENAME2 , std::vector<unsigned int>{ 0x0 , 0x0 , 0x18A85A4 }},
158+
{NULLSUB_DEBUG , std::vector<unsigned int>{ 0x0 , 0x0 , 0x33E50 }},
157159
#endif
158160
};

0 commit comments

Comments
 (0)