@@ -303,16 +303,19 @@ private static byte Byond_ReadList(CByondValue* loc, CByondValue* list, uint* le
303303 return 0 ;
304304 }
305305
306- var srcDreamVals = srcList . GetValues ( ) ;
307- int length = srcDreamVals . Count ;
306+ int length = srcList . GetLength ( ) ;
308307 * len = ( uint ) length ;
309308 if ( list == null || providedBufLen < length ) {
310309 return 0 ;
311310 }
312311
313312 try {
314- for ( int i = 0 ; i < length ; i ++ ) {
315- list [ i ] = ValueToByondApi ( srcDreamVals [ i ] ) ;
313+ int i = 0 ;
314+ foreach ( var value in srcList . EnumerateValues ( ) ) {
315+ if ( i >= length )
316+ throw new Exception ( $ "List { srcList } had more elements than the expected { length } ") ;
317+
318+ list [ i ++ ] = ValueToByondApi ( value ) ;
316319 }
317320 } catch ( Exception ) {
318321 return 0 ;
@@ -706,7 +709,7 @@ private static byte Byond_Block(CByondXYZ* corner1, CByondXYZ* corner2, CByondVa
706709 corner1 ->x , corner1 ->y , corner1 ->z ,
707710 corner2 ->x , corner2 ->y , corner2 ->z ) ;
708711
709- foreach ( var turf in turfs . GetValues ( ) ) {
712+ foreach ( var turf in turfs . EnumerateValues ( ) ) {
710713 list . Add ( ValueToByondApi ( turf ) ) ;
711714 }
712715 } catch ( Exception ) {
@@ -879,15 +882,10 @@ private static byte Byond_NewArglist(CByondValue* cType, CByondValue* cArglist,
879882 var objectDef = treeEntry . ObjectDefinition ;
880883
881884 var arglistVal = ValueFromDreamApi ( * cArglist ) ;
882- if ( ! arglistVal . TryGetValueAsDreamList ( out DreamList ? arglist ) ) return 0 ;
885+ if ( ! arglistVal . TryGetValueAsIDreamList ( out var arglist ) ) return 0 ;
883886
884887 // Copy the arglist's values to a new array to ensure no shenanigans
885- var argListValues = arglist . GetValues ( ) ;
886- var argValues = new DreamValue [ argListValues . Count ] ;
887- for ( int i = 0 ; i < argListValues . Count ; i ++ ) {
888- argValues [ i ] = argListValues [ i ] ;
889- }
890-
888+ var argValues = arglist . CopyToArray ( ) ;
891889 var args = new DreamProcArguments ( argValues ) ;
892890
893891 // TODO: This is code duplicated with DMOpcodeHandlers.CreateObject()
0 commit comments