Skip to content

Commit 4187390

Browse files
committed
Revert F92LA compatibility changes: d1380b4 and d7e1da5
I am not sure they work, very old develop code.
1 parent 951d4cb commit 4187390

6 files changed

Lines changed: 99 additions & 162 deletions

File tree

src/core/loader.cpp

Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
3535
return TRUE;
3636
}
3737

38-
void Loader::InitFromEntryPoint()
39-
{
40-
typedef function_hooker<0x53ECBD, void(int)> ridle_hook;
41-
typedef function_hooker<0x53ECCB, void(int)> rfidle_hook; // Actually void() but... meh
42-
43-
// This may be called more than once due to the cinit/WinMain trick at Patch().
44-
static bool has_patches = false;
45-
if(has_patches) return;
46-
has_patches = true;
47-
48-
auto& gvm = injector::address_manager::singleton();
49-
50-
#ifndef NDEBUG
51-
if(!gvm.IsSA())
52-
{
53-
static int& gGameState = *mem_ptr(0xC8D4C0).get<int>();
54-
55-
gGameState = 5; // skip intro
56-
if(gvm.IsIII())
57-
MakeNOP(raw_ptr(0x5811F8), 10);
58-
else if(gvm.IsVC())
59-
MakeNOP(raw_ptr(0x601B3B), 10);
60-
61-
if(gvm.IsIII())
62-
MakeJMP(raw_ptr(0x405DB0), &Loader::Log);
63-
else if(gvm.IsVC())
64-
MakeJMP(raw_ptr(0x401000), &Loader::Log);
65-
66-
// Debugger does not attach properly in III/VC DxWnd, so we need to do it manually.
67-
LaunchDebugger();
68-
}
69-
#endif
70-
71-
// Install exception filter to log crashes
72-
InstallExceptionCatcher([](const char* buffer)
73-
{
74-
Log("\n\n");
75-
LogGameVersion();
76-
Log(buffer);
77-
loader.Shutdown();
78-
});
79-
80-
// To be called each frame
81-
auto CallTick = [this](ridle_hook::func_type Idle, int& i)
82-
{
83-
this->Tick();
84-
return Idle(i);
85-
};
86-
87-
// Do tick hook only if possible
88-
if(try_address(ridle_hook::addr)) make_static_hook<ridle_hook>(CallTick);
89-
if(try_address(rfidle_hook::addr)) make_static_hook<rfidle_hook>(CallTick);
90-
91-
this->Startup();
92-
}
93-
9438
/*
9539
* Loader::Patch
9640
* Patches the game code to run the loader
9741
*/
9842
bool Loader::Patch()
9943
{
10044
typedef function_hooker_stdcall<0x8246EC, int(HINSTANCE, HINSTANCE, LPSTR, int)> winmain_hook;
101-
typedef function_hooker<0x8246AC, int()> cinit_hook;
45+
typedef function_hooker<0x53ECBD, void(int)> ridle_hook;
46+
typedef function_hooker<0x53ECCB, void(int)> rfidle_hook; // Actually void() but... meh
10247

10348
auto& gvm = injector::address_manager::singleton();
10449
gvm.set_name("Mod Loader");
@@ -109,39 +54,74 @@ bool Loader::Patch()
10954
if(injector::ReadMemory<int>(0xC920E8)) // RwInitialized -- should enter only when using the mss32 loader on III/VC
11055
{
11156
const char* buf = "You installed Mod Loader wrongly!\n\n"
112-
"You need Ultimate ASI Loader, and modloader.asi must be in the 'scripts/' directory.\n\n"
113-
"Please refer to the 'Readme.txt' or 'Leia-me.txt' for more information.";
57+
"You need Ultimate ASI Loader, and modloader.asi must be in the 'scripts/' directory.\n\n"
58+
"Please refer to the 'Readme.txt' or 'Leia-me.txt' for more information.";
11459
this->Error(buf);
11560
return false;
11661
}
11762

11863
// Hook WinMain to run mod loader
11964
injector::make_static_hook<winmain_hook>([this](winmain_hook::func_type WinMain,
120-
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
65+
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
12166
{
122-
// Avoid circular looping forever
67+
// Avoind circular looping forever
12368
static bool bRan = false;
12469
if(bRan) return WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
12570
bRan = true;
12671

127-
this->InitFromEntryPoint();
128-
auto WinMainNext = (winmain_hook::func_type_raw)ReadRelativeOffset(winmain_hook::addr + 1).get();
129-
auto result = WinMainNext(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
72+
#ifndef NDEBUG
73+
auto& gvm = injector::address_manager::singleton();
74+
if(!gvm.IsSA())
75+
{
76+
static int& gGameState = *mem_ptr(0xC8D4C0).get<int>();
77+
78+
gGameState = 5; // skip intro
79+
if(gvm.IsIII())
80+
MakeNOP(raw_ptr(0x5811F8), 10);
81+
else if(gvm.IsVC())
82+
MakeNOP(raw_ptr(0x601B3B), 10);
83+
84+
if(gvm.IsIII())
85+
MakeJMP(raw_ptr(0x405DB0), &Loader::Log);
86+
else if(gvm.IsVC())
87+
MakeJMP(raw_ptr(0x401000), &Loader::Log);
88+
89+
// Debugger does not attach properly in III/VC DxWnd, so we need to do it manually.
90+
LaunchDebugger();
91+
}
92+
#endif
93+
94+
// Install exception filter to log crashes
95+
InstallExceptionCatcher([](const char* buffer)
96+
{
97+
Log("\n\n");
98+
LogGameVersion();
99+
Log(buffer);
100+
loader.Shutdown();
101+
});
102+
103+
// To be called each frame
104+
auto CallTick = [this](ridle_hook::func_type Idle, int& i)
105+
{
106+
this->Tick();
107+
return Idle(i);
108+
};
109+
110+
// Do tick hook only if possible
111+
if(try_address(ridle_hook::addr)) make_static_hook<ridle_hook>(CallTick);
112+
if(try_address(rfidle_hook::addr)) make_static_hook<rfidle_hook>(CallTick);
113+
114+
// Startup the loader and call WinMain, Shutdown the loader after WinMain.
115+
// If any mod hooked WinMain at Startup, no conflict will happen, we're takin' care of that
116+
{
117+
this->Startup();
118+
auto WinMain = (winmain_hook::func_type_raw) ReadRelativeOffset(winmain_hook::addr + 1).get();
119+
auto result = WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
130120
this->Shutdown();
131121
return result;
122+
}
132123
});
133124

134-
// If possible, startup before WinMain.
135-
// This is important for certain mods (e.g. FLA) that need to change offsets of
136-
// functions that run pre-WinMain (e.g. global constructors).
137-
if(try_address(cinit_hook::addr))
138-
{
139-
injector::make_static_hook<cinit_hook>([this](cinit_hook::func_type cinit) {
140-
this->InitFromEntryPoint();
141-
return cinit();
142-
});
143-
}
144-
145125
return true;
146126
}
147127
else

src/core/loader.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ class Loader : public modloader_t
558558
bool Patch();
559559

560560
// Start or Shutdown the loader
561-
void InitFromEntryPoint();
562561
void Startup();
563562
void Shutdown();
564563

src/plugins/gta3/std.stream/backend.cpp

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -428,46 +428,6 @@ void CAbstractStreaming::BuildPrevOnCdMap()
428428
}
429429

430430

431-
/*
432-
* CAbstractStreaming::Patch
433-
* Same as Patch() but called much later during game loading. This is used to
434-
* improve compatibility with certain mods that modify pointer offsets.
435-
*/
436-
void CAbstractStreaming::PatchDelayed()
437-
{
438-
// Pointers
439-
ms_aInfoForModel = ReadMemory<CStreamingInfo*>(0x40D014, true);
440-
LoadCdDirectory2 = ReadRelativeOffset(0x5B8310 + 1).get<void(const char*, int)>();
441-
clothesDirectory = gvm.IsSA()? ReadMemory<CDirectory*>(lazy_ptr<0x5A419B>(), true) : nullptr;
442-
443-
// Part of standard models hooks
444-
if(gvm.IsSA())
445-
{
446-
MakeCALL(0x40CCA6, raw_ptr(HOOK_RegisterNextModelRead));
447-
MakeNOP(0x40CCA6 + 5, 2);
448-
}
449-
else if(gvm.IsVC())
450-
{
451-
MakeCALL(0x40CCA6, raw_ptr(HOOK_RegisterNextModelRead_VC));
452-
MakeCALL(xVc(0x40B738), raw_ptr(HOOK_RegisterNextModelRead_VC));
453-
MakeNOP(0x40CCA6 + 5, 1);
454-
MakeNOP(xVc(0x40B738) + 5, 1);
455-
}
456-
else if(gvm.IsIII()) // doesn't need to be delayed but keep together VC/SA hooks
457-
{
458-
using xcd_hook1 = function_hooker_thiscall<xIII(0x40A128), char(CStreamingInfo*, int*, int*)>;
459-
using xcd_hook2 = function_hooker_thiscall<xIII(0x40A4F3), char(CStreamingInfo*, int*, int*)>;
460-
461-
auto fn_register = [this](xcd_hook1::func_type GetCdPosnAndSize, CStreamingInfo*& model, int*& pOffset, int*& pSize)
462-
{
463-
RegisterNextModelRead(this->InfoForModelIndex(*model));
464-
return GetCdPosnAndSize(model, pOffset, pSize);
465-
};
466-
467-
make_static_hook<xcd_hook1>(fn_register);
468-
make_static_hook<xcd_hook2>(fn_register);
469-
}
470-
}
471431

472432
/*
473433
* CAbstractStreaming::Patch
@@ -494,7 +454,10 @@ void CAbstractStreaming::Patch()
494454
if(!gvm.IsSA())
495455
this->bHasInitializedStreaming = false;
496456

497-
PatchDelayed();
457+
// Pointers
458+
ms_aInfoForModel = ReadMemory<CStreamingInfo*>(0x40D014, true);
459+
LoadCdDirectory2 = ReadRelativeOffset(0x5B8310 + 1).get<void(const char*, int)>();
460+
clothesDirectory = gvm.IsSA()? ReadMemory<CDirectory*>(lazy_ptr<0x5A419B>(), true) : nullptr;
498461

499462
//
500463
this->InitialiseStructAbstraction();
@@ -562,7 +525,32 @@ void CAbstractStreaming::Patch()
562525
}
563526

564527
// We need to know the next model to be read before the CdStreamRead call happens
565-
// XXX this hook has been moved to PatchDelayed!
528+
if(gvm.IsSA())
529+
{
530+
MakeCALL(0x40CCA6, raw_ptr(HOOK_RegisterNextModelRead));
531+
MakeNOP(0x40CCA6 + 5, 2);
532+
}
533+
else if(gvm.IsVC())
534+
{
535+
MakeCALL(0x40CCA6, raw_ptr(HOOK_RegisterNextModelRead_VC));
536+
MakeCALL(xVc(0x40B738), raw_ptr(HOOK_RegisterNextModelRead_VC));
537+
MakeNOP(0x40CCA6 + 5, 1);
538+
MakeNOP(xVc(0x40B738) + 5, 1);
539+
}
540+
else if(gvm.IsIII())
541+
{
542+
using xcd_hook1 = function_hooker_thiscall<xIII(0x40A128), char(CStreamingInfo*, int*, int*)>;
543+
using xcd_hook2 = function_hooker_thiscall<xIII(0x40A4F3), char(CStreamingInfo*, int*, int*)>;
544+
545+
auto fn_register = [this](xcd_hook1::func_type GetCdPosnAndSize, CStreamingInfo*& model, int*& pOffset, int*& pSize)
546+
{
547+
RegisterNextModelRead(this->InfoForModelIndex(*model));
548+
return GetCdPosnAndSize(model, pOffset, pSize);
549+
};
550+
551+
make_static_hook<xcd_hook1>(fn_register);
552+
make_static_hook<xcd_hook2>(fn_register);
553+
}
566554

567555
// We need to return a new hFile if the file is on disk
568556
if(gvm.IsSA())
@@ -707,29 +695,30 @@ void CAbstractStreaming::Patch()
707695
// Although streamed COLs exist in Vice too, they are checked, so we don't need to check ourselves
708696
if(gvm.IsSA())
709697
{
698+
TraitsSA traits; // see comment above
699+
710700
// CColStore finding method is dummie, so we need to avoid duplicate cols by ourselves
711-
make_static_hook<addcol_hook>([this](addcol_hook::func_type AddColSlot, const char*& name)
701+
make_static_hook<addcol_hook>([this, traits](addcol_hook::func_type AddColSlot, const char*& name)
712702
{
713-
const auto col_start = TraitsSA::BaseIndexForCOL();
714-
return this->FindOrRegisterResource(name, "col", col_start, AddColSlot, name);
703+
return this->FindOrRegisterResource(name, "col", traits.col_start, AddColSlot, name);
715704
});
716705
}
717706

718707
// The following files are in SA only
719708
if(gvm.IsSA())
720709
{
710+
TraitsSA traits;
711+
721712
// CVehicleRecording do not care about duplicates, but we should
722-
make_static_hook<addr3_hook>([this](addr3_hook::func_type RegisterRecordingFile, const char*& name)
713+
make_static_hook<addr3_hook>([this, traits](addr3_hook::func_type RegisterRecordingFile, const char*& name)
723714
{
724-
const auto rrr_start = TraitsSA::BaseIndexForRRR();
725-
return this->FindOrRegisterResource(name, "rrr", rrr_start, RegisterRecordingFile, name);
715+
return this->FindOrRegisterResource(name, "rrr", traits.rrr_start, RegisterRecordingFile, name);
726716
});
727717

728718
// CStreamedScripts do not care about duplicates but we should
729-
make_static_hook<addscm_hook>([this](addscm_hook::func_type RegisterScript, void*& self, const char*& name)
719+
make_static_hook<addscm_hook>([this, traits](addscm_hook::func_type RegisterScript, void*& self, const char*& name)
730720
{
731-
const auto scm_start = TraitsSA::BaseIndexForSCM();
732-
return this->FindOrRegisterResource(name, "scm", scm_start, RegisterScript, self, name);
721+
return this->FindOrRegisterResource(name, "scm", traits.scm_start, RegisterScript, self, name);
733722
});
734723
}
735724
}

src/plugins/gta3/std.stream/streaming.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ class CAbstractStreaming
249249
void InitialiseStructAbstraction();
250250
const LibF92LA& GetF92LA();
251251
void Patch();
252-
void PatchDelayed();
253252
void DataPatch();
254253
void InitRefreshInterface();
255254
void ShutRefreshInterface();

src/shared/traits/gta3/sa.hpp

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ struct TraitsSA : TraitsGTA
1919

2020
// Indices range
2121
const id_t dff_start = 0;
22-
const id_t txd_start = BaseIndexForTXD();
23-
const id_t col_start = BaseIndexForCOL();
24-
const id_t rrr_start = BaseIndexForRRR();
25-
const id_t scm_start = BaseIndexForSCM();
22+
const id_t txd_start = injector::lazy_object<0x5B62CF, unsigned int>::get(); // uint32_t not working properly on GCC here
23+
const id_t col_start = injector::lazy_object<0x5B6314, unsigned int>::get(); // Why?
24+
const id_t rrr_start = injector::lazy_object<0x5B63F1, unsigned int>::get();
25+
const id_t scm_start = injector::lazy_object<0x5B641F, unsigned int>::get();
2626

2727
const id_t max_models = txd_start;
2828
const id_t dff_end = txd_start;
@@ -124,33 +124,4 @@ struct TraitsSA : TraitsGTA
124124
return 0;
125125
}
126126

127-
// Indices range
128-
129-
// TODO do the same in TraitsIII/VC and get rid of non-static dff_start/etc
130-
131-
static id_t BaseIndexForDFF()
132-
{
133-
return 0;
134-
}
135-
136-
static id_t BaseIndexForTXD()
137-
{
138-
// XXX uint32_t not working properly on GCC here
139-
return injector::lazy_object<0x5B62CF, unsigned int>::get();
140-
}
141-
142-
static id_t BaseIndexForCOL()
143-
{
144-
return injector::lazy_object<0x5B6314, unsigned int>::get();
145-
}
146-
147-
static id_t BaseIndexForRRR()
148-
{
149-
return injector::lazy_object<0x5B63F1, unsigned int>::get();;
150-
}
151-
152-
static id_t BaseIndexForSCM()
153-
{
154-
return injector::lazy_object<0x5B641F, unsigned int>::get();
155-
}
156127
};

src/translator/gta3/sa/10us.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static void sa_10us(std::map<memory_pointer_raw, memory_pointer_raw>& map)
2121
// Core
2222
if(true)
2323
{
24-
map[0x8246AC] = 0x8246AC; // call _cinit
2524
map[0x8246EC] = 0x8246EC; // call _WinMain
2625
map[0x53ECBD] = 0x53ECBD; // call _Z4IdlePv
2726
map[0x53ECCB] = 0x53ECCB; // call _Z12FrontendIdlePv

0 commit comments

Comments
 (0)