Esempio n. 1
0
        public bool ReadFromDiscFile(PblDiscFile discFile) // 0xDBA560
        {
            if (discFile.IsOpen())
            {
                var fileSize = (int)discFile.GetFileSize();

                Flags1C |= 7;

                Payload   = new byte[fileSize];
                Length    = fileSize;
                MaxLength = fileSize;
                Offset    = 0;

                // Skipping fragmented reading as in the client
                discFile.Read(Payload, fileSize);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public bool Open(string fileName, int a3, bool a4)
        {
            lock (StaticDiscFileData.Lock)
            {
                Close();

                if (StaticDiscFileData.Status2 && StaticDiscFileData.DiscFile != null && !a4)
                {
                    if (!StaticDiscFileData.HeaderRead)
                    {
                        StaticDiscFileData.DiscFile.Seek(StaticDiscFileData.FileOffset, SeekOrigin.Begin);
                        StaticDiscFileData.DiscFile.Read(StaticDiscFileData.TempBuffer, 128);

                        StaticDiscFileData.Setup();

                        StaticDiscFileData.HeaderRead = true;
                    }

                    var  fileNameItr = 0;
                    var  off         = 0;
                    bool match;

                    while (true)
                    {
                        var c = fileName[fileNameItr];

                        if (char.IsLetter(c))
                        {
                            c = char.ToLowerInvariant(c);
                        }

                        if (c == '\\')
                        {
                            c = '/';
                        }

                        var o = StaticDiscFileData.FileName[off++];

                        if (char.IsLetter(o))
                        {
                            o = char.ToLowerInvariant(o);
                        }

                        if (o == '\\')
                        {
                            o = '/';
                        }

                        match = c == o;
                        if (!match)
                        {
                            break;
                        }

                        if (c == 0)
                        {
                            match = o == 0;
                            break;
                        }

                        ++fileNameItr;
                    }

                    var firstInd = fileName.IndexOf('\\', StringComparison.InvariantCulture);
                    if (match || (firstInd != -1 && fileName[(firstInd + 1)..] == StaticDiscFileData.FileName))
                    {
                        IsCustomDiscFile = false;
                        DiscFile         = StaticDiscFileData.DiscFile;
                        F24Offset        = 0L;

                        IsFromLooseFile = StaticDiscFileData.FileSize != -1L;
                        if (!IsFromLooseFile)
                        {
                            StaticDiscFileData.FileOffset += 128L;
                        }
                        else
                        {
                            F32Size       = (int)StaticDiscFileData.FileSize;
                            F16FileOffset = StaticDiscFileData.FileOffset + 128;

                            StaticDiscFileData.FileOffset += StaticDiscFileData.FileSize + 128;

                            if ((StaticDiscFileData.FileSize & 0xF) != 0)
                            {
                                StaticDiscFileData.FileOffset += 16 - (StaticDiscFileData.FileSize & 0xF);
                            }
                        }

                        StaticDiscFileData.HeaderRead = false;

                        if (IsFromLooseFile)
                        {
                            ++StaticDiscFileData.RefCount;
                        }
                        else
                        {
                            IsCustomDiscFile = true;
                            DiscFile         = new PblDiscFile
                            {
                                B13 = B37
                            };

                            if (DiscFile.Open(fileName, a3))
                            {
                                StaticDiscFileData.Status2 = false;

                                return(true);
                            }

                            return(false);
                        }
                    }
                }

                IsCustomDiscFile = true;
                DiscFile         = new PblDiscFile
                {
                    B13 = B37
                };

                return(DiscFile.Open(fileName, a3));
            }
        }