client.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const fs = require('fs');
  3. const path = require('path');
  4. const crypto = require('crypto');
  5. const RESOURCE = 'client/S1UI_CardComposeWindow.gpk';
  6. const EXPECTED_HASH = '812ce57e62351d84159bab36c44376bc3b78714f37f0dff8d03dfe2df5f21839';
  7. module.exports = class InstantCardsClient {
  8. constructor(mod) { this.mod = mod; }
  9. install(installer) {
  10. const mod = this.mod;
  11. if (mod.settings.cards === false) return;
  12. const info = mod.clientInterface.info;
  13. if (info.arch !== 'x64' || Number(info.majorPatchVersion) !== 100 || Number(info.minorPatchVersion) !== 2) {
  14. mod.warn('Instant cards requires the TERA 100.02 x64 client; card animation override was not loaded.');
  15. return;
  16. }
  17. const source = path.join(__dirname, RESOURCE);
  18. const hash = crypto.createHash('sha256').update(fs.readFileSync(source)).digest('hex');
  19. if (hash !== EXPECTED_HASH) throw Error('Instant cards GPK checksum mismatch. Reinstall the module.');
  20. const destination = mod.clientInterface.GPKManager.getFullPath(path.resolve(mod.clientFolder, '..'), path.basename(RESOURCE));
  21. const symlink = fs.symlinkSync;
  22. // Preserve Toolbox tracking/cleanup on Windows without symlink privileges.
  23. fs.symlinkSync = function (from, to, type) {
  24. try { return symlink(from, to, type); }
  25. catch (error) {
  26. if (!['EPERM', 'EACCES'].includes(error.code) || path.resolve(from) !== path.resolve(source) || path.resolve(to) !== path.resolve(destination)) throw error;
  27. fs.copyFileSync(from, to, fs.constants.COPYFILE_EXCL);
  28. }
  29. };
  30. try { installer.gpk(RESOURCE); }
  31. finally { fs.symlinkSync = symlink; }
  32. }
  33. };