Skip to content

Commit

Permalink
Fix ExHIBIT Auto-Install with newer games
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed Jul 13, 2023
1 parent 8bfd401 commit c663732
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 11 deletions.
37 changes: 32 additions & 5 deletions StringReloads/AutoInstall/ExHIBIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@ class ExHIBIT : IAutoInstall
ExHIBIT_lstrcpyA lstrcpyAHook;

ExHIBIT_Say10 Say10Hook;
ExHIBIT_Say11 Say12Hook;
ExHIBIT_PrintSub3 PrintSub3Hook;
ExHIBIT_Question QuestionHook;
public void Install()
{
if (Say10Hook == null)
Say10Hook = new ExHIBIT_Say10();
if (Say10Hook == null && Say12Hook == null)
{
try
{
Say10Hook = new ExHIBIT_Say10();
}
catch
{
Say12Hook = new ExHIBIT_Say11();
}
}

if (QuestionHook == null)
{
try
{
QuestionHook = new ExHIBIT_Question();
}
catch { }
}

if (PrintSub3Hook == null)
PrintSub3Hook = new ExHIBIT_PrintSub3();
Expand All @@ -30,9 +50,14 @@ public void Install()
if (lstrcpyAHook == null)
lstrcpyAHook = new ExHIBIT_lstrcpyA(Resident);

Say10Hook.Install();
Say10Hook?.Install();
Say12Hook?.Install();
PrintSub3Hook.Install();
lstrcpyAHook.Install();

if (QuestionHook == null)
lstrcpyAHook.Install();
else
QuestionHook.Install();
}

public bool IsCompatible()
Expand All @@ -51,7 +76,9 @@ public bool IsCompatible()

public void Uninstall()
{
Say10Hook.Uninstall();
Say10Hook?.Uninstall();
Say12Hook?.Uninstall();
QuestionHook?.Uninstall();
PrintSub3Hook.Uninstall();
lstrcpyAHook.Uninstall();
}
Expand Down
3 changes: 3 additions & 0 deletions StringReloads/Hook/Base/Hook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void Compile(bool ImportHook = false, IntPtr? TargetModule = null)
else
Function = GetProcAddress(hModule, Ordinal);

if (Function == null)
throw new Exception("Target Export Not Found");

if (ImportHook)
SetupImportHook(TargetModule == null ? Config.GameBaseAddress : TargetModule.Value.ToPointer());
else
Expand Down
27 changes: 27 additions & 0 deletions StringReloads/Hook/Others/ExHIBIT_Question.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using StringReloads.Engine.String;
using StringReloads.Hook.Base;
using System;

namespace StringReloads.Hook.Others
{
unsafe class ExHIBIT_Question : Hook<ExHIBIT_QuestionDelegate>
{
public override string Library => "resident.dll";

public const string ExportName = "?prepareQuestion@RetouchSystem@@QAEXHPBD@Z";

public override string Export => ExportName;

public override void Initialize()
{
HookDelegate = hExHIBIT_Question;
Compile();
}

private void hExHIBIT_Question(void* This, void* a1, void* Text)
{
Text = EntryPoint.SRL.ProcessString((CString)Text);
Bypass(This, a1, Text);
}
}
}
4 changes: 3 additions & 1 deletion StringReloads/Hook/Others/ExHIBIT_Say.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ unsafe class ExHIBIT_Say10 : Hook<ExHIBIT_Say10Delegate>
{
public override string Library => "resident.dll";

public override string Export => "?say@RetouchAdvCharacter@@QAEXHPBD0_NHHHHPAVRetouchPrintParam@@K@Z";
public const string ExportName ="?say@RetouchAdvCharacter@@QAEXHPBD0_NHHHHPAVRetouchPrintParam@@K@Z";

public override string Export => ExportName;

public override void Initialize()
{
Expand Down
26 changes: 26 additions & 0 deletions StringReloads/Hook/Others/ExHIBIT_SayV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using StringReloads.Engine.String;
using StringReloads.Hook.Base;

namespace StringReloads.Hook.Others
{
unsafe class ExHIBIT_Say11 : Hook<ExHIBIT_Say11Delegate>
{
public override string Library => "resident.dll";

//?say@RetouchAdvCharacter@@QAEXHPBD0_NHHHHPAVRetouchPrintParam@@KPAVUxRuFukidashiData@@@Z
public const string ExportName = "?say@RetouchAdvCharacter@@QAEXHPBD0_NHHHHPAVRetouchPrintParam@@KPAVUxRuFukidashiData@@@Z";

public override string Export => ExportName;

public override void Initialize()
{
HookDelegate = hExHIBIT_Say12;
Compile();
}

void hExHIBIT_Say12(void* This, void* a1, void* a2, byte* Text, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9, void* a10, void* a11) {
Text = EntryPoint.SRL.ProcessString((CString)Text);
Bypass(This, a1, a2, Text, a4, a5, a6, a7, a8, a9, a10, a11);
}
}
}
11 changes: 6 additions & 5 deletions StringReloads/Hook/Others/ExHIBIT_lstrcpyA.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Text;
using Antlr.Runtime.Tree;
using StringReloads.Engine.String;
using StringReloads.Hook.Base;

Expand Down Expand Up @@ -32,25 +33,25 @@ public override void Initialize() { }

string Str = (CString)lpString2;

if (Minify(Str).Length == 0)
if (MinifiedCount(Str) == 0)
return Bypass(lpString1, lpString2);

lpString2 = EntryPoint.SRL.ProcessString((CString)lpString2);
return Bypass(lpString1, lpString2);
}

private string Minify(string Input) {
StringBuilder Builder = new StringBuilder();
private int MinifiedCount(string Input) {
int Result = 0;
foreach (var Char in Input) {
if (Char >= '0' && Char <= '9')
continue;
if (Char >= ',' && Char <= '.')
continue;
if (Char == ';' || char.IsWhiteSpace(Char))
continue;
Builder.Append(Char);
Result++;
}
return Builder.ToString().Replace("NULL", "").Trim();
return Result;
}
}
}
6 changes: 6 additions & 0 deletions StringReloads/Hook/Types/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ namespace StringReloads.Hook

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public unsafe delegate void ExHIBIT_Say10Delegate(void* This, void* a1, void* a2, byte* Text, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9, void* a10);

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public unsafe delegate void ExHIBIT_Say11Delegate(void* This, void* a1, void* a2, byte* Text, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9, void* a10, void* a11);

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public unsafe delegate void ExHIBIT_QuestionDelegate(void* This, void* a1, void* Text);

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public unsafe delegate void ExHIBIT_PrintSub3Delegate(void* This, void* Text, void* a2, void* a3);
Expand Down

0 comments on commit c663732

Please sign in to comment.