Ejemplo n.º 1
0
        static void VDFS_Open(RegisterMemory mem)
        {
            try
            {
                int self = mem.ECX;
                if (openedFiles.ContainsKey(self))
                {
                    Logger.Log("File is already opened!");
                    mem.EAX = 0;
                    return;
                }

                IFileHandle fileHandle;
                string      path = new zString(self + 0x60).ToString();
                if (path.Length > 0 && path[0] != '\\') // not virtual enough?)
                {
                    path = zFile.s_virtPathString + path;
                }

                if (path[0] == '\\')
                {
                    path = path.Substring(1);
                }

                if (path.EndsWith("CAMERA.DAT"))                       // gothic f***s over its virtual path with multiple thread at one point, ..
                {
                    path = @"_WORK\DATA\SCRIPTS\_COMPILED\CAMERA.DAT"; // .. apparently at the time where the camera is loaded
                }
                //Logger.Log("Open " + self.ToString("X4") + " " + path);
                if (vFiles.Count > 0 && vFiles.TryGetValue(path, out VDFSFileInfo vdfsFileInfo))
                {
                    fileHandle = new VDFSFileHandle(vdfsFileInfo);
                }
                else
                {
                    FileInfo fullPath = new FileInfo(Program.ProjectPathCombine(path));
                    if (fullPath.Exists)
                    {
                        fileHandle = new FileHandle(fullPath);
                    }
                    else
                    {
                        fullPath = new FileInfo(Program.GothicRootPathCombine(path));

                        if (fullPath.Exists)
                        {
                            fileHandle = new FileHandle(fullPath);
                        }
                        else
                        {
                            Logger.Log("Open: File not found! '" + fullPath + "'");
                            mem.EAX = 0x13F2;
                            return;
                        }
                    }
                }

                fileHandle.Open();
                openedFiles.Add(self, fileHandle);
                mem.EAX = 0;
                Process.WriteBool(self + 0x29FC, true);
                Process.WriteBool(self + 0x8C, true);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
            }
        }