open-tibia-library
open-tibia-library copied to clipboard
DatManager saveDat function saves file not the same as loaded .dat file
const client = new Client();
client.setClientVersion(860);
const datManager = new DatManager(client);
await datManager.loadDatFromUrl('http://127.0.0.1/Tibia.dat').then(datLoaded => {
console.log('load dat status', datLoaded)
});
const datFile = datManager.saveDat();
Saves file that is not the same as Tibia.dat loaded.
Data in file is the same, but when you compare it byte by byte, it's different.
Load -> Save code should generate the same file, if nothing was modified by DatManager.
There are 2 problems:
- Original client .dat files have item attributes in different order than from 0 to 39. Different Tibia client version have attributes in different order.
saveDatchanges something in "frame group" (idle/walk animation of outfits added in 10.57), it's 1 byte changed per 1 outfit
I've made this ordered attributes code:
if (this.m_client.getClientVersion() < 780) {
return [254, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 33, 22, 23, 24, 34, 25, 26, 27, 28, 32, 29, 30, 35, 31, 36, 37, 38];
} else if (this.m_client.getClientVersion() < 860) {
return [254, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 33, 22, 23, 24, 34, 25, 26, 27, 28, 32, 29, 30, 35, 31, 36, 37, 38];
} else if (this.m_client.getClientVersion() < 900) {
return [254, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 32, 21, 33, 22, 23, 24, 34, 25, 26, 27, 31, 28, 29, 30, 35, 36, 37, 38];
} else if (this.m_client.getClientVersion() < 1000) {
return [254, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 32, 21, 33, 22, 23, 24, 34, 25, 26, 27, 31, 28, 29, 30, 35, 36, 37, 38];
} else {
return [254, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 33, 22, 23, 24, 34, 25, 26, 27, 28, 32, 29, 30, 35, 31, 36, 37, 38];
}
Current results of loading and saving all versions of Tibia.dat file are ( - 1 = files are the same, - 0 files are different):
760 - 1
770 - 1
772 - 1
780 - 0
781 - 0
790 - 0
792 - 0
800 - 0
811 - 0
820 - 0
821 - 0
822 - 0
830 - 0
831 - 0
840 - 0
841 - 0
842 - 0
850 - 0
852 - 0
853 - 0
854 - 0
855 - 0
856 - 0
857 - 0
860 - 1
861 - 1
862 - 1
870 - 1
871 - 1
900 - 1
910 - 1
920 - 1
931 - 1
940 - 1
941 - 1
942 - 1
943 - 1
944 - 1
946 - 1
952 - 1
954 - 1
960 - 1
970 - 1
971 - 1
980 - 1
981 - 1
1010 - 1
1020 - 1
1035 - 1
1036 - 1
1037 - 1
1038 - 1
1041 - 1
1050 - 1
1055 - 1
1057 - 0
1059 - 0
1061 - 0
1063 - 0
1064 - 0
1070 - 0
1071 - 0
1073 - 0
1075 - 0
1076 - 0
1077 - 0
1078 - 0
1079 - 0
1080 - 0
1081 - 0
1082 - 0
1090 - 0
1091 - 0
1092 - 0
1093 - 0
1094 - 0
1095 - 0
1096 - 0
1097 - 0
1098 - 0
1099 - 0