@@ -373,7 +373,6 @@ namespace YYTK
373
373
{
374
374
last_status = YYC::GmpFindRVArrayOffset (
375
375
array_equals,
376
- m_RunnerInterface,
377
376
&m_RValueArrayOffset
378
377
);
379
378
}
@@ -606,11 +605,43 @@ namespace YYTK
606
605
607
606
if (!AurieSuccess (last_status))
608
607
{
609
- this ->PrintWarning (
608
+ this ->PrintError (
609
+ __FILE__,
610
+ __LINE__,
610
611
" Failed to initialize stage 2 hooks! (%s)" ,
611
612
AurieStatusToString (last_status)
612
613
);
613
614
615
+ return last_status;
616
+ }
617
+
618
+ last_status = GmpGetYYObjectBaseAdd (
619
+ m_RunnerInterface,
620
+ &m_AddToYYObjectBase
621
+ );
622
+
623
+ if (!AurieSuccess (last_status))
624
+ {
625
+ this ->PrintWarning (
626
+ " Failed to find YYObjectBase::Add! (%s)" ,
627
+ AurieStatusToString (last_status)
628
+ );
629
+
630
+ // return last_status;
631
+ }
632
+
633
+ last_status = GmpGetFindAllocSlotFromName (
634
+ m_AddToYYObjectBase,
635
+ &m_FindAllocSlot
636
+ );
637
+
638
+ if (!AurieSuccess (last_status))
639
+ {
640
+ this ->PrintWarning (
641
+ " Failed to find FindAllocSlot! (%s)" ,
642
+ AurieStatusToString (last_status)
643
+ );
644
+
614
645
// return last_status;
615
646
}
616
647
@@ -624,6 +655,9 @@ namespace YYTK
624
655
CmWriteOutput (CM_GRAY, " - m_RValueArrayOffset at 0x%llx" , m_RValueArrayOffset);
625
656
CmWriteOutput (CM_GRAY, " - m_GetRoomData at 0x%p" , m_GetRoomData);
626
657
CmWriteOutput (CM_GRAY, " - m_RunRoom at 0x%p" , m_RunRoom);
658
+ CmWriteOutput (CM_GRAY, " - m_AddToYYObjectBase at 0x%p" , m_AddToYYObjectBase);
659
+ CmWriteOutput (CM_GRAY, " - m_FindAllocSlot at 0x%p" , m_FindAllocSlot);
660
+
627
661
CmWriteOutput (
628
662
CM_GRAY,
629
663
" - RFunction Entry Type: %s" ,
@@ -980,12 +1014,28 @@ namespace YYTK
980
1014
OUT RValue*& Member
981
1015
)
982
1016
{
983
- if (!m_RunnerInterface.StructGetMember )
984
- return AURIE_MODULE_INTERNAL_ERROR;
985
-
986
1017
if (Instance.m_Kind != VALUE_OBJECT)
987
1018
return AURIE_INVALID_PARAMETER;
988
1019
1020
+ // If we don't have the interface function, we use a fallback method
1021
+ if (!m_RunnerInterface.StructGetMember )
1022
+ {
1023
+ int32_t variable_hash = 0 ;
1024
+ AurieStatus last_status = AURIE_SUCCESS;
1025
+
1026
+ last_status = this ->GetVariableSlot (
1027
+ Instance,
1028
+ MemberName,
1029
+ variable_hash
1030
+ );
1031
+
1032
+ if (!AurieSuccess (last_status))
1033
+ return last_status;
1034
+
1035
+ Member = &Instance.m_Object ->InternalGetYYVarRef (variable_hash);
1036
+ return AURIE_SUCCESS;
1037
+ }
1038
+
989
1039
RValue* member_value = m_RunnerInterface.StructGetMember (&Instance, MemberName);
990
1040
991
1041
if (!member_value)
@@ -1004,33 +1054,109 @@ namespace YYTK
1004
1054
if (Instance.m_Kind != VALUE_OBJECT)
1005
1055
return AURIE_INVALID_PARAMETER;
1006
1056
1057
+ // Determine the number of keys in the struct
1058
+ // Use a fallback method if StructGetKeys isn't available in the interface
1059
+ int instance_variable_count = -1 ;
1007
1060
if (!m_RunnerInterface.StructGetKeys )
1008
- return AURIE_MODULE_INTERNAL_ERROR;
1061
+ {
1062
+ AurieStatus last_status = AURIE_SUCCESS;
1063
+ RValue name_count;
1009
1064
1010
- if (!m_RunnerInterface.StructGetMember )
1011
- return AURIE_MODULE_INTERNAL_ERROR;
1065
+ // Ask the engine for the count - this function may not be present
1066
+ last_status = CallBuiltinEx (
1067
+ name_count,
1068
+ " variable_struct_names_count" ,
1069
+ nullptr ,
1070
+ nullptr ,
1071
+ { Instance }
1072
+ );
1012
1073
1013
- int instance_variable_count = m_RunnerInterface.StructGetKeys (
1014
- &Instance,
1015
- nullptr ,
1016
- nullptr
1017
- );
1074
+ // Bail if the function isn't present
1075
+ if (!AurieSuccess (last_status))
1076
+ return last_status;
1018
1077
1019
- assert (instance_variable_count > 0 );
1078
+ instance_variable_count = static_cast <int >(name_count.AsReal ());
1079
+ }
1080
+ else
1081
+ {
1082
+ // Query the count by passing nullptr for the keys array
1083
+ instance_variable_count = m_RunnerInterface.StructGetKeys (
1084
+ &Instance,
1085
+ nullptr ,
1086
+ nullptr
1087
+ );
1088
+ }
1020
1089
1021
- // Get the names of all
1090
+ assert (instance_variable_count >= 0 );
1091
+
1092
+ // Create a vector with enough space to store all the instance variable names
1022
1093
std::vector<const char *> instance_variable_names (instance_variable_count);
1023
- m_RunnerInterface.StructGetKeys (
1024
- &Instance,
1025
- instance_variable_names.data (),
1026
- &instance_variable_count
1027
- );
1094
+
1095
+ // Use a fallback if StructGetKeys isn't available
1096
+ if (!m_RunnerInterface.StructGetKeys )
1097
+ {
1098
+ AurieStatus last_status = AURIE_SUCCESS;
1099
+ RValue name_array;
1100
+
1101
+ // Ask the engine for the count - this function may not be present
1102
+ last_status = CallBuiltinEx (
1103
+ name_array,
1104
+ " variable_struct_get_names" ,
1105
+ nullptr ,
1106
+ nullptr ,
1107
+ { Instance }
1108
+ );
1109
+
1110
+ // Bail if the call failed
1111
+ if (!AurieSuccess (last_status))
1112
+ return last_status;
1113
+
1114
+ // Loop through all elements of the array
1115
+ for (size_t i = 0 ; i < name_array.length (); i++)
1116
+ {
1117
+ // Use array_get to not rely on m_RValueArrayOffset
1118
+ RValue name;
1119
+ last_status = CallBuiltinEx (
1120
+ name,
1121
+ " array_get" ,
1122
+ nullptr ,
1123
+ nullptr ,
1124
+ { name_array, static_cast <int64_t >(i) }
1125
+ );
1126
+
1127
+ // If we can't get the name just bail
1128
+ if (!AurieSuccess (last_status))
1129
+ return last_status;
1130
+
1131
+ // Assign the name into our vector
1132
+ instance_variable_names.at (i) = name.AsString ().data ();
1133
+ }
1134
+ }
1135
+ else
1136
+ {
1137
+ m_RunnerInterface.StructGetKeys (
1138
+ &Instance,
1139
+ instance_variable_names.data (),
1140
+ &instance_variable_count
1141
+ );
1142
+ }
1028
1143
1029
1144
for (int i = 0 ; i < instance_variable_count; i++)
1030
1145
{
1031
1146
const char * variable_name = instance_variable_names.at (i);
1032
1147
1033
- if (EnumFunction (variable_name, m_RunnerInterface.StructGetMember (&Instance, variable_name)))
1148
+ RValue* member_variable = nullptr ;
1149
+ AurieStatus last_status = AURIE_SUCCESS;
1150
+
1151
+ // Try to fetch the variable
1152
+ last_status = GetInstanceMember (Instance, variable_name, member_variable);
1153
+
1154
+ // If we fail we bail
1155
+ if (!AurieSuccess (last_status))
1156
+ return last_status;
1157
+
1158
+ // If EnumFunction returns true, we're good to go
1159
+ if (EnumFunction (variable_name, member_variable))
1034
1160
return AURIE_SUCCESS;
1035
1161
}
1036
1162
@@ -1467,4 +1593,22 @@ namespace YYTK
1467
1593
1468
1594
return AURIE_NOT_IMPLEMENTED;
1469
1595
}
1596
+
1597
+ AurieStatus YYTKInterfaceImpl::GetVariableSlot (
1598
+ IN const RValue& Object,
1599
+ IN const char * VariableName,
1600
+ OUT int32_t & Hash
1601
+ )
1602
+ {
1603
+ // TODO: Use variable_struct_get_hash if possible
1604
+ if (!m_FindAllocSlot)
1605
+ return AURIE_MODULE_INTERNAL_ERROR;
1606
+
1607
+ Hash = m_FindAllocSlot (
1608
+ Object.m_Object ,
1609
+ VariableName
1610
+ );
1611
+
1612
+ return AURIE_SUCCESS;
1613
+ }
1470
1614
}
0 commit comments