2022-07-01 00:00:39 -06:00
# include "pch-il2cpp.h"
2022-05-17 03:13:41 +03:00
# include "DialogSkip.h"
# include <helpers.h>
# include <cheat/game/EntityManager.h>
2022-06-08 07:52:24 +03:00
namespace cheat : : feature
2022-05-17 03:13:41 +03:00
{
static void InLevelCutScenePageContext_UpdateView_Hook ( app : : InLevelCutScenePageContext * __this , MethodInfo * method ) ;
static void InLevelCutScenePageContext_ClearView_Hook ( app : : InLevelCutScenePageContext * __this , MethodInfo * method ) ;
2022-06-08 07:52:24 +03:00
static void CriwareMediaPlayer_Update ( app : : CriwareMediaPlayer * __this , MethodInfo * method ) ;
2022-05-17 03:13:41 +03:00
DialogSkip : : DialogSkip ( ) : Feature ( ) ,
2022-06-08 07:52:24 +03:00
NF ( f_Enabled , " Auto talk " , " AutoTalk " , false ) ,
NF ( f_AutoSelectDialog , " Auto select dialog " , " AutoTalk " , true ) ,
2022-07-01 00:00:39 -06:00
NF ( f_ExcludeImportant , " Exclude Katheryne/Tubby/Wagner " , " AutoTalk " , true ) ,
2022-06-08 07:52:24 +03:00
NF ( f_FastDialog , " Fast dialog " , " AutoTalk " , false ) ,
NF ( f_CutsceneUSM , " Skip Cutscenes " , " AutoTalk " , false ) ,
NF ( f_TimeSpeedup , " Time Speed " , " AutoTalk " , 5.0f )
2022-05-17 03:13:41 +03:00
{
2022-05-29 22:51:08 +03:00
HookManager : : install ( app : : MoleMole_InLevelCutScenePageContext_UpdateView , InLevelCutScenePageContext_UpdateView_Hook ) ;
HookManager : : install ( app : : MoleMole_InLevelCutScenePageContext_ClearView , InLevelCutScenePageContext_ClearView_Hook ) ;
2022-06-08 07:52:24 +03:00
HookManager : : install ( app : : CriwareMediaPlayer_Update , CriwareMediaPlayer_Update ) ;
2022-05-17 03:13:41 +03:00
}
const FeatureGUIInfo & DialogSkip : : GetGUIInfo ( ) const
{
static const FeatureGUIInfo info { " Auto Talk " , " World " , true } ;
return info ;
}
void DialogSkip : : DrawMain ( )
{
ConfigWidget ( " Enabled " , f_Enabled , " Automatically continue the dialog. " ) ;
ConfigWidget ( " Auto-select Dialog " , f_AutoSelectDialog , " Automatically select dialog choices. " ) ;
if ( f_AutoSelectDialog )
{
ImGui : : Indent ( ) ;
2022-07-01 00:00:39 -06:00
ConfigWidget ( " Exclude Katheryne/Tubby/Wagner " , f_ExcludeImportant , " Exclude Kath/Tubby/Wagner from auto-select. " ) ;
2022-05-17 03:13:41 +03:00
ImGui : : Unindent ( ) ;
}
ConfigWidget ( " Fast Dialog " , f_FastDialog , " Speeds up Time " ) ;
if ( f_FastDialog )
{
ConfigWidget ( f_TimeSpeedup , 0.1f , 2.0f , 50.0f , " Time Speedup Multipler \n Higher Values will lead to sync issues with servers \n and is not recommended for Laggy Internet connections. " ) ;
}
2022-06-08 07:52:24 +03:00
ConfigWidget ( " Skip Cutscenes " , f_CutsceneUSM , " Automatically skips game movies. " ) ;
2022-05-17 03:13:41 +03:00
}
bool DialogSkip : : NeedStatusDraw ( ) const
2022-06-08 07:52:24 +03:00
{
return f_Enabled | | f_CutsceneUSM ;
2022-05-17 03:13:41 +03:00
}
2022-06-08 07:52:24 +03:00
void DialogSkip : : DrawStatus ( )
2022-05-17 03:13:41 +03:00
{
2022-06-08 07:52:24 +03:00
if ( f_Enabled )
ImGui : : Text ( " Dialog [%s%s%s%s%s] " ,
f_AutoSelectDialog ? " Auto " : " Manual " ,
f_AutoSelectDialog & & ( f_ExcludeImportant | | f_FastDialog ) ? " | " : " " ,
f_ExcludeImportant ? " Exc " : " " ,
f_ExcludeImportant & & f_FastDialog ? " | " : " " ,
f_FastDialog ? " Fast " : " Normal " ) ;
ImGui : : Text ( f_CutsceneUSM ? " Skip Cutscenes " : " " ) ;
2022-05-17 03:13:41 +03:00
}
DialogSkip & DialogSkip : : GetInstance ( )
{
static DialogSkip instance ;
return instance ;
}
2022-06-08 07:52:24 +03:00
// Raised when dialog view updating
2022-05-17 03:13:41 +03:00
// We call free click, if auto talk enabled, that means we just emulate user click
// When appear dialog choose we create notify with dialog select first item.
2022-06-08 07:52:24 +03:00
void DialogSkip : : OnCutScenePageUpdate ( app : : InLevelCutScenePageContext * context )
2022-05-17 03:13:41 +03:00
{
if ( ! f_Enabled )
return ;
auto talkDialog = context - > fields . _talkDialog ;
if ( talkDialog = = nullptr )
return ;
if ( f_FastDialog )
2022-05-28 04:21:08 -06:00
app : : Time_set_timeScale ( f_TimeSpeedup , nullptr ) ;
2022-07-23 03:32:01 +01:00
else
app : : Time_set_timeScale ( 1.0f , nullptr ) ;
2022-05-17 03:13:41 +03:00
bool isImportant = false ;
if ( f_ExcludeImportant )
{
// TODO: Add a custom filter in the future where users can
// add their own name substrings of entities to avoid
// speeding up dialog on.
std : : vector < std : : string > impEntitiesNames = {
2022-06-08 07:52:24 +03:00
" Djinn " ,
2022-07-01 00:00:39 -06:00
" Katheryne " ,
2022-08-31 08:31:54 -06:00
" Wagner " ,
" Ahangar "
2022-05-17 03:13:41 +03:00
} ;
auto dialogPartnerID = context - > fields . _inteeID ;
auto & manager = game : : EntityManager : : instance ( ) ;
auto dialogPartner = manager . entity ( dialogPartnerID ) ;
auto dialogPartnerName = dialogPartner - > name ( ) ;
for ( auto impEntityName : impEntitiesNames )
{
if ( dialogPartnerName . find ( impEntityName ) ! = - 1 ) {
LOG_DEBUG ( " %s %s %d " , dialogPartnerName . c_str ( ) , impEntityName , dialogPartnerName . find ( impEntityName ) ) ;
isImportant = true ;
break ;
}
}
}
2022-06-08 07:52:24 +03:00
if ( talkDialog - > fields . _inSelect & & f_AutoSelectDialog & & ! isImportant )
{
int32_t value = 0 ;
auto object = il2cpp_value_box ( ( Il2CppClass * ) * app : : Int32__TypeInfo , & value ) ;
2022-07-01 00:00:39 -06:00
app : : Notify notify { } ;
notify . type = app : : MoleMole_NotifyTypes__Enum : : DialogSelectNotify ;
notify . body = ( app : : Object * ) object ;
2022-06-08 07:52:24 +03:00
app : : MoleMole_TalkDialogContext_OnDialogSelectItem ( talkDialog , & notify , nullptr ) ;
}
else if ( ! talkDialog - > fields . _inSelect )
app : : MoleMole_InLevelCutScenePageContext_OnFreeClick ( context , nullptr ) ;
2022-05-17 03:13:41 +03:00
}
2022-06-08 07:52:24 +03:00
static void InLevelCutScenePageContext_UpdateView_Hook ( app : : InLevelCutScenePageContext * __this , MethodInfo * method )
{
CALL_ORIGIN ( InLevelCutScenePageContext_UpdateView_Hook , __this , method ) ;
2022-05-17 03:13:41 +03:00
DialogSkip & dialogSkip = DialogSkip : : GetInstance ( ) ;
dialogSkip . OnCutScenePageUpdate ( __this ) ;
2022-06-08 07:52:24 +03:00
}
2022-05-17 03:13:41 +03:00
// Raised when exiting a dialog. We try to hackishly return to normal value.
// Should be a better way to store the pre-dialog speed using Time_get_timeScale.
static void InLevelCutScenePageContext_ClearView_Hook ( app : : InLevelCutScenePageContext * __this , MethodInfo * method )
{
2022-05-28 04:21:08 -06:00
float gameSpeed = app : : Time_get_timeScale ( nullptr ) ;
2022-05-17 03:13:41 +03:00
if ( gameSpeed > 1.0f )
2022-05-28 04:21:08 -06:00
app : : Time_set_timeScale ( 1.0f , nullptr ) ;
2022-05-17 03:13:41 +03:00
CALL_ORIGIN ( InLevelCutScenePageContext_ClearView_Hook , __this , method ) ;
}
2022-06-08 07:52:24 +03:00
static void CriwareMediaPlayer_Update ( app : : CriwareMediaPlayer * __this , MethodInfo * method )
{
DialogSkip & dialogSkip = DialogSkip : : GetInstance ( ) ;
if ( dialogSkip . f_CutsceneUSM )
app : : CriwareMediaPlayer_Skip ( __this , nullptr ) ;
return CALL_ORIGIN ( CriwareMediaPlayer_Update , __this , method ) ;
}
2022-05-17 03:13:41 +03:00
}