diff options
-rw-r--r-- | featureClass/featureManager.js | 103 | ||||
-rw-r--r-- | features/cosmetics/index.js | 9 | ||||
-rw-r--r-- | features/dungeonSolvers/index.js | 13 | ||||
-rw-r--r-- | features/globalSettings/index.js | 3 | ||||
-rw-r--r-- | features/streamsGUI/index.js | 2 | ||||
-rw-r--r-- | metadata.json | 4 | ||||
-rw-r--r-- | socketConnection.js | 52 |
7 files changed, 174 insertions, 12 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index af539c4..8937043 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -1,8 +1,10 @@ /// <reference types="../../CTAutocomplete" /> /// <reference lib="es2015" /> +const Instant = Java.type("java.time.Instant"); import logger from "../logger"; const File = Java.type("java.io.File") import metadata from "../metadata.js" +import soopyV2Server from "../socketConnection"; import { registerForge as registerForgeBase, unregisterForge as unregisterForgeBase} from "./forgeEvents.js" class FeatureManager { @@ -32,6 +34,11 @@ class FeatureManager { this.featureSettingsDataLastUpdated = false + //PERFORMANCE RECORDING + this.recordingPerformanceUsage = false + this.performanceUsage = {} //{moduleName: {event: {time: 0, count: 0}}} + + this.featureMetas = {} this.featureSettingsData = {} @@ -77,6 +84,48 @@ class FeatureManager { this.loadFeature(args) }).start() }, this) + this.registerCommand("soopylaginformation", (args)=>{ + new Thread(()=>{ + this.recordingPerformanceUsage = true + this.performanceUsage = {} + ChatLib.chat(this.messagePrefix + "Recording performance impact, this will take 10 seconds to complete!") + + Thread.sleep(10000) + + let totalMsGlobal = 0 + this.recordingPerformanceUsage = false + ChatLib.chat(this.messagePrefix + "Performance impact:") + Object.keys(this.performanceUsage).sort((a, b)=>{ + let totalMsA = 0 + Object.keys(this.performanceUsage[a]).forEach((event)=>{ + totalMsA += this.performanceUsage[a][event].time + }) + let totalMsB = 0 + Object.keys(this.performanceUsage[b]).forEach((event)=>{ + totalMsB += this.performanceUsage[b][event].time + }) + + return totalMsA-totalMsB + }).forEach((moduleName)=>{ + let totalMs = 0 + let totalCalls = 0 + Object.keys(this.performanceUsage[moduleName]).forEach((event)=>{ + totalMs += this.performanceUsage[moduleName][event].time + totalCalls += this.performanceUsage[moduleName][event].count + }) + + totalMsGlobal += totalMs + + ChatLib.chat("&eModule: &7" + moduleName) + ChatLib.chat("&eTotal: &7" + totalMs.toFixed(2) + "ms (" + totalCalls + " calls)") + Object.keys(this.performanceUsage[moduleName]).sort((a, b)=>{return this.performanceUsage[moduleName][a].time-this.performanceUsage[moduleName][b].time}).forEach((event)=>{ + ChatLib.chat(" &eEvent:&7 " + event + " - " + this.performanceUsage[moduleName][event].time.toFixed(2) + "ms (" + this.performanceUsage[moduleName][event].count + " calls)") + }) + }) + + ChatLib.chat("&eTotal: &7" + totalMsGlobal.toFixed(2) + "ms") + }).start() + }, this) } loadFeatureSettings(){ @@ -160,20 +209,31 @@ class FeatureManager { if(this.events[event]) try{ for(Event of Object.values(this.events[event])){ - if(Event.context.enabled) Event.func.call(Event.context, ...args) + if(Event.context.enabled){ + this.startRecordingPerformance(Event.context.constructor.name, event) + Event.func.call(Event.context, ...args) + this.stopRecordingPerformance(Event.context.constructor.name, event) + } } }catch(e){ logger.logMessage("Error in " + event + " event: " + JSON.stringify(e, undefined, 2), 2) + + soopyV2Server.reportError(e, "Error in " + event + " event.") } } triggerSoopy(event, args){ if(this.soopyEventHandlers[event]) try{ for(Event of Object.values(this.soopyEventHandlers[event])){ - if(Event.context.enabled) Event.func.call(Event.context, ...args) + if(Event.context.enabled){ + this.startRecordingPerformance(Event.context.constructor.name, event) + Event.func.call(Event.context, ...args) + this.stopRecordingPerformance(Event.context.constructor.name, event) + } } }catch(e){ logger.logMessage("Error in soopy " + event + " event: " + JSON.stringify(e, undefined, 2), 2) + soopyV2Server.reportError(e, "Error in soopy " + event + " event.") } } @@ -258,9 +318,15 @@ class FeatureManager { context: context, trigger: register(type, (...args)=>{ try{ - if(context.enabled) func.call(context, ...(args || [])) + if(context.enabled){ + this.startRecordingPerformance(context.constructor.name, type) + func.call(context, ...(args || [])) + this.stopRecordingPerformance(context.constructor.name, type) + } }catch(e){ logger.logMessage("Error in " + type + " event: " + JSON.stringify(e, undefined, 2), 2) + + soopyV2Server.reportError(e, "Error in " + type + " event.") } }), id: id @@ -277,9 +343,15 @@ class FeatureManager { context: context, trigger: registerForgeBase(event, (...args)=>{ try{ - if(context.enabled) func.call(context, ...args) + if(context.enabled){ + this.startRecordingPerformance(context.constructor.name, event.class.name) + func.call(context, ...(args || [])) + this.stopRecordingPerformance(context.constructor.name, event.class.name) + } }catch(e){ logger.logMessage("Error in " + event.class.toString() + " (forge) event: " + JSON.stringify(e, undefined, 2), 2) + + soopyV2Server.reportError(e, "Error in " + event.class.toString() + " (forge) event.") } }), id: id @@ -358,6 +430,8 @@ class FeatureManager { logger.logMessage("Error loading feature " + feature, 1) console.log(JSON.stringify(e, undefined, 2)) ChatLib.chat(this.messagePrefix + "Error loading feature " + feature) + + soopyV2Server.reportError(e, "Error loading feature " + feature) } return this @@ -398,6 +472,27 @@ class FeatureManager { } } } + + startRecordingPerformance(feature, event){ + if(!this.recordingPerformanceUsage) return + + if(!this.performanceUsage[feature]) this.performanceUsage[feature] = {} + if(!this.performanceUsage[feature][event]) this.performanceUsage[feature][event] = {time: 0,count: 0} + + let instant = Instant.now() + let time = (instant.getEpochSecond() + (instant.getNano() / 1000000000))*1000; + + this.performanceUsage[feature][event].startTime = time + } + stopRecordingPerformance(feature, event){ + if(!this.recordingPerformanceUsage) return + + let instant = Instant.now() + let time = (instant.getEpochSecond() + (instant.getNano() / 1000000000))*1000; + + this.performanceUsage[feature][event].time += time - this.performanceUsage[feature][event].startTime + this.performanceUsage[feature][event].count++ + } } const featureManager = new FeatureManager(); diff --git a/features/cosmetics/index.js b/features/cosmetics/index.js index b12526b..329a7f5 100644 --- a/features/cosmetics/index.js +++ b/features/cosmetics/index.js @@ -41,7 +41,8 @@ class Cosmetics extends Feature { this.registerStep(false, 60*10, ()=>{ new Thread(()=>{this.loadCosmeticsData.call(this)}).start() }) - this.registerEvent("renderEntity", this.renderEntity) + // this.registerEvent("renderEntity", this.renderEntity) + this.loadedRenderEntity = false } renderWorld(ticks){ @@ -64,6 +65,10 @@ class Cosmetics extends Feature { this.cosmeticsData = data this.playerHasACosmeticA = !!data[Player.getUUID().toString().replace(/-/g,"")] + if(this.playerHasACosmeticA && !this.loadedRenderEntity){ + this.registerEvent("renderEntity", this.renderEntity) + this.loadedRenderEntity = true + } this.scanForNewCosmetics() } @@ -126,7 +131,7 @@ class Cosmetics extends Feature { playerLeft(playerName){ this.loadedCosmetics.filter(cosmetic=>{ - if(cosmetic.player.getUUID().toString() === Player.getUUID().toString()) return + if(cosmetic.player.getUUID().toString() === Player.getUUID().toString()) return true if(cosmetic.player.getName() === playerName){ this.uuidToCosmetic[cosmetic.id][cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined diff --git a/features/dungeonSolvers/index.js b/features/dungeonSolvers/index.js index 0d9a825..bdeff6e 100644 --- a/features/dungeonSolvers/index.js +++ b/features/dungeonSolvers/index.js @@ -47,7 +47,8 @@ class DungeonSolvers extends Feature { this.registerEvent("renderOverlay", this.renderHud) this.registerEvent("renderWorld", this.renderWorld) - this.registerEvent("renderEntity", this.renderEntity) + // this.registerEvent("renderEntity", this.renderEntity) + this.renderEntityEvent = undefined } renderWorld(ticks){ @@ -135,6 +136,16 @@ class DungeonSolvers extends Feature { } }) } + + if(this.lividData.correctLividEntity){ + if(!this.renderEntityEvent){ + this.renderEntityEvent = this.registerEvent("renderEntity", this.renderEntity) + } + }else{ + if(this.renderEntityEvent){ + this.unregisterEvent(this.renderEntityEvent) + } + } } initVariables(){ diff --git a/features/globalSettings/index.js b/features/globalSettings/index.js index f7ae0b0..eb1e088 100644 --- a/features/globalSettings/index.js +++ b/features/globalSettings/index.js @@ -9,6 +9,7 @@ import GuiPage from "../soopyGui/GuiPage" import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement"; import Notification from "../../../guimanager/Notification"; import logger from "../../logger"; +import soopyV2Server from "../../socketConnection"; const Files = Java.type("java.nio.file.Files") const Paths = Java.type("java.nio.file.Paths") const JavaString = Java.type("java.lang.String") @@ -42,6 +43,8 @@ class Hud extends Feature { // this.GuiPage = new FirstLoadingPage(this) + soopyV2Server.reportErrorsSetting = this.reportErrorsSetting + this.registerChat("&aYour new API key is &r&b${key}&r", this.newKey) // new Thread(()=>{ diff --git a/features/streamsGUI/index.js b/features/streamsGUI/index.js index 2cd2a4f..aaf5ab7 100644 --- a/features/streamsGUI/index.js +++ b/features/streamsGUI/index.js @@ -122,7 +122,7 @@ class StreamElement extends SoopyBoxElement { this.titleElement.setText(stream.title) - this.channelElement.setText((twitch ? "§0"+stream.user_name : "§0"+stream.channelTitle) + (twitch?"&7 - " + stream.viewer_count + " viewers":"")) + this.channelElement.setText((twitch ? "§0"+stream.user_name : "§0"+stream.channelTitle) + (twitch?"&7 - " + stream.viewer_count + " viewer"+(stream.viewer_count!==1?"s":""):"")) this.channelImg.setImage(twitch ? `https://static-cdn.jtvnw.net/previews-ttv/live_user_${stream.user_login}-640x360.jpg` : stream.thumbnails.high.url) diff --git a/metadata.json b/metadata.json index 36b7b4f..7581c23 100644 --- a/metadata.json +++ b/metadata.json @@ -5,8 +5,8 @@ "entry": "index.js", "description": "Soopy addons v2", "name": "SoopyV2", - "version": "2.0.10", - "versionId": 120, + "version": "2.0.11", + "versionId": 121, "requires": [ "soopyApis", "soopyAddonsData", diff --git a/socketConnection.js b/socketConnection.js index 0c1225d..a7524a9 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -1,5 +1,7 @@ import WebsiteCommunicator from "./../soopyApis/websiteCommunicator" import socketData from "../soopyApis/socketData" +import logger from "./logger" +import metadata from "./metadata" const Cosmetics = require("./features/cosmetics/index.js") class SoopyV2Server extends WebsiteCommunicator { @@ -7,6 +9,10 @@ class SoopyV2Server extends WebsiteCommunicator { super(socketData.serverNameToId.soopyv2) this.spammedMessages = [] + + this.errorsToReport = [] + + this.reportErrorsSetting = undefined } onData(data){ @@ -18,13 +24,55 @@ class SoopyV2Server extends WebsiteCommunicator { } } + onConnect(){ + if(this.reportErrorsSetting && !this.reportErrorsSetting.getValue()) return + new Thread(() => { + while(!this.reportErrorsSetting){ + Thread.sleep(1000) + } + + if(!this.reportErrorsSetting.getValue()) return + + this.errorsToReport.forEach(data => { + this.sendData({ + type: "error", + data: data + }) + }) + this.errorsToReport = [] + }).start() + } + sendMessageToServer(message, lobbyId){ - this.sendData(this.sendData({ + this.sendData({ type: "chatMessage", message: message, lobbyId: lobbyId - })) + }) } + + reportError(error, description){ + if(this.reportErrorsSetting && !this.reportErrorsSetting.getValue()) return + let data = { + lineNumber: error.lineNumber, + fileName: error.fileName.replace(/file:.+?ChatTriggers/g, "file:"), //The replace is to not leak irl names thru windows acct name + message: error.message, + description: description, + stack: error.stack.replace(/file:.+?ChatTriggers/g, "file:"), + modVersion: metadata.version, + modVersionId: metadata.versionId, + } + + if(this.connected && this.reportErrorsSetting){ + this.sendData({ + type: "error", + data: data + }) + }else{ + this.errorsToReport.push(data) + } + } + } let soopyV2Server = new SoopyV2Server() |