bc-deeplib 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,72 +0,0 @@
1
- import { Input } from 'Types/elements';
2
- import { BaseSubscreen, elementSetTooltip, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
3
-
4
- export function elementCreateInput(options: Input) {
5
- const elem = document.getElementById(options.id);
6
-
7
- if (elem) return elem;
8
-
9
- const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
10
- const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
11
- const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
12
- const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
13
- const position = options.position ? 'fixed' : '';
14
-
15
- const retElem = ElementCreate({
16
- tag: 'div',
17
- classList: ['deeplib-input-container'],
18
- style: {
19
- width: width,
20
- height: height,
21
- left: left,
22
- top: top,
23
- position: position,
24
- },
25
- dataAttributes: {
26
- 'size': options.size?.join('x'),
27
- 'position': options.position?.join('x'),
28
- },
29
- children: [
30
- {
31
- tag: 'input',
32
- classList: ['deeplib-input'],
33
- attributes: {
34
- type: options.type,
35
- id: options.id,
36
- placeholder: ' ',
37
- },
38
- },
39
- {
40
- tag: 'label',
41
- classList: ['deeplib-text'],
42
- attributes: {
43
- for: options.id,
44
- },
45
- children: [options.label]
46
- },
47
- {
48
- tag: 'div',
49
- classList: ['deeplib-underline'],
50
- }
51
- ]
52
- });
53
-
54
- if (options.getElementValue?.()) {
55
- const input = document.getElementById(options.id) as HTMLInputElement;
56
- if (input) input.value = options.getElementValue();
57
- }
58
-
59
- if (options.description) {
60
- retElem.addEventListener('mouseover', () => {
61
- elementSetTooltip(options.description);
62
- });
63
-
64
- retElem.addEventListener('mouseout', () => {
65
- elementSetTooltip('');
66
- });
67
- }
68
-
69
- BaseSubscreen.currentElements.push([retElem, options]);
70
-
71
- return retElem;
72
- }
@@ -1,50 +0,0 @@
1
- import { Label } from 'Types/elements';
2
- import { BaseSubscreen, elementSetTooltip, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
3
-
4
- export function elementCreateLabel(options: Label) {
5
- const elem = document.getElementById(options.id);
6
-
7
- if (elem) return elem;
8
-
9
- const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
10
- const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
11
- const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
12
- const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
13
- const position = options.position ? 'fixed' : '';
14
-
15
- const retElem = ElementCreate({
16
- tag: 'span',
17
- classList: ['deeplib-label', 'deeplib-text'],
18
- attributes: {
19
- id: options.id
20
- },
21
- style: {
22
- width: width,
23
- height: height,
24
- left: left,
25
- top: top,
26
- position: position,
27
- },
28
- dataAttributes: {
29
- 'size': options.size?.join('x'),
30
- 'position': options.position?.join('x'),
31
- },
32
- children: [
33
- options.label,
34
- ],
35
- });
36
-
37
- if (options.description) {
38
- retElem.addEventListener('mouseover', () => {
39
- elementSetTooltip(options.description as string);
40
- });
41
-
42
- retElem.addEventListener('mouseout', () => {
43
- elementSetTooltip('');
44
- });
45
- }
46
-
47
- BaseSubscreen.currentElements.push([retElem, options]);
48
-
49
- return retElem;
50
- }
@@ -1,30 +0,0 @@
1
- export function elementCreateTooltip() {
2
- const element = ElementCreate({
3
- tag: 'div',
4
- classList: ['deeplib-tooltip'],
5
- attributes: {
6
- id: 'deeplib-tooltip'
7
- },
8
- style: {
9
- display: 'none'
10
- }
11
- });
12
-
13
- return element;
14
- }
15
-
16
- export function elementGetTooltip() {
17
- return document.getElementById('deeplib-tooltip') ?? undefined;
18
- }
19
-
20
- export function elementSetTooltip(text: string) {
21
- const element = document.getElementById('deeplib-tooltip');
22
-
23
- if (!element) return false;
24
-
25
- element.innerHTML = text;
26
- if (text === '') element.style.display = 'none';
27
- else element.style.display = '';
28
-
29
- return true;
30
- }
@@ -1,79 +0,0 @@
1
- type LogLevel = 'info' | 'log' | 'warn' | 'error' | 'debug';
2
-
3
- interface LogEntry {
4
- readonly args: readonly any[];
5
- readonly date: Date;
6
- readonly logLevel: LogLevel;
7
- }
8
-
9
- export class Logger extends Array<LogEntry> {
10
- private ModName: string = 'DeepLib';
11
-
12
- constructor(modName?: string) {
13
- super();
14
-
15
- if (modName) {
16
- this.ModName = modName;
17
- }
18
- }
19
-
20
- private _Log(level: LogLevel, ...args: any[]): void {
21
- const logEntry: LogEntry = {
22
- logLevel: level,
23
- args: [...args],
24
- // trace: arguments.callee.caller.toString().split('\n'),
25
- date: new Date(Date.now())
26
- // `[${this.ModName}] ${formattedArgs}`
27
- };
28
-
29
- const userAgent = navigator.userAgent.toLowerCase();
30
- if (userAgent.includes('chrome') || userAgent.includes('firefox')) {
31
- const color = Logger.colorizeLog(level);
32
- args.forEach(arg => {
33
- if (typeof arg === 'string') {
34
- arg = `\n%c${arg}`;
35
- // args.splice(args.indexOf(arg), 1, arg, color);
36
- }
37
- });
38
- console.log(`%c${this.ModName}:`, color, ...args);
39
- } else {
40
- console.log(`${this.ModName}:`, ...args);
41
- }
42
-
43
- this.push(logEntry);
44
- }
45
-
46
- info(...args: any[]): void {
47
- this._Log('info', ...args);
48
- }
49
-
50
- log(...args: any[]): void {
51
- this._Log('log', ...args);
52
- }
53
-
54
- warn(...args: any[]): void {
55
- this._Log('warn', ...args);
56
- }
57
-
58
- error(...args: any[]): void {
59
- this._Log('error', ...args);
60
- }
61
-
62
- debug(...args: any[]): void {
63
- this._Log('debug', ...args);
64
- }
65
-
66
- static colorizeLog(logLevel: LogLevel): string {
67
- const colors: Record<LogLevel, string> = {
68
- info: 'color: #32CCCC',
69
- log: 'color: #CCCC32',
70
- warn: 'color: #eec355',
71
- error: 'color: #750b0b',
72
- debug: 'color: #9E4BCF',
73
- };
74
-
75
- return colors[logLevel];
76
- }
77
- }
78
-
79
- export const deepLibLogger = new Logger();
@@ -1,36 +0,0 @@
1
- export function sendLocalMessage(id: string, message: string, timeoutInSeconds?: number) {
2
- const div = document.createElement('div');
3
- div.id = id;
4
- const specialId = id + Date.now();
5
- div.classList.add('ChatMessage', 'deeplib-message', specialId);
6
- div.setAttribute('data-time', ChatRoomCurrentTime());
7
- div.setAttribute('data-sender', Player?.MemberNumber + '');
8
-
9
- const messageContent = message.replaceAll('\n\t', '') + '<br>';
10
- const closeButton = document.createElement('a');
11
- closeButton.classList.add('deeplib-text');
12
- closeButton.addEventListener('click', () => {
13
- div?.remove();
14
- });
15
- closeButton.innerHTML = '<b>Close (Click)</b>';
16
-
17
- div.innerHTML = messageContent;
18
- div.append(closeButton);
19
-
20
- ChatRoomAppendChat(div);
21
- if (!timeoutInSeconds) return;
22
- setTimeout(() => div?.remove(), timeoutInSeconds * 1000);
23
- }
24
-
25
- export function sendActionMessage(msg: string, target: undefined | number = undefined, dictionary: ChatMessageDictionaryEntry[] = []) {
26
- if (!msg) return;
27
- ServerSend('ChatRoomChat', {
28
- Content: 'DEEPLIB_CUSTOM_ACTION',
29
- Type: 'Action',
30
- Target: target ?? undefined,
31
- Dictionary: [
32
- { Tag: 'MISSING TEXT IN "Interface.csv": DEEPLIB_CUSTOM_ACTION', Text: msg },
33
- ...dictionary,
34
- ],
35
- });
36
- }
@@ -1,104 +0,0 @@
1
- import bcModSdkRef, { ModSDKModAPI, ModSDKModInfo, ModSDKModOptions } from 'bondage-club-mod-sdk';
2
-
3
- export enum HookPriority {
4
- Observe = 0,
5
- AddBehavior = 1,
6
- ModifyBehavior = 5,
7
- OverrideBehavior = 10,
8
- Top = 100
9
- }
10
-
11
- export type ModuleCategory = number;
12
-
13
- export declare type AnyFunction = (...args: any) => any;
14
- type PatchHook<TFunction extends AnyFunction = AnyFunction> = (args: [...Parameters<TFunction>], next: (args: [...Parameters<TFunction>]) => ReturnType<TFunction>) => ReturnType<TFunction>;
15
-
16
- interface IPatchedFunctionData {
17
- name: string;
18
- hooks: {
19
- hook: PatchHook;
20
- priority: number;
21
- module: ModuleCategory | null;
22
- removeCallback: () => void;
23
- }[];
24
- }
25
-
26
- type GetDotedPathType<Base, DotedKey extends string> = DotedKey extends `${infer Key1}.${infer Key2}` ? GetDotedPathType<GetDotedPathType<Base, Key1>, Key2> : DotedKey extends keyof Base ? Base[DotedKey] : never;
27
-
28
- export class bcSdkMod {
29
- private static SDK: ModSDKModAPI;
30
- private static patchedFunctions: Map<string, IPatchedFunctionData> = new Map();
31
-
32
- public static ModInfo: ModSDKModInfo;
33
-
34
- constructor(info: ModSDKModInfo, options?: ModSDKModOptions) {
35
- bcSdkMod.SDK = bcModSdkRef.registerMod(info, options);
36
- bcSdkMod.ModInfo = info;
37
- }
38
-
39
- initPatchableFunction(target: string): IPatchedFunctionData {
40
- let result = bcSdkMod.patchedFunctions.get(target);
41
- if (!result) {
42
- result = {
43
- name: target,
44
- hooks: []
45
- };
46
- bcSdkMod.patchedFunctions.set(target, result);
47
- }
48
- return result;
49
- }
50
-
51
- hookFunction<TargetName extends string>(
52
- target: TargetName,
53
- priority: number,
54
- hook: PatchHook<GetDotedPathType<typeof globalThis, TargetName>>,
55
- module: ModuleCategory | null = null
56
- ): () => void {
57
- const data = this.initPatchableFunction(target);
58
-
59
- if (data.hooks.some((h) => h.hook === hook)) {
60
- return () => null;
61
- }
62
-
63
- const removeCallback = bcSdkMod.SDK?.hookFunction(target, priority, hook);
64
-
65
- data.hooks.push({
66
- hook,
67
- priority,
68
- module,
69
- removeCallback
70
- });
71
- data.hooks.sort((a, b) => b.priority - a.priority);
72
- return removeCallback;
73
- }
74
-
75
- patchFunction(target: string, patches: Record<string, string>): void {
76
- this.patchFunction(target, patches);
77
- }
78
-
79
- removeHookByModule(target: string, module: ModuleCategory): boolean {
80
- const data = this.initPatchableFunction(target);
81
-
82
- for (let i = data.hooks.length - 1; i >= 0; i--) {
83
- if (data.hooks[i].module === module) {
84
- data.hooks[i].removeCallback();
85
- data.hooks.splice(i, 1);
86
- }
87
- }
88
-
89
- return true;
90
- }
91
-
92
- removeAllHooksByModule(module: ModuleCategory): boolean {
93
- for (const data of bcSdkMod.patchedFunctions.values()) {
94
- for (let i = data.hooks.length - 1; i >= 0; i--) {
95
- if (data.hooks[i].module === module) {
96
- data.hooks[i].removeCallback();
97
- data.hooks.splice(i, 1);
98
- }
99
- }
100
- }
101
-
102
- return true;
103
- }
104
- }
@@ -1,31 +0,0 @@
1
- import { deepLibLogger } from './Logger';
2
-
3
- export class _String {
4
- static encode(string: string | object) {
5
- return LZString.compressToBase64(JSON.stringify(string));
6
- }
7
-
8
- static decode(string: string | undefined) {
9
- const d = LZString.decompressFromBase64(string as string);
10
- let data = {};
11
-
12
- try {
13
- const decoded = JSON.parse(d as string);
14
- data = decoded;
15
- } catch (error) {
16
- deepLibLogger.error(error);
17
- }
18
- if (data) return data;
19
- }
20
-
21
- static shuffle(string: string[]) {
22
- const temp: string[] = JSON.parse(JSON.stringify(string));
23
- const ret: string[] = [];
24
- while (temp.length > 0) {
25
- const d = Math.floor(Math.random() * temp.length);
26
- ret.push(temp[d]);
27
- temp.splice(d, 1);
28
- }
29
- return ret;
30
- }
31
- }
@@ -1,24 +0,0 @@
1
- export class Style {
2
- static inject(id: string, styleSource: string) {
3
- const isStyleLoaded = !!document.getElementById(id);
4
-
5
- if (isStyleLoaded) return;
6
-
7
- const styleElement = document.createElement('style');
8
- styleElement.id = id;
9
- styleElement.appendChild(document.createTextNode(styleSource));
10
- document.head.appendChild(styleElement);
11
- }
12
-
13
- static eject(id: string) {
14
- const style = document.getElementById(id);
15
- if (!style) return;
16
-
17
- style.remove();
18
- }
19
-
20
- static reload(id: string, styleSource: string) {
21
- Style.eject(id);
22
- Style.inject(id, styleSource);
23
- }
24
- }
@@ -1,59 +0,0 @@
1
- type TranslationDict = {
2
- [key: string]: string;
3
- };
4
-
5
- export class Localization {
6
- private Translation: TranslationDict = {};
7
- private static PathToTranslation: string;
8
-
9
- constructor(options: {
10
- pathToTranslationsFolder: string;
11
- }) {
12
- Localization.PathToTranslation = options.pathToTranslationsFolder.endsWith('/') ? options.pathToTranslationsFolder : options.pathToTranslationsFolder + '/';
13
- }
14
-
15
- static async init() {
16
- const lang = TranslationLanguage.toLowerCase();
17
- const translation = await Localization.fetchLanguageFile(lang);
18
-
19
- if (lang === 'en') {
20
- Localization.prototype.Translation = translation;
21
- } else {
22
- const fallbackTranslation = await Localization.fetchLanguageFile('en');
23
- Localization.prototype.Translation = { ...fallbackTranslation, ...translation };
24
- }
25
- }
26
-
27
- static getText(srcTag: string) {
28
- return Localization.prototype.Translation?.[srcTag] || srcTag || '';
29
- }
30
-
31
- private static async fetchLanguageFile(lang: string): Promise<TranslationDict> {
32
- const response = await fetch(`${Localization.PathToTranslation}${lang}.lang`);
33
-
34
- if (lang !== 'en' && !response.ok) {
35
- return this.fetchLanguageFile('en');
36
- }
37
- const langFileContent = await response.text();
38
-
39
- return this.parseLanguageFile(langFileContent);
40
- }
41
-
42
- private static parseLanguageFile(content: string): TranslationDict {
43
- const translations: TranslationDict = {};
44
- const lines = content.split('\n');
45
-
46
- for (const line of lines) {
47
- if (line.trim() === '' || line.trim().startsWith('#')) {
48
- continue;
49
- }
50
-
51
- const [key, value] = line.split('=');
52
- translations[key.trim()] = value.trim();
53
- }
54
-
55
- return translations;
56
- }
57
- }
58
-
59
- export const getText = (string: string): string => Localization.getText(string);