-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatch.js
More file actions
145 lines (126 loc) · 4.92 KB
/
patch.js
File metadata and controls
145 lines (126 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const fs = require("fs")
const path = require("path")
function patch_fmod_fmod() {
console.log("Patching java/fmod_fmod.d.ts ...")
try {
const file = path.join(__dirname, "java/fmod_fmod.d.ts")
let content = fs.readFileSync(file, 'utf-8')
content = content.replaceAll(": fmod.fmod", ": fmod")
content = content.replaceAll("<fmod.fmod", "<fmod")
fs.writeFileSync(file, content)
}
catch(error) {
console.error(error)
}
}
function patch_pipewrench_content(content) {
content = content.replace(`// [server/recipecode.d.ts]`, ``)
content = content.replace(`export abstract class Recipe extends lua.server.Recipe {}`, ``)
content = content.replace(`export abstract class scavenges extends lua.shared.Foraging.scavenges {}`, ``)
content = content.replace(`export abstract class ThermoDebug extends lua.client.DebugUIs.DebugMenu.Climate.ThermoDebug {}`, ``)
content = content.replace(`lua.shared.ISBaseObject.ISBaseObject`, `lua.shared.ISBaseObject`)
content = content.replace(`export abstract class Joypad extends lua.shared.JoyPad.Joypad {}`, ``)
content = content.replace(`/** @customConstructor CGlobalObject.new */`, ``)
content = content.replace(`export class CGlobalObject extends zombie.globalObjects.CGlobalObject {}`, ``)
content = content.replace(`/** @customConstructor CGlobalObjectSystem.new */`, ``)
content = content.replace(`export class CGlobalObjectSystem extends zombie.globalObjects.CGlobalObjectSystem {}`, ``)
content = content.replace(`/** @customConstructor SGlobalObject.new */`, ``)
content = content.replace(`export class SGlobalObject extends zombie.globalObjects.SGlobalObject {}`, ``)
content = content.replace(`/** @customConstructor SGlobalObjectSystem.new */`, ``)
content = content.replace(`export class SGlobalObjectSystem extends zombie.globalObjects.SGlobalObjectSystem {}`, ``)
return content
}
function patch_pipewrench() {
console.log("Patching PipeWrench.d.ts ...")
try {
const fileNames = [
'PipeWrench.d.ts',
'server.d.ts',
'client.d.ts',
]
fileNames.forEach(fileName => {
const file = path.join(__dirname, fileName)
let content = fs.readFileSync(file, 'utf-8')
const patchedContent = patch_pipewrench_content(content)
fs.writeFileSync(file, patchedContent)
})
}
catch(error) {
console.error(error)
}
}
function patch_ThermoDebug() {
console.log("Patching ThermoDebug.d.ts ...")
try {
const file = path.join(__dirname, "lua/client/DebugUIs/DebugMenu/Climate/ThermoDebug.d.ts")
let content = fs.readFileSync(file, 'utf-8')
let remove = ` export abstract class ThermoDebug {\n`
remove += ` static [id: string]: any;\n`
remove += ` }`
content = content.replace(remove, ``)
fs.writeFileSync(file, content)
}
catch(error) {
console.error(error)
}
}
function getAllFiles(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function(file) {
const fullPath = path.join(dirPath, "/", file)
if (fs.statSync(fullPath).isDirectory()) {
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles)
} else {
arrayOfFiles.push(fullPath)
}
})
return arrayOfFiles
}
function patch_ISBaseObject() {
console.log("Patching ISBaseObject ...")
try {
const dir = path.join(__dirname, 'lua')
const files = getAllFiles(dir)
files.forEach(file => {
try {
let content = fs.readFileSync(file, 'utf-8')
if (content.includes('lua.shared.ISBaseObject.ISBaseObject')) {
console.log(`> Patching ${file} ...`)
content = content.replaceAll(`lua.shared.ISBaseObject.ISBaseObject`, `lua.shared.ISBaseObject`)
fs.writeFileSync(file, content)
}
}
catch(error) {
console.error(error)
}
})
}
catch(error) {
console.error(error)
}
}
/**
* fix error TS2425: Class 'ISPanel' defines instance member property 'onMouseDoubleClick', but extended class 'ISButton' defines it as instance member function.
*/
function patch_ISUIElement() {
console.log("Patching ISUIElement.d.ts ...")
try {
const file = path.join(__dirname, "lua/client/ISUI/ISUIElement.d.ts")
let content = fs.readFileSync(file, 'utf-8')
content = content.replace(
`onMouseDoubleClick: any;`,
`onMouseDoubleClick(x: any, y: any, ...__args: never[]): any;`
)
fs.writeFileSync(file, content)
}
catch(error) {
console.error(error)
}
}
// Run
patch_fmod_fmod()
patch_pipewrench()
patch_ThermoDebug()
patch_ISBaseObject()
patch_ISUIElement()