[ create a new paste ] login | about

Link: http://codepad.org/hMfSXy66    [ raw code | fork ]

SourceSeeker - C++, pasted on Oct 23:
// ObjectMergerFixer.cpp
// VERSION 4.0.1 [2016_10_23]
//         ^     = MAJOR REBUILDS
//           ^   = NEW STUFF
//             ^ = FIXES
// BY SourceSeeker / EdwardElric (hiveworkshop.com) / MasterOfSickness (wc3c.net)

// THANKS TO:
// - Vexorian (AUTHOR OF JASSHELPER) FOR EVERYTHING :D
// - PitzerMike (AUTHOR OF GRIMEX) FOR PUBLISHING HIS SOURCE CODE
// - WaterKnight (http://www.hiveworkshop.com/members/waterknight.178519/) FOR HELPFUL TIPS VIA CHAT (http://www.hiveworkshop.com/chat/) & BEING PATIENT WITH ME & MY QUESTIONS ;p
// - Barade (http://www.hiveworkshop.com/members/barade.125524/) FOR HELPFUL TIPS ABOUT MPQ API



#include "sfmpq/SFmpqapi_no-lib.h" // HEADER FOR: MpqOpenArchiveForUpdate, ...

#include <iostream>		// SYSTEM HEADER FOR: cout
#include <fstream>		// SYSTEM HEADER FOR: ofstream
#include <vector>		// SYSTEM HEADER FOR: vector
#include <algorithm>	// SYSTEM HEADER FOR: search

using namespace std;



vector<char> getFixedW3U_uaen( char * c_buf, int size ) {
	
	// COPY INPUT W3U DATA INTO BUFFER:
	vector<char> v_buffer( c_buf, c_buf +size );
	
	vector<char> v_output;
	vector<char>::iterator it_counter;
	
	const char c_uaen[9] = { 0x75, 0x61, 0x65, 0x6E, 0x03, 0x00, 0x00, 0x00 }; // { 0x75, 0x61, 0x65, 0x6E, ... } = { u, a, e, n, ... }
	int i_uaen_getValue;
	
	int i_distance;
	int i_distance2 = 0;
	
	
	
	// SEARCH FOR "uaen" IN BINARY STREAM AS HEX SEQUENCE: { 0x75, 0x61, 0x65, 0x6E, 0x03, 0x00, 0x00, 0x00 }
		// OBJECT MERGER ERROR 1:
		// THOSE LAST 4 BYTES SHOULD BE { 0x00, 0x00, 0x00, 0x00 }
	// FOR EACH MATCH RETRIEVE THE FOLLOWING BYTE WHICH CAN BE 0x48, 0x49, 0x50 OR 0x51 (0, 1, 2 OR 3)
		// OBJECT MERGER ERROR 2:
		// THIS BYTE SHOULD BE 0x00, 0x01, 0x02 OR 0x03, FOLLOWED BY 3 NULL BYTES,
		// INSTEAD THE BYTE IS 0x48, 0x49, 0x50 OR 0x51, FOLLOWED BY 1 NULL BYTE!
	// PUT CORRECT BYTES INTO OUTPUT VECTOR
	it_counter = search( v_buffer.begin(), v_buffer.end(), c_uaen, c_uaen +8 );
	
	// IF W3U DOESN'T CONTAIN "uaen....", EXIT:
	if ( it_counter == v_buffer.end() ) {
		return vector<char>();
	
	// IF W3U CONTAINS "uaen....", APPLY FIX:
	} else {
		while ( it_counter != v_buffer.end() ) {
			
			i_distance = it_counter - v_buffer.begin();
			
			// APPEND PART OF INPUT VECTOR v_buffer TO OUTPUT VECTOR v_output:
			v_output.insert( v_output.end(), v_buffer.begin() +i_distance2, v_buffer.begin() +i_distance +4 );
			
			i_distance2 = i_distance +4;
				// = EVERYTHING UNTIL (INLCUDING) ...uaen
			
			// GET uaen VALUE:
				// CAN BE: 0, 1, 2 OR 3
				// - 0 = NOTHING
				// - 1 = ONLY ATTACK 1
				// - 2 = ONLY ATTACK 2
				// - 3 = BOTH
			i_uaen_getValue = (int)v_buffer[i_distance +8];
			i_uaen_getValue = i_uaen_getValue - '0';
				// int CONVERSION: ASCII VALUE OF NUMBER TO NUMBER
			
			// ADD FIX:
			int dataArray[8] = { 0, 0, 0, 0, i_uaen_getValue, 0, 0, 0 };
			v_output.insert( v_output.end(), &dataArray[0], &dataArray[8] );
			
			i_distance2 = i_distance2 +6;
				// i_distance2 +6 BECAUSE:
					// u a e n   0x03 0x00 0x00 0x00   0/1/2/3 0x00   
					//         ^ = distance2                        ^ = distance2 +6
			
			// CONTINUE SEARCH:
			it_counter = search( v_buffer.begin() +i_distance +4, v_buffer.end(), c_uaen, c_uaen +8 );
		}
		
		// APPEND END OF INPUT VECTOR buffer TO OUTPUT VECTOR v_output:
		v_output.insert( v_output.end(), v_buffer.begin() +i_distance2, v_buffer.end() );
		
		return v_output;
	}
	
	return vector<char>();
}



