@@ -15,13 +15,16 @@ namespace TFE_Jedi
15
15
enum InfStateVersion : u32
16
16
{
17
17
InfState_InitVersion = 1 ,
18
- InfState_CurVersion = InfState_InitVersion,
18
+ InfState_ScriptCall,
19
+ InfState_CurVersion = InfState_ScriptCall,
19
20
};
20
21
21
22
// INF State
22
23
InfSerializableState s_infSerState = { };
23
24
InfState s_infState = { };
24
25
26
+ static std::vector<InfScriptCall*> s_infScriptCallsToFixup;
27
+
25
28
// ///////////////////////////////////////////
26
29
// Forward Declarations
27
30
// ///////////////////////////////////////////
@@ -493,6 +496,8 @@ namespace TFE_Jedi
493
496
494
497
void inf_serialize (Stream* stream)
495
498
{
499
+ s_infScriptCallsToFixup.clear ();
500
+
496
501
SERIALIZE_VERSION (InfState_CurVersion);
497
502
498
503
s32 elevCount, teleCount, trigCount;
@@ -627,6 +632,32 @@ namespace TFE_Jedi
627
632
SERIALIZE (InfState_InitVersion, msg->arg2 , 0 );
628
633
}
629
634
635
+ void inf_serializeSciptCall (Stream* stream, Stop* stop, InfScriptCall* call)
636
+ {
637
+ SERIALIZE (InfState_ScriptCall, call->argCount , 0 );
638
+ for (s32 i = 0 ; i < call->argCount ; i++)
639
+ {
640
+ serialization_serializeScriptArg (stream, InfState_ScriptCall, &call->args [i]);
641
+ }
642
+ SERIALIZE_CSTRING (InfState_ScriptCall, call->funcName );
643
+ if (serialization_getMode () == SMODE_READ)
644
+ {
645
+ call->funcPtr = nullptr ;
646
+ s_infScriptCallsToFixup.push_back (call);
647
+ }
648
+ }
649
+
650
+ void inf_fixupScriptCalls ()
651
+ {
652
+ const s32 count = (s32)s_infScriptCallsToFixup.size ();
653
+ for (s32 i = 0 ; i < count; i++)
654
+ {
655
+ InfScriptCall* call = s_infScriptCallsToFixup[i];
656
+ call->funcPtr = getLevelScriptFunc (call->funcName );
657
+ }
658
+ s_infScriptCallsToFixup.clear ();
659
+ }
660
+
630
661
void inf_serializeAdjoin (Stream* stream, Stop* stop, AdjoinCmd* adjCmd)
631
662
{
632
663
serialization_serializeSectorPtr (stream, InfState_InitVersion, adjCmd->sector0 );
@@ -684,6 +715,35 @@ namespace TFE_Jedi
684
715
}
685
716
}
686
717
718
+ // Script Calls
719
+ s32 scriptCallCount = 0 ;
720
+ if (serialization_getMode () == SMODE_WRITE)
721
+ {
722
+ scriptCallCount = allocator_getCount (stop->scriptCalls );
723
+ }
724
+ SERIALIZE (InfState_ScriptCall, scriptCallCount, 0 );
725
+ if (serialization_getMode () == SMODE_WRITE)
726
+ {
727
+ allocator_saveIter (stop->scriptCalls );
728
+ InfScriptCall* call = (InfScriptCall*)allocator_getHead (stop->scriptCalls );
729
+ while (call)
730
+ {
731
+ inf_serializeSciptCall (stream, stop, call);
732
+ call = (InfScriptCall*)allocator_getNext (stop->scriptCalls );
733
+ }
734
+ allocator_restoreIter (stop->scriptCalls );
735
+ }
736
+ else if (scriptCallCount > 0 ) // SMODE_READ
737
+ {
738
+ stop->scriptCalls = allocator_create (sizeof (InfScriptCall));
739
+ for (s32 c = 0 ; c < scriptCallCount; c++)
740
+ {
741
+ InfScriptCall* call = (InfScriptCall*)allocator_newItem (stop->scriptCalls );
742
+ if (!call) { return ; }
743
+ inf_serializeSciptCall (stream, stop, call);
744
+ }
745
+ }
746
+
687
747
// Adjoin Commands
688
748
s32 adjCount;
689
749
if (serialization_getMode () == SMODE_WRITE)
@@ -708,8 +768,7 @@ namespace TFE_Jedi
708
768
for (s32 a = 0 ; a < adjCount; a++)
709
769
{
710
770
AdjoinCmd* adjCmd = (AdjoinCmd*)allocator_newItem (stop->adjoinCmds );
711
- if (!adjCmd)
712
- return ;
771
+ if (!adjCmd) { return ; }
713
772
inf_serializeAdjoin (stream, stop, adjCmd);
714
773
}
715
774
}
0 commit comments