Ejemplo n.º 1
0
        static void VDFS_Exists(RegisterMemory mem)
        {
            try
            {
                if (openedFiles.ContainsKey(mem.ECX))
                {
                    mem.EAX = 1;
                    return;
                }

                string path = new zString(mem.ECX + 0x60).ToString();

                if (path.Length > 0 && path[0] != '\\') // not virtual?
                {
                    path = zFile.s_virtPathString + path;
                }

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

                if ((vFiles.Count > 0 && vFiles.ContainsKey(path)) ||
                    File.Exists(Program.ProjectPathCombine(path)) ||
                    File.Exists(Program.GothicRootPathCombine(path)))
                {
                    //Logger.Log("Exists: " + path);
                    mem.EAX = 1;
                    return;
                }

                //Logger.Log("Not Existing: " + path);
                mem.EAX = 0;
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
            }
        }
Ejemplo n.º 2
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());
            }
        }
Ejemplo n.º 3
0
        static void VDFS_SearchFile(RegisterMemory mem)
        {
            try
            {
                zFile_File zfile    = new zFile_File(mem.ECX);
                string     fileName = new zString(mem.GetArg(0)).ToString();
                string     folder   = new zString(mem.GetArg(1)).ToString();

                if (folder.Length > 0 && folder[0] == '\\')
                {
                    folder = folder.Substring(1);
                }
                if (folder.Length > 0 && folder[folder.Length - 1] == '\\')
                {
                    folder = folder.Remove(folder.Length - 1);
                }

                //Logger.Log("SearchFile: " + fileName + " " + folder);
                if (vFiles.Count > 0)
                {
                    if (vDirs.TryGetValue(folder, out VDFSDirectoryInfo dir))
                    {
                        VDFSFileInfo fi = dir.SearchFile(fileName);
                        if (fi != null)
                        {
                            zfile.SetPath('\\' + fi.Path);
                            mem.EAX = 0;
                            return;
                        }
                    }
                }

                DirectoryInfo dirInfo = new DirectoryInfo(Program.ProjectPathCombine(folder));
                if (dirInfo.Exists)
                {
                    FileInfo fi = dirInfo.EnumerateFiles(fileName, SearchOption.AllDirectories).FirstOrDefault();
                    if (fi != null)
                    {
                        zfile.SetPath(fi.FullName.Substring(Program.ProjectPath.Length));
                        mem.EAX = 0;
                        return;
                    }
                }

                dirInfo = new DirectoryInfo(Program.GothicRootPathCombine(folder));
                if (dirInfo.Exists)
                {
                    FileInfo fi = dirInfo.EnumerateFiles(fileName, SearchOption.AllDirectories).FirstOrDefault();
                    if (fi != null)
                    {
                        zfile.SetPath(fi.FullName.Substring(Program.GothicRootPath.Length));
                        mem.EAX = 0;
                        return;
                    }
                }

                mem.EAX = 0x138B;
                //Logger.Log("SearchFile: " + fileName + " not found!");
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
            }
        }