public void WriteArray(Writer writer) { if (Settings.s.game == Settings.Game.R2Revolution) { Pointer.Goto(ref writer, Pointer.Current(writer) + 4); writer.Write((byte)arrayTypeNumber); writer.Write(arrayLength); writer.Write((byte)0); writer.Write((byte)0); } else { writer.Write(arrayTypeNumber); writer.Write(arrayLength); writer.Write((byte)0); writer.Write((byte)0); writer.Write((byte)0); } arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber); if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType) { Debug.LogWarning(currentbuf + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(writer)); } if (valueArray != null && arrayLength == valueArray.Length) { for (uint i = 0; i < arrayLength; i++) { valueArray[i].Write(writer); } } }
public void ReadArray(Reader reader) { if (Settings.s.game == Settings.Game.R2Revolution) { reader.ReadUInt32(); arrayTypeNumber = reader.ReadByte(); arrayLength = reader.ReadByte(); reader.ReadBytes(2); // padding } else { arrayTypeNumber = reader.ReadUInt32(); arrayLength = reader.ReadByte(); reader.ReadBytes(3); // padding } arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber); if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType) { Debug.LogWarning(currentbuf + " - " + type + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(reader)); } if (valueArray == null || arrayLength != valueArray.Length) { valueArray = new DsgVarValue[arrayLength]; for (int i = 0; i < arrayLength; i++) { valueArray[i] = new DsgVarValue(arrayType); } } for (uint i = 0; i < arrayLength; i++) { valueArray[i].Read(reader); } }
public static DsgVarInfoEntry Read(EndianBinaryReader reader, Pointer offset) { DsgVarInfoEntry d = new DsgVarInfoEntry(offset); d.offsetInBuffer = reader.ReadUInt32(); d.typeNumber = reader.ReadUInt32(); d.type = (DsgVarType)d.typeNumber; d.saveType = reader.ReadUInt32(); d.initType = reader.ReadUInt32(); return(d); }
public static DsgVar Read(EndianBinaryReader reader, Pointer offset, DsgMem dsgMem = null) { DsgVar dsgVar = new DsgVar(offset); dsgVar.off_dsgMemBuffer = Pointer.Read(reader); dsgVar.off_dsgVarInfo = Pointer.Read(reader); // Unknown stuff if (dsgMem == null) { dsgVar.something3 = reader.ReadUInt32(); } if (dsgMem == null) { dsgVar.amountOfInfos = reader.ReadUInt32(); dsgVar.dsgMemBufferLength = reader.ReadUInt32() * 4; } else { dsgVar.dsgMemBufferLength = reader.ReadUInt32(); dsgVar.amountOfInfos = reader.ReadUInt32(); } dsgVar.dsgVarInfos = new DsgVarInfoEntry[dsgVar.amountOfInfos]; if (dsgVar.off_dsgVarInfo != null && dsgVar.amountOfInfos > 0) { Pointer off_current = Pointer.Goto(ref reader, dsgVar.off_dsgVarInfo); for (int i = 0; i < dsgVar.amountOfInfos; i++) { DsgVarInfoEntry infoEntry = DsgVarInfoEntry.Read(reader, Pointer.Current(reader)); if (dsgMem != null) { infoEntry.value = dsgVar.ReadValueFromDsgMemBuffer(reader, infoEntry, dsgMem); } else { infoEntry.value = dsgVar.ReadValueFromDsgVarBuffer(reader, infoEntry, dsgVar); } dsgVar.dsgVarInfos[i] = infoEntry; } Pointer.Goto(ref reader, off_current); // Move the reader back to where it was } /*if (d.off_AI_model != null) { * Pointer.Goto(ref reader, d.off_AI_model); * d.AI_model = AIModel.Read(reader, d.off_AI_model); * }*/ return(dsgVar); }
protected override void ReadInternal(Reader reader) { off_dsgMemBuffer = Pointer.Read(reader); off_dsgVarInfo = Pointer.Read(reader); if (Settings.s.game == Settings.Game.R2Revolution) { dsgMemBufferLength = reader.ReadUInt16(); amountOfInfos = reader.ReadUInt16(); } else { dsgMemBufferLength = reader.ReadUInt32(); amountOfInfos = reader.ReadByte(); reader.ReadBytes(3); } dsgVarInfos = new DsgVarInfoEntry[amountOfInfos]; defaultValues = new DsgVarValue[amountOfInfos]; if (amountOfInfos > 0) { Pointer.DoAt(ref reader, off_dsgVarInfo, () => { //l.print(dsgVar.amountOfInfos); for (uint i = 0; i < amountOfInfos; i++) { dsgVarInfos[i] = DsgVarInfoEntry.Read(reader, Pointer.Current(reader), i); defaultValues[i] = new DsgVarValue(dsgVarInfos[i].type, null); defaultValues[i].ReadFromDsgVarBuffer(reader, dsgVarInfos[i], this); //l.print(infoEntry.offset + " - " + infoEntry.typeNumber + " - " + infoEntry.type + " - " + infoEntry.offsetInBuffer); /*if (dsgMem != null) { * if (Settings.s.platform != Settings.Platform.DC) { * infoEntry.value = dsgVar.ReadValueFromDsgMemBuffer(reader, infoEntry, dsgMem); * } * if (dsgMem.memBufferInitial != null) { * infoEntry.initialValue = dsgVar.ReadInitialValueFromDsgMemBuffer(reader, infoEntry, dsgMem); * if (Settings.s.platform == Settings.Platform.DC) { * infoEntry.value = infoEntry.initialValue; * } * } * } else { * infoEntry.value = dsgVar.ReadValueFromDsgVarBuffer(reader, infoEntry, dsgVar); * } * dsgVar.dsgVarInfos[i] = infoEntry;*/ } }); } }
public static string DsgVarEntryToCSharpAssignment(DsgVar dsgVar, int index) { DsgVarInfoEntry dsgVarEntry = dsgVar.dsgVarInfos[index]; string text = ""; string typeText = DsgVarInfoEntry.GetCSharpStringFromType(dsgVarEntry.type); text += typeText + " " + "dsgVar_" + dsgVarEntry.number; if (dsgVar.defaultValues != null) { text += " = "; string stringVal = dsgVar.defaultValues[index].ToString(); text += stringVal; } text += ";"; return(text); }
public static DsgVarInfoEntry Read(Reader reader, Pointer offset, uint number) { MapLoader l = MapLoader.Loader; DsgVarInfoEntry d = new DsgVarInfoEntry(offset); //l.print(offset); if (Settings.s.game == Settings.Game.LargoWinch) { d.offsetInBuffer = reader.ReadUInt32(); d.typeNumber = reader.ReadUInt32(); d.saveType = reader.ReadByte(); d.initType = reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); } else if (Settings.s.game == Settings.Game.R2Revolution) { d.offsetInBuffer = reader.ReadUInt16(); reader.ReadUInt16(); d.typeNumber = reader.ReadByte(); d.saveType = reader.ReadByte(); d.initType = d.saveType; } else { d.offsetInBuffer = reader.ReadUInt32(); d.typeNumber = reader.ReadUInt32(); d.saveType = reader.ReadUInt32(); d.initType = reader.ReadUInt32(); } d.number = number; d.type = Settings.s.aiTypes.GetDsgVarType(d.typeNumber); return(d); }
public void ReadFromDsgMemBufferInitial(Reader reader, DsgVarInfoEntry infoEntry, DsgMem dsgMem) { currentbuf = "dsgmem_initial"; ReadFromBuffer(reader, infoEntry, dsgMem.memBufferInitial); }
public void ReadFromBuffer(Reader reader, DsgVarInfoEntry infoEntry, Pointer buffer) { ReadFromBuffer(reader, infoEntry.offsetInBuffer, buffer); }
public static DsgVar Read(Reader reader, Pointer offset, DsgMem dsgMem = null) { MapLoader l = MapLoader.Loader; //l.print("DsgVar " + offset); DsgVar dsgVar = new DsgVar(offset); dsgVar.off_dsgMemBuffer = Pointer.Read(reader); dsgVar.off_dsgVarInfo = Pointer.Read(reader); /*if (dsgMem != null) { * l.print(offset + " - " + dsgVar.off_dsgMemBuffer + " - " + dsgVar.off_dsgVarInfo); * l.print("DsgMem initial: " + dsgMem.memBufferInitial + " - cur: " + dsgMem.memBuffer); * }*/ // Unknown stuff if (dsgMem == null && Settings.s.platform != Settings.Platform.GC && Settings.s.platform != Settings.Platform.DC && Settings.s.platform != Settings.Platform.Xbox360 && Settings.s.game != Settings.Game.R2Revolution && Settings.s.game != Settings.Game.LargoWinch && Settings.s.engineVersion >= Settings.EngineVersion.R2) { dsgVar.something3 = reader.ReadUInt32(); } if (Settings.s.game == Settings.Game.R2Revolution) { dsgVar.dsgMemBufferLength = reader.ReadUInt16(); dsgVar.amountOfInfos = reader.ReadUInt16(); } else if (Settings.s.platform == Settings.Platform.GC || Settings.s.platform == Settings.Platform.DC || Settings.s.platform == Settings.Platform.Xbox360 || Settings.s.engineVersion < Settings.EngineVersion.R2 || Settings.s.game == Settings.Game.LargoWinch) { dsgVar.dsgMemBufferLength = reader.ReadUInt32(); dsgVar.amountOfInfos = reader.ReadByte(); } else if (dsgMem == null) { dsgVar.amountOfInfos = reader.ReadUInt32(); dsgVar.dsgMemBufferLength = reader.ReadUInt32() * 4; } else { dsgVar.dsgMemBufferLength = reader.ReadUInt32(); dsgVar.amountOfInfos = reader.ReadUInt32(); } if (dsgMem != null && dsgMem.memBufferInitial == null) { dsgMem.memBufferInitial = dsgVar.off_dsgMemBuffer; } dsgVar.dsgVarInfos = new DsgVarInfoEntry[dsgVar.amountOfInfos]; if (dsgVar.amountOfInfos > 0) { Pointer.DoAt(ref reader, dsgVar.off_dsgVarInfo, () => { //l.print(dsgVar.amountOfInfos); for (uint i = 0; i < dsgVar.amountOfInfos; i++) { DsgVarInfoEntry infoEntry = DsgVarInfoEntry.Read(reader, Pointer.Current(reader), i); //l.print(infoEntry.offset + " - " + infoEntry.typeNumber + " - " + infoEntry.type + " - " + infoEntry.offsetInBuffer); if (dsgMem != null) { if (Settings.s.platform != Settings.Platform.DC) { infoEntry.value = dsgVar.ReadValueFromDsgMemBuffer(reader, infoEntry, dsgMem); } if (dsgMem.memBufferInitial != null) { infoEntry.initialValue = dsgVar.ReadInitialValueFromDsgMemBuffer(reader, infoEntry, dsgMem); if (Settings.s.platform == Settings.Platform.DC) { infoEntry.value = infoEntry.initialValue; } } } else { infoEntry.value = dsgVar.ReadValueFromDsgVarBuffer(reader, infoEntry, dsgVar); } dsgVar.dsgVarInfos[i] = infoEntry; } }); } /*if (d.off_AI_model != null) { * Pointer.Goto(ref reader, d.off_AI_model); * d.AI_model = AIModel.Read(reader, d.off_AI_model); * }*/ return(dsgVar); }
public object ReadValueFromDsgMemBuffer(EndianBinaryReader reader, DsgVarInfoEntry infoEntry, DsgMem dsgMem) { return(ReadValueFromBuffer(reader, infoEntry, dsgMem.memBuffer)); }
public object ReadInitialValueFromDsgMemBuffer(Reader reader, DsgVarInfoEntry infoEntry, DsgMem dsgMem) { return(ReadValueFromBuffer(reader, infoEntry, dsgMem.memBufferInitial)); }
public object ReadValueFromBuffer(Reader reader, DsgVarInfoEntry.DsgVarType type, uint offsetInBuffer, Pointer buffer, DsgVarInfoEntry entry = null) { object returnValue = null; Pointer.DoAt(ref reader, buffer + offsetInBuffer, () => { if (entry != null) { entry.debugValueOffset = Pointer.Current(reader); } returnValue = ReadValue(reader, type); }); return(returnValue); }
public object ReadValueFromBuffer(Reader reader, DsgVarInfoEntry infoEntry, Pointer buffer) { return(ReadValueFromBuffer(reader, infoEntry.type, infoEntry.offsetInBuffer, buffer, infoEntry)); }
public object ReadValueFromBuffer(EndianBinaryReader reader, DsgVarInfoEntry infoEntry, Pointer buffer) { Pointer original = Pointer.Goto(ref reader, buffer + infoEntry.offsetInBuffer); object returnValue = null; try { switch (infoEntry.type) { case DsgVarType.Boolean: returnValue = reader.ReadBoolean(); break; case DsgVarType.Byte: returnValue = reader.ReadSByte(); break; case DsgVarType.UByte: returnValue = reader.ReadByte(); break; case DsgVarType.Float: returnValue = reader.ReadSingle(); break; case DsgVarType.Int: returnValue = reader.ReadInt32(); break; case DsgVarType.UInt: returnValue = reader.ReadUInt32(); break; case DsgVarType.Short: returnValue = reader.ReadInt16(); break; case DsgVarType.UShort: returnValue = reader.ReadUInt16(); break; case DsgVarType.Vector: float x = reader.ReadSingle(); float y = reader.ReadSingle(); float z = reader.ReadSingle(); returnValue = new Vector3(x, y, z); /*Pointer off_vec = Pointer.Read(reader); * if (off_vec != null) { * Pointer.Goto(ref reader, off_vec); * float x = reader.ReadSingle(); * float y = reader.ReadSingle(); * float z = reader.ReadSingle(); * returnValue = new Vector3(x, y, z); * } else { * returnValue = "null"; * }*/ break; default: returnValue = reader.ReadInt32(); break; } } catch (Exception e) { returnValue = "Exception: " + e.Message; } Pointer.Goto(ref reader, original); return(returnValue); }
public void ReadFromDsgVarBuffer(Reader reader, DsgVarInfoEntry infoEntry, DsgVar dsgVar) { currentbuf = "dsgvar"; ReadFromBuffer(reader, infoEntry, dsgVar.off_dsgMemBuffer); }
public object ReadValueFromDsgVarBuffer(Reader reader, DsgVarInfoEntry infoEntry, DsgVar dsgVar) { return(ReadValueFromBuffer(reader, infoEntry, dsgVar.off_dsgMemBuffer)); }
public static string DsgVarEntryToCSharpAssignment(DsgVarInfoEntry dsgVarEntry) { DsgVarComponent.DsgVarEditableEntry editableEntry = new DsgVarComponent.DsgVarEditableEntry((int)dsgVarEntry.number, dsgVarEntry); string text = ""; string typeText = ""; switch (dsgVarEntry.type) { case DsgVarInfoEntry.DsgVarType.None: break; case DsgVarInfoEntry.DsgVarType.Boolean: typeText = "DsgVarBool"; break; case DsgVarInfoEntry.DsgVarType.Byte: typeText = "DsgVarByte"; break; case DsgVarInfoEntry.DsgVarType.UByte: typeText = "DsgVarUByte"; break; case DsgVarInfoEntry.DsgVarType.Short: typeText = "DsgVarShort"; break; case DsgVarInfoEntry.DsgVarType.UShort: typeText = "DsgVarUShort"; break; case DsgVarInfoEntry.DsgVarType.Int: typeText = "DsgVarInt"; break; case DsgVarInfoEntry.DsgVarType.UInt: typeText = "DsgVarUInt"; break; case DsgVarInfoEntry.DsgVarType.Float: typeText = "DsgVarFloat"; break; case DsgVarInfoEntry.DsgVarType.Vector: typeText = "Vector3"; break; case DsgVarInfoEntry.DsgVarType.List: typeText = "DsgVarList"; break; case DsgVarInfoEntry.DsgVarType.Comport: typeText = "Comport"; break; case DsgVarInfoEntry.DsgVarType.Action: typeText = "Action"; break; case DsgVarInfoEntry.DsgVarType.Caps: typeText = "Caps"; break; case DsgVarInfoEntry.DsgVarType.Input: typeText = "Input"; break; case DsgVarInfoEntry.DsgVarType.SoundEvent: typeText = "SoundEvent"; break; case DsgVarInfoEntry.DsgVarType.Light: typeText = "Light"; break; case DsgVarInfoEntry.DsgVarType.GameMaterial: typeText = "GameMaterial"; break; case DsgVarInfoEntry.DsgVarType.VisualMaterial: typeText = "VisualMaterial"; break; case DsgVarInfoEntry.DsgVarType.Perso: typeText = "Perso"; break; case DsgVarInfoEntry.DsgVarType.Waypoint: typeText = "WayPoint"; break; case DsgVarInfoEntry.DsgVarType.Graph: typeText = "Graph"; break; case DsgVarInfoEntry.DsgVarType.Text: typeText = "DsgVarString"; break; case DsgVarInfoEntry.DsgVarType.SuperObject: typeText = "SuperObject"; break; case DsgVarInfoEntry.DsgVarType.SOLinks: typeText = "SOLinks"; break; case DsgVarInfoEntry.DsgVarType.PersoArray: typeText = "List<Perso>"; break; case DsgVarInfoEntry.DsgVarType.VectorArray: typeText = "List<Vector3>"; break; case DsgVarInfoEntry.DsgVarType.FloatArray: typeText = "List<DsgVarFloat>"; break; case DsgVarInfoEntry.DsgVarType.IntegerArray: typeText = "List<DsgVarInt>"; break; case DsgVarInfoEntry.DsgVarType.WayPointArray: typeText = "List<WayPoint>"; break; case DsgVarInfoEntry.DsgVarType.TextArray: // These are text references typeText = "List<DsgVarTextRef>"; break; case DsgVarInfoEntry.DsgVarType.TextRefArray: // Don't know what these are then? typeText = "List<DsgVarTextRef2>"; break; case DsgVarInfoEntry.DsgVarType.Array6: typeText = "List<Unknown_6>"; break; case DsgVarInfoEntry.DsgVarType.Array9: typeText = "List<Unknown_7>"; break; case DsgVarInfoEntry.DsgVarType.SoundEventArray: typeText = "List<DsgVarSoundEvent>"; break; case DsgVarInfoEntry.DsgVarType.Array11: typeText = "List<Unknown_11>"; break; case DsgVarInfoEntry.DsgVarType.Way: typeText = "Way"; break; case DsgVarInfoEntry.DsgVarType.ActionArray: typeText = "List<Action>"; break; case DsgVarInfoEntry.DsgVarType.SuperObjectArray: typeText = "List<SuperObject>"; break; } text += typeText + " " + "dsgVar_" + dsgVarEntry.number; if (dsgVarEntry.initialValue != null) { text += " = "; string stringVal = ""; switch (dsgVarEntry.type) { case DsgVarInfoEntry.DsgVarType.Boolean: stringVal = editableEntry.valueAsBool_initial.ToString().ToLower(); break; case DsgVarInfoEntry.DsgVarType.Int: stringVal = (editableEntry.valueAsInt_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.UInt: stringVal = (editableEntry.valueAsUInt_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.Short: stringVal = (editableEntry.valueAsShort_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.UShort: stringVal = (editableEntry.valueAsUShort_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.Byte: stringVal = (editableEntry.valueAsSByte_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.UByte: stringVal = (editableEntry.valueAsByte_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.Float: stringVal = (editableEntry.valueAsFloat_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.Text: stringVal = (editableEntry.valueAsString_initial.ToString()); break; case DsgVarInfoEntry.DsgVarType.Vector: float val_x = editableEntry.valueAsVector_initial.x; float val_y = editableEntry.valueAsVector_initial.y; float val_z = editableEntry.valueAsVector_initial.z; stringVal = "new Vector3(" + val_x + ", " + val_y + ", " + val_z + ")"; break; case DsgVarInfoEntry.DsgVarType.Perso: PersoBehaviour currentPersoBehaviour = editableEntry.valueAsPersoGao_initial != null?editableEntry.valueAsPersoGao_initial.GetComponent <PersoBehaviour>() : null; if (currentPersoBehaviour != null) { stringVal += "Perso.GetByName(" + currentPersoBehaviour.perso.namePerso + ")"; } else { stringVal += "null"; } break; case DsgVarInfoEntry.DsgVarType.SuperObject: GameObject currentGao = editableEntry.valueAsSuperObjectGao_initial != null ? editableEntry.valueAsSuperObjectGao_initial : null; if (currentGao != null) { stringVal += "GameObject.GetByName(" + currentGao.name + ")"; } else { stringVal += "null"; } break; } text += stringVal; } text += ";"; return(text); }