public void Unserialize(UndertaleReader reader) { Name = reader.ReadUndertaleString(); Occurrences = reader.ReadUInt32(); if (Occurrences > 0) { FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>(); // Parse the chain of references UndertaleInstruction.Reference <UndertaleFunction> reference = null; uint addr = reader.GetAddressForUndertaleObject(FirstAddress); for (int i = 0; i < Occurrences; i++) { reference = reader.GetUndertaleObjectAtAddress <UndertaleInstruction>(addr).GetReference <UndertaleFunction>(); if (reference == null) { throw new IOException("Failed to find reference at " + addr); } reference.Target = this; addr += (uint)reference.NextOccurrenceOffset; } UnknownChainEndingValue = reference.NextOccurrenceOffset; } else { if (reader.ReadInt32() != -1) { throw new Exception("Function with no occurrences, but still has a first occurrence address"); } FirstAddress = null; } }
//private static int id = 0; public void Unserialize(UndertaleReader reader) { Name = reader.ReadUndertaleString(); InstanceType = (UndertaleInstruction.InstanceType)reader.ReadInt32(); VarID = reader.ReadInt32(); Occurrences = reader.ReadUInt32(); //Debug.WriteLine("Variable " + (id++) + " at " + reader.GetAddressForUndertaleObject(Name).ToString("X8") + " child of " + Unknown); if (Occurrences > 0) { FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>(); // Parse the chain of references UndertaleInstruction.Reference <UndertaleVariable> reference = null; uint addr = reader.GetAddressForUndertaleObject(FirstAddress); for (int i = 0; i < Occurrences; i++) { reference = reader.GetUndertaleObjectAtAddress <UndertaleInstruction>(addr).GetReference <UndertaleVariable>(); if (reference == null) { throw new IOException("Failed to find reference at " + addr); } reference.Target = this; // Debug.WriteLine("* " + addr.ToString("X8")); addr += (uint)reference.NextOccurrenceOffset; } //Debug.WriteLine("* " + reference.NextOccurrenceOffset.ToString() + " (ending value)"); UnknownChainEndingValue = reference.NextOccurrenceOffset; } else { if (reader.ReadInt32() != -1) { throw new Exception("Variable with no occurrences, but still has a first occurrence address"); } FirstAddress = null; } }