//protected Stream ImageStream; public RDTTextureViewModel(RedBaseClass data, RedDocumentViewModel file) { Header = "Texture Preview"; File = file; _data = data; SetupImage(); }
public override void WriteClass(RedBaseClass cls) { if (cls is IRedCustomData customCls) { customCls.CustomWrite(this); return; } _writer.Write((byte)0); var typeInfo = RedReflection.GetTypeInfo(cls.GetType()); foreach (var propertyInfo in typeInfo.GetWritableProperties()) { var value = propertyInfo.GetValue(cls); if (!typeInfo.SerializeDefault && RedReflection.IsDefault(cls.GetType(), propertyInfo, value)) { continue; } var redTypeName = RedReflection.GetRedTypeFromCSType(propertyInfo.Type, propertyInfo.Flags.Clone()); CNameRef.Add(_writer.BaseStream.Position, propertyInfo.RedName); _writer.Write(GetStringIndex(propertyInfo.RedName)); CNameRef.Add(_writer.BaseStream.Position, redTypeName); _writer.Write(GetStringIndex(redTypeName)); var sizePos = _writer.BaseStream.Position; _writer.Write(0); Write((IRedType)value); var endPos = _writer.BaseStream.Position; var bytesWritten = (uint)(endPos - sizePos); _writer.BaseStream.Position = sizePos; _writer.Write(bytesWritten); _writer.BaseStream.Position = endPos; } _writer.Write((ushort)0); if (cls is IRedAppendix app) { app.Write(this); } }
public override void ReadClass(RedBaseClass cls, uint size) { if (cls is IRedCustomData customCls) { customCls.CustomRead(this, size); return; } var startpos = _reader.BaseStream.Position; #region initial checks // ... okay CDPR, is that a joke or what? int zero = _reader.ReadByte(); if (zero != 0) { throw new Exception($"Tried parsing a CVariable: zero read {zero}."); } #endregion #region parse sequential variables while (true) { var cvar = ReadVariable(cls); if (!cvar) { break; } } #endregion var endpos = _reader.BaseStream.Position; var bytesread = endpos - startpos; if (cls is IRedAppendix app) { app.Read(this, (uint)(size - bytesread)); } if (bytesread != size) { //throw new InvalidParsingException($"Read bytes not equal to expected bytes. Difference: {bytesread - size}"); } }
public RDTDataViewModel(RedBaseClass data, RedDocumentViewModel file) { OnDemandLoadingCommand = new DelegateCommand <TreeViewNode>(ExecuteOnDemandLoading, CanExecuteOnDemandLoading); OpenImportCommand = new Functionality.Commands.DelegateCommand <ICR2WImport>(ExecuteOpenImport); //ExportChunkCommand = new DelegateCommand<ChunkViewModel>((p) => ExecuteExportChunk(p), (p) => CanExportChunk(p)); File = file; _data = data; Header = _data.GetType().Name; //RootChunk = Chunks[0]; //if (Chunks != null) //{ // foreach (ChunkViewModel item in Chunks) // { // item.WhenAnyValue(x => x.IsDirty).Subscribe(x => IsDirty |= x); // } //} //_file.WhenAnyValue(x => x).Subscribe(x => IsDirty |= true); }
public RDTDataViewModel(string header, RedBaseClass data, RedDocumentViewModel file) : this(data, file) { Header = header; }
public void SetValue(RedBaseClass instance, IRedType value) { instance.InternalForceSetPropertyValue(RedName, value, true); instance._writtenProperties.Add(RedName); }
public object GetValue(RedBaseClass instance) => instance.InternalGetPropertyValue(Type, RedName, Flags);
public RDTMeshViewModel(CMesh data, RedDocumentViewModel file) { Header = "Preview"; File = file; _data = data; }
public bool ReadVariable(RedBaseClass cls) { var nameId = _reader.ReadUInt16(); if (nameId == 0) { return(false); } var varName = GetStringValue(nameId); // Read Type var typeId = _reader.ReadUInt16(); var typename = GetStringValue(typeId); // Read Size var sizepos = _reader.BaseStream.Position; var size = _reader.ReadUInt32(); var(type, flags) = RedReflection.GetCSTypeFromRedType(typename); IRedType value; var prop = RedReflection.GetPropertyByRedName(cls.GetType(), varName); if (prop == null) { value = Read(type, size - 4, flags); RedReflection.AddDynamicProperty(cls, varName, value); } else { value = Read(prop.Type, size - 4, prop.Flags.Clone()); var typeInfo = RedReflection.GetTypeInfo(cls.GetType()); var propName = $"{RedReflection.GetRedTypeFromCSType(cls.GetType())}.{varName}"; if (type != prop.Type) { throw new InvalidRTTIException(propName, prop.Type, type); } #if DEBUG if (!typeInfo.SerializeDefault && !prop.SerializeDefault && RedReflection.IsDefault(cls.GetType(), varName, value)) { throw new InvalidParsingException($"Invalid default val for: \"{propName}\""); } #endif prop.SetValue(cls, value); } PostProcess(); return(true); void PostProcess() { if (value is IRedBufferPointer buf) { buf.GetValue().ParentTypes.Add($"{cls.GetType().Name}.{varName}"); } if (value is IRedArray arr) { if (typeof(IRedBufferPointer).IsAssignableFrom(arr.InnerType)) { foreach (IRedBufferPointer entry in arr) { entry.GetValue().ParentTypes.Add($"{cls.GetType().Name}.{varName}"); } } } } }