Skip to content

Commit

Permalink
FPSLimited fully done (i hope), module setting descriptions + ui stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zastlx committed Apr 24, 2024
1 parent 8069628 commit 8f786bb
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 50 deletions.
4 changes: 4 additions & 0 deletions src/api/systemjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SystemJS } from "@cctypes/systemjs";

// @ts-ignore
export default (): SystemJS => window.System;
70 changes: 33 additions & 37 deletions src/gui/GUIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gui, catagories } from "./index";
import { IElement, createElement, createCssFromObjects } from "./helper";
import { Module } from "module/ModuleManager";
import * as styles from "./styles";
import { ModuleSettingBool } from "module/ModuleManager.types";
import { ModuleSettingBool, ModuleSettingNumber } from "module/ModuleManager.types";

interface IGUIManager {
registerModule(module: Module): void;
Expand All @@ -27,7 +27,7 @@ class GUIManager implements IGUIManager {

constructor() {
console.log("Initlizing GUIManager");
const guiStyle = createElement("style", { style: { display: "none" }, id: "elficia-styles-settings" })
createElement("style", { style: { display: "none" }, id: "elficia-styles-settings" })
.setInnerHtml(createCssFromObjects(styles.sliderSettingStyles))
.appendTo(document.head);

Expand Down Expand Up @@ -137,6 +137,16 @@ class GUIManager implements IGUIManager {
setting.currentValue = !setting.currentValue;
module.onSettingsUpdate(name);
settingEnabledIndicator.setStyle("display", setting.currentValue ? "block" : "none");
})
.onHover((hovering) => {
if (hovering) {
this.moduleDescription.setText(setting.description);
this.moduleDescription.setStyle("display", "flex");
}
else {
this.moduleDescription.setText("");
this.moduleDescription.setStyle("display", "none");
}
});
const settingTitle = createElement("span", { style: { color: "white", fontSize: "1vw" } })
.setText(name);
Expand All @@ -148,48 +158,31 @@ class GUIManager implements IGUIManager {
moduleSettingsElements.push(settingElement);
break;
}
case "number": {
/*dragging = false
hovering = false
clicked = false
temp1.onmouseover = () => {
hovering = true
dragging = clicked && hovering;
}
temp1.onmouseout = () => {
hovering = false
dragging = clicked && hovering;
}
temp1.onmousedown = () => {
clicked = true;
dragging = clicked && hovering;
}
temp1.onmousemove = (event) => {
if (!dragging) return;
const divRect = temp1.getBoundingClientRect();
const mouseX = event.clientX;
const mouseY = event.clientY;
const offset = mouseX - divRect.left;
const percentageX = (offset / divRect.width) * 100;
if (mouseX >= divRect.left && mouseX <= divRect.right && mouseY >= divRect.top && mouseY <= divRect.bottom) console.log(Math.round(percentageX));
}
document.onmouseup = () => {
clicked = false;
dragging = clicked && hovering;
}*/
case "number": {
let state = {
dragging: false,
hovering: false,
clicked: false
}
const settingElement = createElement("div", { style: styles.boolModuleSetting })
.appendTo(moduleSettingsContainer.element);
.appendTo(moduleSettingsContainer.element)
.onHover((hovering) => {
if (hovering) {
this.moduleDescription.setText(setting.description);
this.moduleDescription.setStyle("display", "flex");
}
else {
this.moduleDescription.setText("");
this.moduleDescription.setStyle("display", "none");
}
});
const settingTitle = createElement("span", { style: { color: "white", fontSize: "1vw" } })
.setText(name);

const settingInner = createElement("div", { style: styles.numberModuleSettingInnerContainer });
const settingValueDisplayContainer = createElement("div", { style: styles.numberModuleSettingValueDisplayContainer });
const settingValueDisplay = createElement("span", {})
.setText((setting as ModuleSettingNumber).currentValue.toString());
const settingInner = createElement("div", { style: styles.numberModuleSettingInnerContainer })
.setStyle("width", `${(setting as ModuleSettingNumber).currentValue/((setting as ModuleSettingNumber).max/100)}%`);
const settingOuter = createElement("div", { style: styles.numberModuleSettingOuterContainer })
.onHover((hovering) => {
state.hovering = hovering;
Expand All @@ -211,8 +204,9 @@ document.onmouseup = () => {
const offset = mouseX - divRect.left;
const percentageX = (offset / divRect.width) * 100;
if (mouseX >= divRect.left && mouseX <= divRect.right && mouseY >= divRect.top && mouseY <= divRect.bottom) {
setting.currentValue = Math.round(percentageX);
setting.currentValue = Math.round((setting as ModuleSettingNumber).max * (percentageX/100));
module.onSettingsUpdate(name);
settingValueDisplay.setText((setting as ModuleSettingNumber).currentValue.toString());
settingInner.setStyle("width", `${percentageX}%`);
}
});
Expand All @@ -222,6 +216,8 @@ document.onmouseup = () => {
state.dragging = state.clicked && state.hovering;
});
settingTitle.appendTo(settingElement.element);
settingValueDisplay.appendTo(settingValueDisplayContainer.element);
settingValueDisplayContainer.appendTo(settingOuter.element);
settingOuter.appendTo(settingElement.element);
settingInner.appendTo(settingOuter.element);
moduleSettingsElements.push(settingElement);
Expand Down
22 changes: 20 additions & 2 deletions src/gui/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,28 @@ const sliderSettingStyles = [
}
},
];
/*
<div style="
display: flex;
position: absolute;
align-items: center;
color: black;
width: 80%;
justify-content: center;
"><span style="
">100</span></div>
*/
const numberModuleSettingValueDisplayContainer = {
display: "flex",
position: "absolute",
alignItems: "center",
color: "black",
width: "80%",
justifyContent: "center",
};



export { numberModuleSettingOuterContainer, numberModuleSettingInnerContainer, boolSettingIndicator, boolModuleSetting, sliderModuleSetting, sliderModuleSettingSliderContainer, sliderModuleSettingSliderInput, sliderSettingStyles, moduleDescription, module, moduleContainer, moduleNameContainer, moduleSettingsContainer, catagory, gui, catagoryTitle, catagoryTitleText, catagoryTitleLine, guiIn, slideInFromUp, slideOutToUp };
export { numberModuleSettingValueDisplayContainer, numberModuleSettingOuterContainer, numberModuleSettingInnerContainer, boolSettingIndicator, boolModuleSetting, sliderModuleSetting, sliderModuleSettingSliderContainer, sliderModuleSettingSliderInput, sliderSettingStyles, moduleDescription, module, moduleContainer, moduleNameContainer, moduleSettingsContainer, catagory, gui, catagoryTitle, catagoryTitleText, catagoryTitleLine, guiIn, slideInFromUp, slideOutToUp };

/*
.gui {
Expand Down
67 changes: 60 additions & 7 deletions src/module/modules/misc/FPSUnlocker.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,80 @@
import { IModuleSetting } from "module/ModuleManager.types";

import { Module } from "../../ModuleManager";
import { getGameManager } from "@api/Game";
import cocos from "@api/cocos";
import { ModuleSettingBool, ModuleSettingNumber } from "module/ModuleManager.types";
import { after } from "spitroast";
import { unpatch } from "spitroast/dist/types/unpatch";

enum GameState {
Init = 0,
GameplayModeSelect = 1,
CourseSelect = 2,
Play = 3,
WaitToCompleteHole = 4,
TournamentSelect = 5,
TournamentWait = 6,
TournamentOver = 7
}

class FPSUnlockedModule extends Module {
constructor() {
super("FPSUnlocker", "A way to unlock or limit your FPS", "Misc")
this.registerNumberSetting("Focused FPS", "Set your FPS when the game is focused", 60, 0, 1000);
this.registerNumberSetting("Unfocused FPS", "Set your FPS when the game is unfocused", 25, 0, 1000);
this.registerBoolSetting("Infinite FPS", "Unlock your FPS", false);
this.registerNumberSetting("FPS", "Set your default maximum game FPS", 60, 0, 500);
this.registerNumberSetting("Menu FPS", "Set your FPS when the game is in ANY menu (e.g Map Voting, Game Mode Selection, etc...), this is chosen over FPS", 25, 0, 500);
this.registerBoolSetting("Infinite FPS", "Unlock your FPS fully, ignores all other values", false);
}
// @ts-ignore it gets angy
currentGameState: number = getGameManager().getChildByName("GolfMode")!.getComponent("GolfMode")!.gameState ?? -1;
unpatch: (() => boolean) | undefined;

updateFPS(): void {
// incase i fail cleanup
if (!this.isEnabled()) return;

// i dont reasonably see anyones computer being able to handle above this \_(;-;)_/
if ((this.getSettings().get("Infinite FPS") as ModuleSettingBool).currentValue) return cocos().game.setFrameRate(99999);
if (!document.hasFocus()) return cocos().game.setFrameRate((this.getSettings().get("Unfocused FPS") as ModuleSettingNumber)?.currentValue);

switch (this.currentGameState) {
case GameState.Init:
case GameState.GameplayModeSelect:
case GameState.CourseSelect:
case GameState.TournamentSelect:
case GameState.TournamentWait:
case GameState.TournamentOver:
cocos().game.setFrameRate((this.getSettings().get("Menu FPS") as ModuleSettingNumber)?.currentValue);
break;
case GameState.WaitToCompleteHole:
case GameState.Play:
cocos().game.setFrameRate((this.getSettings().get("FPS") as ModuleSettingNumber)?.currentValue);
break;
default:
console.warn("Unknown game state, setting to focused FPS")
cocos().game.setFrameRate((this.getSettings().get("FPS") as ModuleSettingNumber)?.currentValue);
break;
}
}

getDisplayName(): string {
return "FPSUnlocker";
return `FPS Unlocker | ${this.getSettings().get("Infinite FPS")?.currentValue ? "Infinite" : this.getSettings().get("FPS")?.currentValue} FPS`
}

onEnable(): void {
console.log(this.getSettings().get("Infinite FPS")?.currentValue);
this.updateFPS();
this.unpatch = after("SendCurrentState", getGameManager().getChildByName("GolfMode")!.getComponent("GolfMode"), (args) => {
this.currentGameState = args[0];
this.updateFPS();
});
}

onDisable(): void {
console.log(this.getSettings().get("Infinite FPS")?.currentValue);
cocos().game.setFrameRate(60);
if (this.unpatch) this.unpatch();
}

onSettingsUpdate(setting: string): void {
this.updateFPS();
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/patcher/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { before, instead, after, unpatchAll } from "spitroast";
// @ts-ignore
window.spitroast = { before, instead, after, unpatchAll };
// instead("fetch", window, (args, oFunc) => {
// if (args[0].includes("log")) return;
// else return oFunc(args);
// });

export { before, instead, after, unpatchAll };
110 changes: 110 additions & 0 deletions src/types/systemjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
interface SystemJS {
/**
* Loads a javascript module from either a url or bare specifier that is in an import map.
* You may optionally provide a parentUrl that will be used for resolving relative urls.
*/
import: System.ImportFn;

/**
* Inserts a new module into the SystemJS module registry. The System.register format is
* the underlying implementation that allows for ESM emulation.
* See https://github.com/systemjs/systemjs/blob/master/docs/system-register.md for more details.
* Register may be called with a name argument if you are using the named-register extra. (See
* https://github.com/systemjs/systemjs#extras).
*/
register(dependencies: string[], declare: System.DeclareFn): void;
register(name: string, dependencies: string[], declare: System.DeclareFn): void;

/**
* Resolve any moduleId to its full URL. For a moduleId that is in the import map, this will resolve
* the full import map URL. For a moduleId that is a relative url, the returned url will be resolved
* relative to the parentUrl or the current browser page's base url. For a full url, resolve() is
* a no-op.
*/
resolve(moduleId: string, parentUrl?: string): string;

/**
* Delete a module from the module registry. Note that the moduleId almost always must be a full url and that
* you might need to call System.resolve() to obtain the moduleId for modules in an import map.
* The returned function is intended for use after re-importing the module. Calling the function
* will re-bind all the exports of the re-imported module to every module that depends on the module.
*/
delete(moduleId: string): false | System.UpdateModuleFn;

/**
* Get a module from the SystemJS module registry. Note that the moduleId almost always must be a full url
* and that you might need to call System.resolve() to obtain the moduleId. If the module does not exist in
* the registry, null is returned.
*/
get(moduleId: string): System.Module | null;
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
get<T>(moduleId: string): T | null;

/**
* Indicates whether the SystemJS module registry contains a module. Note that the moduleId almost always
* must be a full url and that you might need to call System.resolve() to obtain the moduleId.
*/
has(moduleId: string): boolean;

/**
* An alternative to System.register(), this allows you to insert a module into the module registry. Note that
* the moduleId you provide will go straight into the registry without being resolved first.
*/
set(moduleId: string, module: System.Module): void;

/**
* Use for (let entry of System.entries()) to access all of the modules in the SystemJS registry.
*/
entries(): Iterable<[string, System.Module]>;

/**
* Dynamically extend additional mappings into the import map at any time.
* Any existing map entries will be overridden with the new values.
*/
addImportMap(importMap: System.ImportMap): void;
};

declare namespace System {
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
type ImportFn = <T extends Module>(moduleId: string, parentUrl?: string) => Promise<T>;

type DeclareFn = (_export: ExportFn, _context: Context) => Declare;
interface Declare {
setters?: SetterFn[] | undefined;
execute?(): any;
}
type SetterFn = (moduleValue: Module) => any;
type ExecuteFn = () => any;

interface ExportFn {
(exportName: string, value: any): void;
(exports: object): void;
}

type UpdateModuleFn = () => void;

type GetFn = GetFnModule | GetFnGeneric;
type GetFnModule = (moduleId: string) => Module;
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
type GetFnGeneric = <T>(moduleId: string) => T;

interface Context {
import: ImportFn;
meta: {
url: string;
};
}

interface Module {
default?: any;
[exportName: string]: any;
}

/** The importmap standard is defined here: https://github.com/WICG/import-maps */
interface ImportMap {
imports?: Record<string, string>;
scopes?: Record<string, Record<string, string>>;
}
}

export { SystemJS };

0 comments on commit 8f786bb

Please sign in to comment.