Proper Saving a custom .bin file client-side

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
User avatar
weapon-x
Forum Legend
Arch-Angel
Posts: 1042
Joined: Wed Mar 18, 2009 4:52 am
Location: Mindanao, Philippines
Contact:
Philippines

Proper Saving a custom .bin file client-side

Post by weapon-x » Sun Nov 25, 2018 8:20 am

howdy all, yep... sorry to disappoint you guys but i am still alive (yay !) :lol:

anyhow, just currently went back to modding, so yeah...

i have lots of ideas that i wished to see in D2, however a lot of stuff requires custom data saving for each client.

i am currently able to generate a custom binary file with the following format (save\%playername%.bin), however i seemed to encounter a problem. i temporarily call the custom .bin generation code along with the frontpanel drawing code, thinking since its client-sided only (i am almost certain that this will only be called client-side so i put it there), however when i started a multiplayer session on two test PCs, the custom .bin file is only generated on the host PC, which doesn't make any sense :-|

any ideas?
" It's not the size of the dog in the fight, it's the size of the fight in the dog. "

~Mark Twain

User avatar
Necrolis
Site Admin
Throne
Posts: 8942
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: Proper Saving a custom .bin file client-side

Post by Necrolis » Mon Nov 26, 2018 7:01 am

Is it an output from txt compilation, or a custom format? Where are you hooking to create the file?
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
weapon-x
Forum Legend
Arch-Angel
Posts: 1042
Joined: Wed Mar 18, 2009 4:52 am
Location: Mindanao, Philippines
Contact:
Philippines

Re: Proper Saving a custom .bin file client-side

Post by weapon-x » Wed Dec 05, 2018 4:02 am

Necrolis wrote:
Mon Nov 26, 2018 7:01 am
Is it an output from txt compilation, or a custom format? Where are you hooking to create the file?
its a custom .bin file, and was hooked on d2client (front-panel) drawing

*sorry sir, took some time to reply, haven't got the chance to use the internet these past few days :-|

will post the code as soon as possible.


edit:

Here is the code i used, its actually just a simple stream. This is intended to save custom menu settings per character.

Code: Select all

BOOL __stdcall D2REVOLUTION_WriteCustomSaveFile(D2UnitStrc* pUnit)
{
	MyRecord pRecord;
	ZeroMemory(&pRecord, sizeof(MyRecord));

	strcpy(pRecord.szName, pUnit->pPlayerData->szName);			//save name
	pRecord.nLevel = D2COMMON_GetStat(pUnit, STAT_LEVEL, 0);	//save level
	
	pRecord.OptionA = DisplayHPBarFlag;
	pRecord.OptionB = DisplayMPBarFlag;
	pRecord.OptionC = DisplayStamBarFlag;
	pRecord.OptionD = DisplayCritterNameFlag;
	pRecord.OptionE = DisplayAllyNPCNameFlag;
	pRecord.OptionF = DisplayEnemyMonsterNameFlag;
	pRecord.OptionG = DisplayMonsterInfoTabFlag;
	pRecord.OptionH = DisplaySuperUniqueHPBarFlag;
	pRecord.OptionI = DisplayFullArmorSpriteFlag;
	pRecord.OptionJ = UseHeadColorPaletteFlag;
	pRecord.OptionK = DisplayClientGoldAutopickFlag;
	pRecord.OptionL = DisplayHPMPValFlag;
	pRecord.OptionM = DrawInvItemHighlightFlag;
	pRecord.OptionN = DrawMouseOverInvItemHighlightFlag;
	pRecord.OptionO = DrawEquippedItemHighlightFlag;
	pRecord.OptionP = DrawMouseOverEquipmentItemHighlightFlag;
	pRecord.OptionQ = DrawQuantityValueOverItemGfxFlag;
	pRecord.OptionR = DrawItemCompareFlag;

	char FileName[128];
	sprintf_s(FileName, sizeof(FileName),"save/%s.bin",pUnit->pPlayerData->szName);

	ofstream outbal(FileName, ios::out | ios::binary); //filename
	if(!outbal) 
	{
		return FALSE;
	}
  
	outbal.write((char *) &pRecord, sizeof(struct MyRecord));
	outbal.close();
  
	return TRUE;
}
I am planning to rewrite this function to handle a lot more stuff mainly custom quests, save items/item_data, object_data basically things that needs to be recorded and or retrieved :lol:
" It's not the size of the dog in the fight, it's the size of the fight in the dog. "

~Mark Twain

User avatar
Necrolis
Site Admin
Throne
Posts: 8942
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: Proper Saving a custom .bin file client-side

Post by Necrolis » Wed Dec 05, 2018 11:13 am

AH, so you are writing save files; in this case you need to be careful of where you get the data from. For UI configs, this isn't an issue because the data is all client side.
The first issue I can see is the save path; D2 isn't always launched from the folder where the save file is stored; I suggest you use the fog ordinal (#10115) to get the current save path, this will also ensure that the save folder exists (remember, Windows file paths are case sensitive).

Code: Select all

char szSavePath[256];
char szFilePath[256];
D2GetSavePath(szSavePath,sizeof(szSavePath));
sprintf_s(szFilePath,sizeof(szFilePath),"%s\\%s.uiconfig",szSavePath,pUnit->pPlayerData->szName);
When you need to save stuff other than client configs; you need the server to write the savefile to a memory buffer and stream that to the client for writing to the harddisk (and the for the client to stream it to the server when a character is loaded), this is why its easier to just hijack the last section of the save file (the iron golem) or one of the simpler sections (like skills) and inject all the custom data in there.
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
weapon-x
Forum Legend
Arch-Angel
Posts: 1042
Joined: Wed Mar 18, 2009 4:52 am
Location: Mindanao, Philippines
Contact:
Philippines

Re: Proper Saving a custom .bin file client-side

Post by weapon-x » Fri Dec 07, 2018 1:27 pm

Necrolis wrote:
Wed Dec 05, 2018 11:13 am
AH, so you are writing save files; in this case you need to be careful of where you get the data from. For UI configs, this isn't an issue because the data is all client side.
The first issue I can see is the save path; D2 isn't always launched from the folder where the save file is stored; I suggest you use the fog ordinal (#10115) to get the current save path, this will also ensure that the save folder exists (remember, Windows file paths are case sensitive).

Code: Select all

char szSavePath[256];
char szFilePath[256];
D2GetSavePath(szSavePath,sizeof(szSavePath));
sprintf_s(szFilePath,sizeof(szFilePath),"%s\\%s.uiconfig",szSavePath,pUnit->pPlayerData->szName);
When you need to save stuff other than client configs; you need the server to write the savefile to a memory buffer and stream that to the client for writing to the harddisk (and the for the client to stream it to the server when a character is loaded), this is why its easier to just hijack the last section of the save file (the iron golem) or one of the simpler sections (like skills) and inject all the custom data in there.
i was thinking of using custom S>C packets for saving important data, client-side. C>S packets for validation/checks and other stuff. I will look into hijacking the last section of the save file too, as i am not quite familiar with this routine yet

thanks for the insight sir, will try to test-out using fog ordinal #10115 first thing
" It's not the size of the dog in the fight, it's the size of the fight in the dog. "

~Mark Twain

Post Reply

Return to “Code Editing”