int main(int argc, char **argv) {
	
	funcMpqOpenArchiveForUpdate MpqOpenArchiveForUpdate = 0;
	funcMpqCloseUpdatedArchive MpqCloseUpdatedArchive = 0;
	funcMpqAddFileFromBufferEx MpqAddFileFromBufferEx = 0;
	funcMpqAddFileFromBuffer MpqAddFileFromBuffer = 0;
	
	funcSFileOpenFileEx SFileOpenFileEx = 0;
	funcSFileGetFileSize SFileGetFileSize = 0;
	funcSFileReadFile SFileReadFile = 0;
	funcSFileCloseFile SFileCloseFile = 0;
	
	
	
	HINSTANCE hSFMpq = 0;
	hSFMpq = LoadLibrary("SFMpq.dll");
		// "SFMpq.dll" FROM PitzerMike WAS BUILD AS 32-BIT DLL!
		// IF YOU WANT TO USE THIS DLL, YOUR PROJECT HAS TO BE COMPILED AS 32-BIT TOO, OTHERWISE THE DLL ISN'T LOADED!
	
	// IF DLL 'SFMpq.dll' WAS LOADED, CONTINUE:
	if (hSFMpq!=0) {
		
		MpqOpenArchiveForUpdate = (funcMpqOpenArchiveForUpdate)GetProcAddress(hSFMpq,"MpqOpenArchiveForUpdate");
		MpqCloseUpdatedArchive = (funcMpqCloseUpdatedArchive)GetProcAddress(hSFMpq,"MpqCloseUpdatedArchive");
		MpqAddFileFromBufferEx = (funcMpqAddFileFromBufferEx)GetProcAddress(hSFMpq,"MpqAddFileFromBufferEx");
		MpqAddFileFromBuffer = (funcMpqAddFileFromBuffer)GetProcAddress(hSFMpq,"MpqAddFileFromBuffer");
		
		SFileOpenFileEx = (funcSFileOpenFileEx)GetProcAddress(hSFMpq,"SFileOpenFileEx");
		SFileGetFileSize = (funcSFileGetFileSize)GetProcAddress(hSFMpq,"SFileGetFileSize");
		SFileReadFile = (funcSFileReadFile)GetProcAddress(hSFMpq,"SFileReadFile");
		SFileCloseFile = (funcSFileCloseFile)GetProcAddress(hSFMpq,"SFileCloseFile");
		
		
		
		HANDLE mpq = MpqOpenArchiveForUpdate(argv[1], MOAU_OPEN_EXISTING | MOAU_MAINTAIN_LISTFILE, 1024);
		
		HANDLE file;
		
		if(!SFileOpenFileEx(mpq, "war3map.w3u", 0, &file)) {
			// DEBUG:
			MessageBox(0, "fail: could not open 'war3map.w3u'", "error", MB_OK);
			cout << "fail: could not open 'war3map.w3u'\n" << "HIT ENTER TO CONTINUE!\n";
			getchar();
			return 0;
		}
		
		DWORD size = SFileGetFileSize(file, 0);
			// Retrieves a size of the file within archive
			// http://www.zezula.net/en/mpq/stormlib.html
		
		char * c_buf = new char[size];
		
		SFileReadFile(file, c_buf, size, &size, NULL);
			// Reads data from the file
			// http://www.zezula.net/en/mpq/stormlib.html
			// CONTENT FROM FILE file IS SAVED TO buf.buf
		
		SFileCloseFile(file);
		
		
		
		// W3U FIXES:
		vector<char> v_output = getFixedW3U_uaen(c_buf, size);
		
		
		
		// ADD FIXED W3U BACK TO W3M/W3X:
		if ( !MpqAddFileFromBufferEx(mpq, (LPVOID)&v_output[0], v_output.size(), "war3map.w3u", MAFA_REPLACE_EXISTING | MAFA_COMPRESS, MAFA_COMPRESS_DEFLATE, Z_BEST_COMPRESSION) ) {
			// DEBUG:
			MessageBox(0, "fail: could not write 'war3map.w3u'", "error", MB_OK);
			cout << "fail: could not write 'war3map.w3u'\n" << "HIT ENTER TO CONTINUE!\n";
			getchar();
		}
		
		
		
		if ( !MpqCloseUpdatedArchive(mpq, 0) ) {
			// DEBUG:
			MessageBox(0, "fail: could not update MPQ", "error", MB_OK);
			cout << "fail: could not update MPQ\n" << "HIT ENTER TO CONTINUE!\n";
			getchar();
		}
	
	// IF DLL 'SFMpq.dll' WAS NOT LOADED, EXIT:
	} else {
		// DEBUG:
		MessageBox(0, "fail: could not load 'SFMpq.dll'", "error", MB_OK);
		cout << "fail: could not load 'SFMpq.dll'\n" << "HIT ENTER TO CONTINUE!\n";
		getchar();
	}
	
	
	
	return 0;
}


Create a new paste based on this one


Comments: