Extracting data from a .p3d file - is it feasible?

This is a discussion on Extracting data from a .p3d file - is it feasible? within the C++ Programming forums, part of the General Programming Boards category; Hi, Quick one chaps and chappesses. I'm making a game for real. Spending hours and hours every day learning loads ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    87

    Smile Extracting data from a .p3d file - is it feasible?

    Hi,

    Quick one chaps and chappesses. I'm making a game for real. Spending hours and hours every day learning loads of stuff and things are actually happening.

    Keen as ever to make use of work people have done before I want to know if it is possible to write a program in C++ that can extract data from a .p3d file. I have found a reference online detailing the format of a .p3d file but when I opened one up in notepad it just looked like some tremendously confusing language I've never seen before. Like a collection of greek characters which I'm told might mean it has been encrypted but I'm not sure.

    So what I want to know is, is this possible? Even if I could just extract the vertices it would make life so much easier as there's tonnes of .p3d models made from Operation Flashpoint which are freeware and would speed things up alot.

    If it's entirely unrealistic though it would be helpful to know so I can avoid wasting time on it and just make the models myself or source another source of models.

    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Add words like "source code" or "library" to your search terms.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    87
    I had a look on google but found mostly there was sparse if any information. I'm beginning to get the feel that this is beyond me. I'll probably just have to settle for the fact I'm not going to be able to use them

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    If you have the file format, then you should be able to read in the data. I highly doubt that it's encrypted. The gibberish that you see is simply because a lot of the data is binary and when you open it as ASCII it looks like junk.

    If you have the format, then you should know when to read what kind of data types in from the file, etc, etc.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    87
    I see! So it's perhaps not out of the question. Thanks for the input. One question that I'm wondering about and perhaps this will give away that my skill level at present is simply not up to this but:

    1)How can I get a pointer to the 'start' of the file?

    2)Once/if I get that address can I just make a for loop type of code block that runs through the file format for each vertex/polygon?

    Is that how it works? Or am I barking up the wrong tree in the wrong forest? Thanks for the help

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    Quote Originally Posted by shrink_tubing View Post
    1)How can I get a pointer to the 'start' of the file?
    It's the same as opening any other file.

    Quote Originally Posted by shrink_tubing View Post
    2)Once/if I get that address can I just make a for loop type of code block that runs through the file format for each vertex/polygon?
    That would kind of be how it works. I don't know the format, so you might need multiple loops that deal with specific sections of the file. E.g., the beginning of the file might just tell you a summary of the data contained within before ever getting the actual data that describes the model. So one simple for loop wouldn't work. You have to read the proper data in at the proper time.

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    87
    Ok great thanks I feel ready to start looking at this now. I've forgotten how to open a file though it's been so long since I touched anything like that. All the recent stuff I've been doing has only been C++ relating to DirectX and shaders.

    Any ideas what the command is? Thanks so much this might work. I'm glad you helped me anyway even if it doesn't

  8. #8
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    Well, I would do some reading on how to open files, specifically for whatever environment you are currently developing in. There are many, many resources online. I'm sure you will have no problem finding something.

    After you have an idea and have tried something, feel free to come back and ask more specific questions

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    87
    That's great thanks, I'll do exactly that

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    87

    Lightbulb

    Hi!

    I was able to sort through a right old messy .x file using the following code. I put a string at the end of the file of a type not likely to be found anywhere else in it. I used ^_^ and the code sorted through it all and produced a very neat human readable version text file output. The source file data looked something akin to a tiger's stripes beforehand it was all over the place as the endl command hadn't been used to create it.

    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main ()
    {
        //declare an instance of ofstream
        ifstream iStream;
        ofstream oStream;
    
        string line;
    
        iStream.open ("sourcefile.x");
        oStream.open ("destinationfile.txt");
    
        while (line != "^_^")
        {
            getline (iStream,line);
            cout << line << endl;
            oStream << line << endl;
        }  
    
        return 0;
    }
    All very good and all, now I can much more easily read the source format of any .x files my modelling programs output.

    However, a .p3d file is a different ball game (ODOL 7 and 40 - they're in binary). What I want to know is, instead of using strings can I read individual bytes and output them as ASCII type characters (chars basically)? That way I could loop through an entire .p3d file and output it's source to a text file where it could be read. I would need to read individual bytes and also be able to issue an std::endl instruction when encountering a carriage return or tab.

    Can anyone help? I don't know how to do this or even if I can use formatted I/O through <iostream> to do it? Thanks
    Last edited by shrink_tubing; 06-26-2010 at 10:04 AM.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    87

    Question

    Actually it's just occured to me that if do that I might get the same pile of encrypted looking junk I would see if I just opened it into a notepad file.

    Hmmm. Is there someway I can setup a pointer that loops through each memory address in the file, finds the variable type at the location and casts it to a char?

    Not really *too* sure what I'm talking about here. I know .p3d files contain arrays and structs as well as chars, floats and ints. They also contain compressed parts too - bugger.

    I presume if sorting through a binary file there wouldn't be any nice carriage returns either to say when to start a new line. You'd have to write code that knew when it was at a suitable point (say the end of an array) and manually insert a std::endl call, to help make the file human readable.

    Any ideas? Is there such a way to find out what variable type is at a memory address and then direct extraction of that variable to a suitable piece of code which outputted it all as chars or strings?

    The mind boggles

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in C programming (too lazy)
    By cwillygs in forum C Programming
    Replies: 12
    Last Post: 04-20-2010, 12:23 AM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21