xmen Posted August 31, 2007 Share Posted August 31, 2007 hi there, i m making a tool something like img tool but i have some problems that are the tool read offset as 2 but the others img tool shows it 0001000 the same with size but i got it and multiplied it by 2 and it solved but offset is still making me crazy can some one tell me how can i solve it and how can i add/ extract and delete the files in it? im using C# 2005 i read spark source code but he made it so complicated that no one can understand it easily thanks Link to comment Share on other sites More sharing options...
aru Posted September 2, 2007 Share Posted September 2, 2007 What's so complicated about it? You have to multiply by 2048 (or 0x800) to get the real offset and real size. Link to comment Share on other sites More sharing options...
Teckizt Posted September 3, 2007 Share Posted September 3, 2007 yeah, i wanna do something like that but spark img code is complicated. You should use the IMGTool code and the Spark interface. Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 (edited) What's so complicated about it? You have to multiply by 2048 (or 0x800) to get the real offset and real size. everything you wrote 2048...??? its showing offset is 2 and when i multiply it to 2048 then it will be 4096 but other img tools is showing 1000 not 4096 You should use the IMGTool code and the Spark interface. where is IMGTool Code??? Edited September 3, 2007 by xmen Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 IMG Archive programming part 1 in C# Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 IMG Archive programming part 1 in C# i think its for gta 3/vc but i will check any other thing you wanna say ? thanks Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 IMG Archive programming part 1 in C# i think its for gta 3/vc but i will check any other thing you wanna say ? thanks Yea, but it shows you the format and how to read it in C#, then all you have to do is change it for VER2 archives which is almost the exact same, the first 4 bytes are the version and the next 4 bytes are the number of DIR items, then its the same from there on in. Check that source code out and then check out GTAModding.com IMG Archive format page. Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 IMG Archive programming part 1 in C# i think its for gta 3/vc but i will check any other thing you wanna say ? thanks Yea, but it shows you the format and how to read it in C#, then all you have to do is change it for VER2 archives which is almost the exact same, the first 4 bytes are the version and the next 4 bytes are the number of DIR items, then its the same from there on in. Check that source code out and then check out GTAModding.com IMG Archive format page. friend you misunderstood me, i knew already how to read img i just wanna know how to convert offet to as in all img tools and how to add/extract and delete files in img.... Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 The offset info is on gtamodding.com, the offset just like the size is multiplied by 2048, read the gtamodding.com page for the full details. To extract a file you open the archive at the offset for that file and then save take the bytes for that file (size is gotten by multiplying the size by 2048) and put them into an external file. To add a file you open the archive, go to the end of the file and add your external file, then you update the dir with the new info. Just look up Binary File I/O for C# and you will see some examples, have a read of the gtamodding.com page and if you have any specific questions I will check back here during the day, im gonna get a sammich. Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 ok, now i understand but i have one more question that is how to populate the bytes[] array ?? as filestream is asking for bytes[] not bytes int offset = 2048 * currentoffset;int count = 2048 * currentsize;FileStream fs= new FileStream(@"C:\Documents and Settings\NoProblem\Desktop\amn.dff", FileMode.Create); fs.Write(bytes[] array, offset, count) its just for checking Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 Will you at least try and find things out first using google, programming sites and forums instead of just asking everything. BinaryReader BinaryReader ReadBytes Method Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 (edited) Will you at least try and find things out first using google, programming sites and forums instead of just asking everything. BinaryReader BinaryReader ReadBytes Method yeah i have already did that and wasted my half day in just searching but not a single site have the information about gta except of gtamodding and gtaforums im not asking about reading bytes, i just wanna know what should be in bytes[] array means bytes[0] = ??? bytes[1] = ??? bytes =??? cant you explain little more..?? im still soo confuse about it Edited September 3, 2007 by xmen Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 Will you at least try and find things out first using google, programming sites and forums instead of just asking everything. BinaryReader BinaryReader ReadBytes Method yeah i have already did that and wasted my half day in just searching but not a single site have the information about gta except of gtamodding and gtaforums im not asking about reading bytes, i just wanna know what should be in bytes[] array means bytes[0] = ??? bytes[1] = ??? bytes =??? cant you explain little more..?? im still soo confuse about it ok... The IMG archive is nothing more than one file on top of another, think of it like a stack of files, now to make it faster for the machine the files are padded out to the nearest 2048 block. So for example if a 1byte file is added 2047 bytes are added to make up the difference. So now you know what the file is about. What goes into your byte array is the blocks of 2048 bytes that make up that file. For example take the first file in the archive thats size is 2 and its offset is 0. You set your binary reader's position to 0. You create your array of bytes with a size of 4096 (2 x 2048) You use the readbytes method to read 4096 bytes into the array. Close the binary reader and then create the new file and write the array of bytes to the file. And thats it. Link to comment Share on other sites More sharing options...
xmen Posted September 3, 2007 Author Share Posted September 3, 2007 ok as far as i understood that if i added file of 4000 bytes the 96 bytes will added as empty to make the difference, isnt it? i will try it soon and post here the result thank you buddy Link to comment Share on other sites More sharing options...
REspawn Posted September 3, 2007 Share Posted September 3, 2007 ok as far as i understood that if i added file of 4000 bytes the 96 bytes will added as empty to make the difference, isnt it? i will try it soon and post here the result thank you buddy Yep thats right. Link to comment Share on other sites More sharing options...
xmen Posted September 4, 2007 Author Share Posted September 4, 2007 (edited) oh , yeah i did , at last i extracted the file thank you soooo much REspawn Edited September 4, 2007 by xmen Link to comment Share on other sites More sharing options...
stinger99 Posted September 21, 2007 Share Posted September 21, 2007 Hey, what does 'rebuild archive' mean? Is it updating entries and deleting NULL bytes which were created after editing/deleting files from archives? Link to comment Share on other sites More sharing options...
REspawn Posted September 21, 2007 Share Posted September 21, 2007 Hey, what does 'rebuild archive' mean? Is it updating entries and deleting NULL bytes which were created after editing/deleting files from archives? Yea pretty much, when you delete a file from the archive you tend to just remove it from the listing instead of removing the physical file so thats what rebuild cleans up. Link to comment Share on other sites More sharing options...
stinger99 Posted September 21, 2007 Share Posted September 21, 2007 But if i replace file ex. afro.dff what is in gta archive and afro.dff from mod. But the second one has less blocks than first one. After replacing those files, in gta arch. there will be blank space (because oryginal file had 200kB but that from mod had only 100kB). So have I update entries after every replace operation? Or better to delete oryginal, and attach new file on end of archive? Sorry about my english. but I think you understand me Link to comment Share on other sites More sharing options...
xmen Posted September 22, 2007 Author Share Posted September 22, 2007 But if i replace file ex. afro.dff what is in gta archive and afro.dff from mod. But the second one has less blocks than first one. After replacing those files, in gta arch. there will be blank space (because oryginal file had 200kB but that from mod had only 100kB). So have I update entries after every replace operation? Or better to delete oryginal, and attach new file on end of archive? Sorry about my english. but I think you understand me i think replace function replace only the entry with new one and place the file at the end of archive it just my guess, i never do that Link to comment Share on other sites More sharing options...
stinger99 Posted September 22, 2007 Share Posted September 22, 2007 int offset = 2048 * currentoffset;int count = 2048 * currentsize;FileStream fs= new FileStream(@"C:\Documents and Settings\NoProblem\Desktop\amn.dff", FileMode.Create); fs.Write(bytes[] array, offset, count) Is it C++? And what type is bytes[] array? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now