Skip to content

Commit

Permalink
feat: rename lib folders
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Aug 31, 2020
1 parent 16fc741 commit a14616e
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/GHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {GhostBNetSIDHandler} from "./ghost/bnet/GhostBNetSIDHandler";
import {GhostBNetSIDReceiver} from "./ghost/bnet/GhostBNetSIDReceiver";
import {Config} from "./Config";
import {SHA1} from "./SHA1";
import {MPQ} from './libStorm';
import {MPQ} from './storm';

const {debug, info, error} = createLoggerFor('GHost');

Expand Down
5 changes: 0 additions & 5 deletions src/Storm.ts

This file was deleted.

25 changes: 12 additions & 13 deletions src/BNCSUtil.ts → src/bncsutil/BNCSUtil.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// libbncsutil
import * as ref from 'ref-napi';
import * as bp from 'bufferpack';
import * as os from 'os';

import * as lib from './libbncsutil/libbncsutil';
import {ByteArray} from './Bytes';
import {createLoggerFor} from "./Logger";
import {bncsutil} from './libbncsutil';
import {ByteArray} from '../Bytes';
import {createLoggerFor} from "../Logger";

const {debug, info, error} = createLoggerFor('BNCSUtil');

Expand All @@ -30,7 +29,7 @@ export class BNCSUtil {
static PLATFORM_OSX = 3;

static extractMPQNumber(mpqName): string {
return lib.libbncsutil.extractMPQNumber(mpqName);
return bncsutil.extractMPQNumber(mpqName);
}

static getPlatform(): number {
Expand All @@ -52,7 +51,7 @@ export class BNCSUtil {
static getVersion(): string {
let verChar = ref.alloc('string');

lib.libbncsutil.bncsutil_getVersionString(verChar);
bncsutil.bncsutil_getVersionString(verChar);

return verChar.toString();
}
Expand All @@ -72,7 +71,7 @@ export class BNCSUtil {

//MEXP(int) getExeInfo(const char* file_name, char* exe_info, size_t exe_info_size, uint32_t* version, int platform)

let length = lib.libbncsutil.getExeInfo(
let length = bncsutil.getExeInfo(
fileName,
exeInfo,
exeInfo.length,
Expand Down Expand Up @@ -106,7 +105,7 @@ export class BNCSUtil {

//console.log('checkRevisionFlat', arguments);

lib.libbncsutil.checkRevisionFlat(
bncsutil.checkRevisionFlat(
valueString,
file1,
file2,
Expand Down Expand Up @@ -139,7 +138,7 @@ export class BNCSUtil {
let product = ref.alloc('uint32');
let hashBuffer = ref.alloc('string');

lib.libbncsutil.kd_quick(
bncsutil.kd_quick(
CDKey,
clientToken,
serverToken,
Expand Down Expand Up @@ -171,7 +170,7 @@ export class BNCSUtil {
* MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length,
const char* password, unsigned long password_length)
*/
return lib.libbncsutil.nls_init_l(username, username.length, password, password.length)
return bncsutil.nls_init_l(username, username.length, password, password.length)
}

/**
Expand All @@ -180,7 +179,7 @@ export class BNCSUtil {
static nls_get_A(nls_t): Buffer {
let buffer = Buffer.alloc(32);

lib.libbncsutil.nls_get_A(nls_t, buffer);
bncsutil.nls_get_A(nls_t, buffer);

return buffer;
}
Expand All @@ -193,7 +192,7 @@ export class BNCSUtil {
//MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt);
let buffer = Buffer.alloc(20);

lib.libbncsutil.nls_get_M1(nls_t, buffer, B, salt);
bncsutil.nls_get_M1(nls_t, buffer, B, salt);

return buffer;
}
Expand All @@ -204,7 +203,7 @@ export class BNCSUtil {
static hashPassword(password): Buffer {
let buffer = Buffer.alloc(20);

lib.libbncsutil.hashPassword(password, buffer);
bncsutil.hashPassword(password, buffer);

return buffer
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 6 additions & 44 deletions src/libbncsutil/libbncsutil.js → src/bncsutil/libbncsutil.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { resolveLibraryPath } from "../util";

const FFI = require('ffi-napi'),
ref = require('ref-napi'),
path = require('path');
ref = require('ref-napi');

const voidPtr = ref.refType(ref.types.void);

exports.CONSTANTS = {
const CONSTANTS = {
'': {
P_ALL: 0,
P_PID: 1,
Expand All @@ -15,47 +16,12 @@ exports.CONSTANTS = {
},
};

// var siginfo_t = exports.siginfo_t = voidPtr;
// var siginfo_tPtr = exports.siginfo_tPtr = ref.refType(siginfo_t);
// var div_t = exports.div_t = Struct({
// quot: ref.types.int32,
// rem: ref.types.int32,
// });
// var div_tPtr = exports.div_tPtr = ref.refType(div_t);
// var ldiv_t = exports.ldiv_t = Struct({
// quot: ref.types.long,
// rem: ref.types.long,
// });
// var ldiv_tPtr = exports.ldiv_tPtr = ref.refType(ldiv_t);
// var lldiv_t = exports.lldiv_t = Struct({
// quot: ref.types.longlong,
// rem: ref.types.longlong,
// });
// var lldiv_tPtr = exports.lldiv_tPtr = ref.refType(lldiv_t);
// var wchar_t = exports.wchar_t = Struct({
// __darwin_wchar_t: ref.types.int32,
// });
// var wchar_tPtr = exports.wchar_tPtr = ref.refType(wchar_t);
const uint32_t = exports.uint32_t = voidPtr;
const uint32_tPtr = exports.uint32_tPtr = ref.refType(uint32_t);
const nls_t = exports.nls_t = voidPtr;
const nls_tPtr = exports.nls_tPtr = ref.refType(nls_t);

const platform = process.platform;
const cwd = process.cwd();
let libPath = null;

if (platform === 'win32'){
libPath = '/libbncsutil.dll';
}else if(platform === 'linux'){
libPath = '/libbncsutil.so';
}else if(platform === 'darwin'){
libPath = '/libbncsutil.dylib';
}else{
throw new Error('unsupported plateform for mathlibLoc');
}

exports.libbncsutil = new FFI.Library(path.resolve(cwd + libPath), {
const bncsutil = new FFI.Library(resolveLibraryPath('bncsutil'), {
extractMPQNumber: [ref.types.int32, [
ref.types.CString,
]],
Expand Down Expand Up @@ -86,11 +52,6 @@ exports.libbncsutil = new FFI.Library(path.resolve(cwd + libPath), {
ref.types.ulong,
ref.types.CString,
]],
// bsha1_hash: [ref.types.void, [
// ref.types.CString,
// ref.types.uint32,
// ref.types.CString,
// ]],
doubleHashPassword: [ref.types.void, [
ref.types.CString,
ref.types.uint32,
Expand Down Expand Up @@ -232,3 +193,4 @@ exports.libbncsutil = new FFI.Library(path.resolve(cwd + libPath), {
]],
});

export { bncsutil }
2 changes: 1 addition & 1 deletion src/bnet/AuthInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from "assert";
import {ByteExtractString, ByteExtractUInt32, BytesExtract, ValidateLength} from "../Bytes";
import {BNCSUtil} from "../BNCSUtil";
import {BNCSUtil} from "../bncsutil/BNCSUtil";
import {createLoggerFor, hex} from '../Logger';
import {BNetConnection} from "./BNetConnection";

Expand Down
2 changes: 1 addition & 1 deletion src/bnet/AuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from "assert";
import {BNetConnection} from "./BNetConnection";
import {createLoggerFor, hex} from '../Logger';
import {BNetKR} from "./BNetKR";
import {BNCSUtil} from "../BNCSUtil";
import {BNCSUtil} from "../bncsutil/BNCSUtil";

const {debug, info, error} = createLoggerFor('AuthState');

Expand Down
2 changes: 1 addition & 1 deletion src/game/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {createLoggerFor} from '../Logger';
import {Config} from "../Config";
import {GHost} from "../GHost";
import {arch} from "os";
import {MPQ} from "../libStorm";
import {MPQ} from "../storm";

const {debug, info, error} = createLoggerFor('Map');

Expand Down
2 changes: 1 addition & 1 deletion src/ghost/bnet/GhostBNetSIDHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IBNetSIDHandler} from "../../bnet/IBNetSIDHandler";
import {BNetConnection} from "../../bnet/BNetConnection";
import {IBNetProtocol} from "../../bnet/IBNetProtocol";
import {createLoggerFor} from "../../Logger";
import {BNCSUtil} from '../../BNCSUtil';
import {BNCSUtil} from '../../bncsutil/BNCSUtil';
import {IBNetConnection} from "../../bnet/IBNetConnection";

const {debug, info, error} = createLoggerFor('BNet_SID_Handler');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 3 additions & 25 deletions src/libStorm/storm-lib.ts → src/storm/storm-lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs');
import {resolveLibraryPath} from "../util";

const ffi = require('ffi-napi');
const ref = require('ref-napi');
const Struct = require('ref-struct-napi');
const path = require('path');

const { bool, int32, uint32 } = ref.types;
const string = ref.types.CString;
Expand Down Expand Up @@ -39,29 +39,7 @@ const HANDLEPtr = ref.refType(HANDLE);

const LPDWORD = voidPtr;

const platform = process.platform;
const cwd = process.cwd();
let libPath = null;

if (platform === 'win32'){
libPath = '/storm.dll';
}else if(platform === 'linux'){
libPath = '/libstorm.so';
}else if(platform === 'darwin'){
libPath = '/libstorm.dylib';
}else{
throw new Error('unsupported plateform for mathlibLoc');
}

let libName = path.resolve(cwd + libPath);

if (!fs.existsSync(libName)) {
console.error(libName + ' not found, fallback to libstorm');

libName = 'libstorm';
}

const StormLib = new ffi.Library(libName, {
const StormLib = new ffi.Library(resolveLibraryPath('storm'), {
SFileGetLocale: [uint32, []],

SFileSetLocale: [uint32, [
Expand Down
28 changes: 28 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';

const startTime = Date.now();

Expand Down Expand Up @@ -52,3 +54,29 @@ export function ipToBuffer(ip:string) {
export function isNameValid(name) {
return name.length && name.length <= 15
}

export function resolveLibraryPath(name: string) {
const platform = process.platform;
const cwd = process.cwd();
let libPath = null;

if (platform === 'win32') {
libPath = `${name}.dll`;
} else if (platform === 'linux') {
libPath = `lib${name}.so`;
} else if (platform === 'darwin') {
libPath = `lib${name}.dylib`;
} else {
throw new Error(`unsupported plateform for ${name}`);
}

let libName = path.resolve(cwd, libPath);

if (!fs.existsSync(libName)) {
console.error(`${libName} not found, fallback to libstorm`);

return `lib${name}`;
}

return libName;
}

0 comments on commit a14616e

Please sign in to comment.