Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- typedef unsigned int uint32;
- typedef int int32;
- typedef unsigned short uint16;
- typedef short int16;
- struct Vec3F {
- /*0x000*/ float x;
- /*0x004*/ float y;
- /*0x008*/ float z;
- };
- struct ABlock {
- /*0x000*/ uint16 InterpolationType;
- /*0x002*/ uint16 GlobalSequenceID;
- /*0x004*/ uint32 numberOfTimestampPairs;
- /*0x008*/ uint32 offsetToTimestampPairs;
- /*0x00C*/ uint32 numberOfKeyFramePairs;
- /*0x010*/ uint32 offsetToKeyFramePairs;
- };
- struct Pairs {
- /*0x000*/ uint32 Number;
- /*0x004*/ uint32 Offset;
- };
- struct M2Header {
- /*0x000*/ char Magic[4];
- /*0x004*/ uint32 Version;
- /*0x008*/ uint32 lName;
- /*0x00C*/ uint32 ofsName;
- /*0x010*/ uint32 GlobalModelFlags;
- /*0x014*/ uint32 nGlobalSequences;
- /*0x018*/ uint32 ofsGlobalSequences;
- /*0x01C*/ uint32 nAnimations;
- /*0x020*/ uint32 ofsAnimations;
- /*0x024*/ uint32 nAnimationLookup;
- /*0x028*/ uint32 ofsAnimationLookup;
- /*0x02C*/ uint32 nBones;
- /*0x030*/ uint32 ofsBones;
- /*0x034*/ uint32 nKeyBoneLookup;
- /*0x038*/ uint32 ofsKeyBoneLookup;
- /*0x03C*/ uint32 nVertices;
- /*0x040*/ uint32 ofsVertices;
- /*0x044*/ uint32 nViews;
- /*0x048*/ uint32 nColors;
- /*0x04C*/ uint32 ofsColors;
- /*0x050*/ uint32 nTextures;
- /*0x054*/ uint32 ofsTextures;
- /*0x058*/ uint32 nTransparency;
- /*0x05C*/ uint32 ofsTransparency;
- /*0x060*/ uint32 nUVAnimation;
- /*0x064*/ uint32 ofsUVAnimation;
- /*0x068*/ uint32 nTexReplace;
- /*0x06C*/ uint32 ofsTexReplace;
- /*0x070*/ uint32 nRenderFlags;
- /*0x074*/ uint32 ofsRenderFlags;
- /*0x078*/ uint32 nBoneLookupTable;
- /*0x07C*/ uint32 ofsBoneLookupTable;
- /*0x080*/ uint32 nTexLookup;
- /*0x084*/ uint32 ofsTexLookup;
- /*0x088*/ uint32 nTexUnits;
- /*0x08C*/ uint32 ofsTexUnits;
- /*0x090*/ uint32 nTransLookup;
- /*0x094*/ uint32 ofsTransLookup;
- /*0x098*/ uint32 nUVAnimLookup;
- /*0x09C*/ uint32 ofsUVAnimLookup;
- /*0x0A0*/ Vec3F VertexBox[2];
- /*0x0B8*/ float VertexRadius;
- /*0x0BC*/ Vec3F BoundingBox[2];
- /*0x0D4*/ float BoundingRadius;
- /*0x0D8*/ uint32 nBoundingTriangles;
- /*0x0DC*/ uint32 ofsBoundingTriangles;
- /*0x0E0*/ uint32 nBoundingVertices;
- /*0x0E4*/ uint32 ofsBoundingVertices;
- /*0x0E8*/ uint32 nBoundingNormals;
- /*0x0EC*/ uint32 ofsBoundingNormals;
- /*0x0F0*/ uint32 nAttachments;
- /*0x0F4*/ uint32 ofsAttachments;
- /*0x0F8*/ uint32 nAttachLookup;
- /*0x0FC*/ uint32 ofsAttachLookup;
- /*0x100*/ uint32 nEvents;
- /*0x104*/ uint32 ofsEvents;
- /*0x108*/ uint32 nLights;
- /*0x10C*/ uint32 ofsLights;
- /*0x110*/ uint32 nCameras;
- /*0x114*/ uint32 ofsCameras;
- /*0x118*/ uint32 nCameraLookup;
- /*0x11C*/ uint32 ofsCameraLookup;
- /*0x120*/ uint32 nRibbonEmitters;
- /*0x124*/ uint32 ofsRibbonEmitters;
- /*0x128*/ uint32 nParticleEmitters;
- /*0x12C*/ uint32 ofsParticleEmitters;
- };
- struct Light
- {
- /*0x00*/ uint16 Type;
- /*0x02*/ int16 Bone ;
- /*0x04*/ float Position[3];
- /*0x10*/ ABlock AmbientColor;
- /*0x24*/ ABlock AmbientIntensity;
- /*0x38*/ ABlock DiffuseColor;
- /*0x4C*/ ABlock DiffuseIntensity;
- /*0x60*/ ABlock AttenuationStart;
- /*0x74*/ ABlock AttenuationEnd;
- /*0x88*/ ABlock Unknown;
- };
- const short OFFSET = 0x0;
- const short BUFFER = 8;
- M2Header header;
- fstream m2file;
- char command;
- float getABlockFloat(fstream *file, uint32 offset, int index = 0);
- void setABlockFloat(fstream *file, float value, uint32 offset, int index = 0);
- void setABlockInt(fstream *file, uint32 value, uint32 offset, int index);
- void setUInt16(fstream *file, unsigned short value, unsigned int offset);
- void setInt16(fstream *file, short value, unsigned int offset);
- void setFloat(fstream *file, float value, unsigned int offset);
- int main(int argc, char **argv) {
- if(argc == 1)
- {
- cout << "You need to put a M2 file to get this working.";
- cin.ignore( numeric_limits<streamsize>::max(), '\n' );
- return 0;
- }
- //TODO: Add check for M2 (magic) file.
- m2file.open(argv[1], ios::in | ios::out | ios::binary);
- m2file.seekg(OFFSET);
- m2file.read(reinterpret_cast<char *>(&header), sizeof(M2Header));
- Light *lights;
- lights = new Light[header.nLights];
- if(!header.ofsLights == 0 && !header.nLights == 0)
- {
- m2file.seekg(header.ofsLights);
- for(int i=0; i<header.nLights; i++)
- {
- m2file.read(reinterpret_cast<char *>(&(lights[i])), sizeof(Light));
- }
- }
- cout << "Done by MegaBigBoss/Garthog. Thanks to Schlumpf and Tigurius for helping me." << endl << "Also, be careful. This tool could corrupt your M2" << endl << endl;
- cout << "h : This message" << endl;
- cout << "i : Print info" << endl;
- cout << "c : Create new Light" << endl;
- cout << "m : Modify existing light" << endl;
- cout << "d : Delete existing light" << endl;
- cout << "x : Exit" << endl;
- while(1)
- {
- cout << endl << "> ";
- cin >> command;
- switch(command)
- {
- case 'c':
- {
- if(header.nLights > 0)
- {
- // il faut copier les lumières existantes, ainsi que leurs données, les zerofiller, et en recréer à la fin
- // du fichier avec les mêmes valeurs et tout et tout.
- cout << "This file already have lights. Please, delete them before trying to add new one, because it can only add one light to one model which hasn't got any light." << endl;
- }
- else
- {
- long size;
- const char null = NULL;
- m2file.seekg(0,ifstream::end);
- m2file.seekp(0,ifstream::end);
- size=m2file.tellg();
- header.nLights = 1;
- header.ofsLights = size; // Formula to add that shit. ( Hm. End of the file ? And then file.put(260) - 1C4 all the ABlocks shits + 9C light size
- char tmp[0x260];
- memset(tmp, 0, sizeof(tmp));
- m2file.write(tmp, sizeof(tmp));
- cout << endl << "DEBUG : " << hex << size << endl;
- // Now, we need to define aaaaall the vars.
- Light newLight;
- float ar, ag, ab, ai, dr, dg, db, di;
- cout << "Write the data following this format : [TYPE] [BONE] [X] [Y] [Z]" << endl;
- cin >> newLight.Type >> newLight.Bone >> newLight.Position[0] >> newLight.Position[1] >> newLight.Position[2];
- cout << "Now, this format : [AR] [AG] [AB] [AI] [DR] [DG] [DB] [DI]" << endl;
- cin >> ar >> ag >> ab >> ai >> dr >> dg >> db >> di;
- /*
- *OFSLIGHT + A0 = OFS_PAIRS[0]
- *OFS_PAIRS[0].N = 1
- *OFS_PAIRS[0].OFS = OFS_PAIRS[0] + E0
- */
- uint32 one = 1;
- uint32 offset;
- newLight.AmbientColor.InterpolationType = 0;
- newLight.AmbientColor.GlobalSequenceID = -1;
- newLight.AmbientColor.numberOfTimestampPairs = 1;
- newLight.AmbientColor.offsetToTimestampPairs = header.ofsLights + 0xA0;
- m2file.seekp(header.ofsLights + 0xA0);
- offset = header.ofsLights + 0xA0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AmbientColor.numberOfKeyFramePairs = 1;
- newLight.AmbientColor.offsetToKeyFramePairs = header.ofsLights + 0xB0;
- m2file.seekp(header.ofsLights + 0xB0);
- offset = header.ofsLights + 0xB0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AmbientIntensity.InterpolationType = 0;
- newLight.AmbientIntensity.GlobalSequenceID = -1;
- newLight.AmbientIntensity.numberOfTimestampPairs = 1;
- newLight.AmbientIntensity.offsetToTimestampPairs = header.ofsLights + 0xC0;
- m2file.seekp(header.ofsLights + 0xC0);
- offset = header.ofsLights + 0xC0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AmbientIntensity.numberOfKeyFramePairs = 1;
- newLight.AmbientIntensity.offsetToKeyFramePairs = header.ofsLights + 0xD0;
- m2file.seekp(header.ofsLights + 0xD0);
- offset = header.ofsLights + 0xD0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.DiffuseColor.InterpolationType = 0;
- newLight.DiffuseColor.GlobalSequenceID = -1;
- newLight.DiffuseColor.numberOfTimestampPairs = 1;
- newLight.DiffuseColor.offsetToTimestampPairs = header.ofsLights + 0xE0;
- m2file.seekp(header.ofsLights + 0xE0);
- offset = header.ofsLights + 0xE0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.DiffuseColor.numberOfKeyFramePairs = 1;
- newLight.DiffuseColor.offsetToKeyFramePairs = header.ofsLights + 0xF0;
- m2file.seekp(header.ofsLights + 0xF0);
- offset = header.ofsLights + 0xF0 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.DiffuseIntensity.InterpolationType = 0;
- newLight.DiffuseIntensity.GlobalSequenceID = -1;
- newLight.DiffuseIntensity.numberOfTimestampPairs = 1;
- newLight.DiffuseIntensity.offsetToTimestampPairs = header.ofsLights + 0x100;
- m2file.seekp(header.ofsLights + 0x100);
- offset = header.ofsLights + 0x100 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.DiffuseIntensity.numberOfKeyFramePairs = 1;
- newLight.DiffuseIntensity.offsetToKeyFramePairs = header.ofsLights + 0x110;
- m2file.seekp(header.ofsLights + 0x110);
- offset = header.ofsLights + 0x110 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AttenuationStart.InterpolationType = 0;
- newLight.AttenuationStart.GlobalSequenceID = -1;
- newLight.AttenuationStart.numberOfTimestampPairs = 1;
- newLight.AttenuationStart.offsetToTimestampPairs = header.ofsLights + 0x120;
- m2file.seekp(header.ofsLights + 0x120);
- offset = header.ofsLights + 0x120 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AttenuationStart.numberOfKeyFramePairs = 1;
- newLight.AttenuationStart.offsetToKeyFramePairs = header.ofsLights + 0x130;
- m2file.seekp(header.ofsLights + 0x130);
- offset = header.ofsLights + 0x130 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AttenuationEnd.InterpolationType = 0;
- newLight.AttenuationEnd.GlobalSequenceID = -1;
- newLight.AttenuationEnd.numberOfTimestampPairs = 1;
- newLight.AttenuationEnd.offsetToTimestampPairs = header.ofsLights + 0x140;
- m2file.seekp(header.ofsLights + 0x140);
- offset = header.ofsLights + 0x140 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.AttenuationEnd.numberOfKeyFramePairs = 1;
- newLight.AttenuationEnd.offsetToKeyFramePairs = header.ofsLights + 0x150;
- m2file.seekp(header.ofsLights + 0x150);
- offset = header.ofsLights + 0x150 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.Unknown.InterpolationType = 0;
- newLight.Unknown.GlobalSequenceID = -1;
- newLight.Unknown.numberOfTimestampPairs = 1;
- newLight.Unknown.offsetToTimestampPairs = header.ofsLights + 0x160;
- m2file.seekp(header.ofsLights + 0x160);
- offset = header.ofsLights + 0x160 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- newLight.Unknown.numberOfKeyFramePairs = 1;
- newLight.Unknown.offsetToKeyFramePairs = header.ofsLights + 0x170;
- m2file.seekp(header.ofsLights + 0x170);
- offset = header.ofsLights + 0x170 + 0xE0;
- m2file.write(reinterpret_cast<char *>(&(one)), sizeof(uint32));
- m2file.write(reinterpret_cast<char *>(&(offset)), sizeof(uint32));
- setABlockFloat(&m2file, ar, newLight.AmbientColor.offsetToKeyFramePairs,0);
- setABlockFloat(&m2file, ag, newLight.AmbientColor.offsetToKeyFramePairs,1);
- setABlockFloat(&m2file, ab, newLight.AmbientColor.offsetToKeyFramePairs,2);
- setABlockFloat(&m2file, ai, newLight.AmbientIntensity.offsetToKeyFramePairs,0);
- setABlockFloat(&m2file, dr, newLight.DiffuseColor.offsetToKeyFramePairs,0);
- setABlockFloat(&m2file, dg, newLight.DiffuseColor.offsetToKeyFramePairs,1);
- setABlockFloat(&m2file, db, newLight.DiffuseColor.offsetToKeyFramePairs,2);
- setABlockFloat(&m2file, di, newLight.DiffuseIntensity.offsetToKeyFramePairs,0);
- float start = 1.2;
- float end = 2.4;
- setABlockFloat(&m2file, start, newLight.AttenuationStart.offsetToKeyFramePairs,0);
- setABlockFloat(&m2file, end, newLight.AttenuationEnd.offsetToKeyFramePairs,0);
- setABlockInt(&m2file, 1, newLight.Unknown.offsetToKeyFramePairs,0);
- m2file.seekp(header.ofsLights);
- m2file.write(reinterpret_cast<char *>(&(newLight)), sizeof(newLight));
- m2file.seekp(OFFSET);
- m2file.write(reinterpret_cast<char *>(&header), sizeof(M2Header));
- }
- }
- break;
- case 'd':
- {
- }
- break;
- case 'm':
- {
- int entry = 0;
- bool menu = false;
- char subcommand;
- std::system ( "CLS" );
- cout << "Light entry > ";
- cin >> entry;
- if(entry > header.nLights)
- {
- cout << "Bad entry";
- }
- else
- {
- menu = true;
- cout << endl;
- cout << "r : Return in the previous menu" << endl;
- cout << "t : Set type of light" << endl;
- cout << "b : Set bone of light" << endl;
- cout << "p : Set X, Y, Z of light" << endl << endl;
- cout << "a : Set RGB of light's AmbientColor" << endl;
- cout << "z : Set intensity of AmbiantColor" << endl << endl;
- cout << "d : Set RGB of light's DiffuseColor" << endl;
- cout << "i : Set intensity of light's DiffuseColor" << endl << endl;
- while(menu == true)
- {
- cout << "> ";
- cin >> subcommand;
- switch(subcommand)
- {
- case 'r':
- {
- menu = false;
- std::system ( "CLS" );
- cout << "Done by MegaBigBoss/Garthog. Thanks to Schlumpf and Tigurius for helping me." << endl << endl;
- cout << "h : This message" << endl;
- cout << "i : Print info" << endl;
- cout << "c : Create new Light" << endl;
- cout << "m : Modify existing light" << endl;
- cout << "d : Delete existing light" << endl;
- cout << "x : Exit" << endl;
- }
- break;
- case 't':
- {
- uint16 newtype;
- cout << "New type >";
- cin >> newtype;
- lights[entry].Type = newtype;
- setUInt16(&m2file, newtype, (header.ofsLights + (entry * sizeof(Light))));
- }
- break;
- case 'b':
- {
- int16 bone;
- cout << "New bone >";
- cin >> bone;
- lights[entry].Bone = bone;
- setInt16(&m2file, bone, (header.ofsLights + sizeof(uint16) + (entry * sizeof(Light))));
- }
- break;
- case 'p':
- {
- float x, y, z;
- cout << "X >";
- cin >> x;
- cout << endl << "Y >";
- cin >> y;
- cout << endl << "Z >";
- cin >> z;
- lights[entry].Position[0] = x;
- lights[entry].Position[1] = y;
- lights[entry].Position[2] = z;
- setFloat(&m2file, x, (header.ofsLights + 0x04 + (entry * sizeof(Light))));
- setFloat(&m2file, y, (header.ofsLights + 0x08 + (entry * sizeof(Light))));
- setFloat(&m2file, z, (header.ofsLights + 0xC + (entry * sizeof(Light))));
- }
- break;
- case 'a':
- {
- float r, g, b;
- cout << "R >";
- cin >> r;
- cout << endl << "G >";
- cin >> g;
- cout << endl << "B >";
- cin >> b;
- setABlockFloat(&m2file, r, lights[entry].AmbientColor.offsetToKeyFramePairs);
- setABlockFloat(&m2file, g, lights[entry].AmbientColor.offsetToKeyFramePairs, 1);
- setABlockFloat(&m2file, b, lights[entry].AmbientColor.offsetToKeyFramePairs, 2);
- }
- break;
- case 'z':
- {
- float intensity;
- cout << "Intensity >";
- cin >> intensity;
- setABlockFloat(&m2file, intensity, lights[entry].AmbientIntensity.offsetToKeyFramePairs);
- }
- break;
- case 'd':
- {
- float r, g, b;
- cout << "R >";
- cin >> r;
- cout << endl << "G >";
- cin >> g;
- cout << endl << "B >";
- cin >> b;
- setABlockFloat(&m2file, r, lights[entry].DiffuseColor.offsetToKeyFramePairs);
- setABlockFloat(&m2file, g, lights[entry].DiffuseColor.offsetToKeyFramePairs, 1);
- setABlockFloat(&m2file, b, lights[entry].DiffuseColor.offsetToKeyFramePairs, 2);
- }
- break;
- case 'i':
- {
- float intensity;
- cout << "Intensity >";
- cin >> intensity;
- setABlockFloat(&m2file, intensity, lights[entry].DiffuseIntensity.offsetToKeyFramePairs);
- }
- break;
- }
- }
- }
- }
- break;
- case 'i':
- {
- cout << "There are : " << header.nLights << " lights in this M2." << endl << endl;
- for(int i=0; i<header.nLights; i++)
- {
- cout << "Light " << i << " ( " << std::hex << header.ofsLights + (i * sizeof(Light)) << " )" << endl;
- cout << "Type : " << lights[i].Type << endl;
- cout << "Bone : " << lights[i].Bone << endl;
- cout << "Position X = " << lights[i].Position[0] << " Y = " << lights[i].Position[1] << " Z = " << lights[i].Position[2] << endl;
- cout << "Ambient Color ( RGB ) : " << getABlockFloat(&m2file, lights[i].AmbientColor.offsetToKeyFramePairs) << " " << getABlockFloat(&m2file, lights[i].AmbientColor.offsetToKeyFramePairs, 1) << " " << getABlockFloat(&m2file, lights[i].AmbientColor.offsetToKeyFramePairs, 2) << endl;
- cout << "Ambient intensity : " << getABlockFloat(&m2file, lights[i].AmbientIntensity.offsetToKeyFramePairs) << endl;
- cout << "Diffuse Color ( RGB ) : " << getABlockFloat(&m2file, lights[i].DiffuseColor.offsetToKeyFramePairs) << " " << getABlockFloat(&m2file, lights[i].AmbientColor.offsetToKeyFramePairs, 1) << " " << getABlockFloat(&m2file, lights[i].AmbientColor.offsetToKeyFramePairs, 2) << endl;
- cout << "Diffuse intensity : " << getABlockFloat(&m2file, lights[i].DiffuseIntensity.offsetToKeyFramePairs) << endl;
- }
- }
- break;
- case 'x':
- {
- delete[] lights;
- m2file.close();
- return 0;
- }
- break;
- default:
- {
- cout << "Done by MegaBigBoss/Garthog. Thanks to Schlumpf and Tigurius for helping me." << endl << endl;
- cout << "i : Print info" << endl;
- cout << "c : Create new Light" << endl;
- cout << "m : Modify existing light" << endl;
- cout << "d : Delete existing light" << endl;
- cout << "x : Exit" << endl << endl;
- }
- break;
- }
- }
- }
- float getABlockFloat(fstream *file, uint32 offset, int index)
- {
- uint32 location = file->tellg();
- int32 real_offset;
- float value;
- file->seekg(offset + sizeof(int32));
- file->read(reinterpret_cast<char *>(&(real_offset)), sizeof(int32));
- file->seekg(real_offset + (index * sizeof(float)));
- file->read(reinterpret_cast<char *>(&(value)), sizeof(float));
- file->seekg(location);
- return value;
- }
- void setABlockFloat(fstream *file, float value, uint32 offset, int index)
- {
- uint32 glocation = file->tellg();
- uint32 plocation = file->tellp();
- int32 real_offset;
- file->seekg(offset + sizeof(int32));
- file->read(reinterpret_cast<char *>(&(real_offset)), sizeof(int32));
- file->seekp(real_offset + (index * sizeof(float)));
- file->write(reinterpret_cast<char *>(&(value)), sizeof(float));
- file->seekg(glocation);
- file->seekp(plocation);
- }
- void setABlockInt(fstream *file, uint32 value, uint32 offset, int index)
- {
- uint32 glocation = file->tellg();
- uint32 plocation = file->tellp();
- int32 real_offset;
- file->seekg(offset + sizeof(int32));
- file->read(reinterpret_cast<char *>(&(real_offset)), sizeof(int32));
- file->seekp(real_offset + (index * sizeof(uint32)));
- file->write(reinterpret_cast<char *>(&(value)), sizeof(uint32));
- file->seekg(glocation);
- file->seekp(plocation);
- }
- void setUInt16(fstream *file, unsigned short value, unsigned int offset)
- {
- uint32 glocation = file->tellg();
- uint32 plocation = file->tellp();
- file->seekp(offset);
- file->write(reinterpret_cast<char *>(&(value)), sizeof(unsigned short));
- file->seekg(glocation);
- file->seekp(plocation);
- }
- void setInt16(fstream *file, short value, unsigned int offset)
- {
- uint32 glocation = file->tellg();
- uint32 plocation = file->tellp();
- file->seekp(offset);
- file->write(reinterpret_cast<char *>(&(value)), sizeof(short));
- file->seekg(glocation);
- file->seekp(plocation);
- }
- void setFloat(fstream *file, float value, unsigned int offset)
- {
- uint32 glocation = file->tellg();
- uint32 plocation = file->tellp();
- file->seekp(offset);
- file->write(reinterpret_cast<char *>(&(value)), sizeof(float));
- file->seekg(glocation);
- file->seekp(plocation);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement