From f33810a8c0617641d16953fd026b8598bd090a50 Mon Sep 17 00:00:00 2001 From: Scott Thomas Date: Fri, 15 Apr 2011 21:45:32 +0930 Subject: GROOVIE: Implement resource search-by-name for v2 games --- engines/groovie/resource.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'engines/groovie') diff --git a/engines/groovie/resource.cpp b/engines/groovie/resource.cpp index 179d746ec2..9c4e6fb2fa 100644 --- a/engines/groovie/resource.cpp +++ b/engines/groovie/resource.cpp @@ -218,7 +218,41 @@ ResMan_v2::ResMan_v2() { } uint32 ResMan_v2::getRef(Common::String name, Common::String scriptname) { - return 0; + // Open the RL file + Common::File rlFile; + if (!rlFile.open("dir.rl")) { + error("Groovie::Resource: Couldn't open dir.rl"); + return false; + } + + uint32 resNum; + bool found = false; + for (resNum = 0; !found && !rlFile.err() && !rlFile.eos(); resNum++) { + // Seek past metadata + rlFile.seek(14, SEEK_CUR); + + // Read the resource name + char readname[18]; + rlFile.read(readname, 18); + + // Test whether it's the resource we're searching + Common::String resname(readname, 18); + if (resname.hasPrefix(name.c_str())) { + debugC(2, kGroovieDebugResource | kGroovieDebugAll, "Groovie::Resource: Resource %12s matches %s", readname, name.c_str()); + found = true; + } + } + + // Close the RL file + rlFile.close(); + + // Verify we really found the resource + if (!found) { + error("Groovie::Resource: Couldn't find resource %s", name.c_str()); + return (uint32)-1; + } + + return resNum; } bool ResMan_v2::getResInfo(uint32 fileRef, ResInfo &resInfo) { -- cgit v1.2.3