2025-02-21 16:23:52 -08:00
#communication stuff here
import requests
import json
from hashlib import sha256
2025-03-07 20:38:10 -08:00
from pathlib import Path
from shutil import copyfileobj
2025-02-21 16:23:52 -08:00
from . import helpers , savetools
from websockets . sync . client import connect
from subprocess import Popen , PIPE
from sys import platform
from os import listdir
from os . path import isfile , join , exists
2025-03-07 20:38:10 -08:00
import os
2025-02-21 16:23:52 -08:00
from pathlib import Path
import subprocess
2025-03-07 20:38:10 -08:00
def startClient ( self , id ) :
cmd = f " steam://rungameid/ { id } "
Popen ( [ ' steam ' , cmd ] )
2025-02-21 16:23:52 -08:00
def downloadLatestDll ( self , filepath ) :
x = requests . get ( ' https://openwf.io/supplementals/client %20d rop-in/meta ' )
meta = json . loads ( x . text )
url = f " https://openwf.io/supplementals/client%20drop-in/ { meta [ ' version ' ] } /dwmapi.dll " #
content = requests . get ( url , stream = True ) . content
hashofdll = sha256 ( )
hashofdll . update ( content ) #
if hashofdll . hexdigest ( ) == meta [ ' sha256 ' ] :
2025-03-07 20:38:10 -08:00
print ( filepath )
2025-02-21 16:23:52 -08:00
with open ( filepath + " dwmapi.dll " , " wb " ) as out_file :
out_file . write ( content )
helpers . messageBox ( self = self , title = " Bootstrapper Downloaded " , message = " Bootstrapper Downloaded! " , type = " info " )
else :
helpers . messageBox ( self = self , title = " Unknown Error. " , message = " SpaceninGUI could not verify the hash of the Bootstrapper. Sorry :( " , type = " error " ) #
def getLatestVersions ( self , cacheFile , value ) :
ver = {
" server " : (
" no lol " #not finished update check for server, check back later :3
) ,
" client " : " "
}
#client code here
x = requests . get ( ' https://openwf.io/supplementals/client %20d rop-in/meta ' )
meta = json . loads ( x . text )
ver [ " client " ] = meta [ ' version ' ]
try :
oldVer = savetools . loadFile ( self , cacheFile ) [ " client " ]
except :
with open ( ' tempFile.json ' , ' w ' ) as f :
json . dump ( {
" client " : ' notassigned ' ,
' server ' : ' notassigned '
} , f , indent = 2 )
oldVer = savetools . loadFile ( self , cacheFile ) [ " client " ]
if oldVer == ver [ " client " ] :
client = " Up To Date! "
else :
client = " New Version " + ver [ " client " ]
server = " server Check Not Implemented "
value [ 0 ] . set ( " Latest Server Version: " + server )
value [ 1 ] . set ( " Latest Client Version: " + client )
2025-03-07 20:38:10 -08:00
def startServer ( self , cd , logArea ) : # To my knowledge, running the server in the main thread would stall the gui, fuck that lol
logmax = helpers . getLogMax ( self , self . configFile )
logarr = [ ]
def mongo ( ) :
sysctl = Popen ( [ ' systemctl ' , ' start ' , ' mongodb ' ] )
sysctl . wait ( ) #
def execute ( cd ) :
popen = Popen ( [ ' npm ' , ' run ' , ' dev ' ] , stdin = PIPE , stdout = PIPE , universal_newlines = True , cwd = cd , preexec_fn = os . setsid )
self . popenThreads . append ( popen )
for stdout_line in iter ( popen . stdout . readline , " " ) :
yield stdout_line
popen . stdout . close ( )
return_code = popen . wait ( )
if return_code :
raise subprocess . CalledProcessError ( return_code ) #
def start ( cd , logArea ) :
for path in execute ( cd ) :
if len ( logarr ) < logmax :
logarr . append ( path )
else :
logarr . pop ( 0 )
logarr . append ( path )
if logArea :
logArea . configure ( state = " normal " )
logArea . delete ( 1.0 , " end " )
for element in logarr :
logArea . insert ( " end " , element )
logArea . configure ( state = " disabled " )
if platform == " linux " :
if not self . popenThreads :
helpers . messageBox ( self , title = " MongoDB " , message = " The mongodb server is required to start SNS \n You will need to give sudo permission for this. " , type = " info " )
mongo ( )
start ( cd , logArea )
else :
helpers . messageBox ( self , title = " Already Running! " , message = " The Server is already running! " , type = " info " )
2025-02-21 16:23:52 -08:00
def getClientResponse ( ) :
try :
2025-03-07 20:38:10 -08:00
with connect ( " ws://localhost:6155 " ) as websocket :
2025-02-21 16:23:52 -08:00
message = json . loads ( websocket . recv ( ) )
except :
message = False
return message
def checkForClient ( clientpath ) :
onlyfiles = [ f for f in listdir ( clientpath ) if isfile ( join ( clientpath , f ) ) ]
if " dwmapi.dll " in onlyfiles :
return True
else :
return False
2025-03-07 20:38:10 -08:00
def runPluto ( self , name , runningList ) :
openwfpath = self . clientPath + " /OpenWF/scripts/ "
2025-02-21 16:23:52 -08:00
onlyfiles = [ f for f in listdir ( openwfpath ) if isfile ( join ( openwfpath , f ) ) ]
2025-03-07 20:38:10 -08:00
print ( " called " + name )
if getClientResponse ( ) :
2025-02-21 16:23:52 -08:00
running = [ ]
2025-03-07 20:38:10 -08:00
print ( getClientResponse ( ) [ " running_scripts " ] )
2025-02-21 16:23:52 -08:00
if name in running :
2025-03-07 20:38:10 -08:00
requests . get ( url = ( " http://localhost:6155/stop_script?OpenWF/scripts/ " + name ) )
2025-02-21 16:23:52 -08:00
else :
2025-03-07 20:38:10 -08:00
requests . get ( url = ( " http://localhost:6155/start_script?OpenWF/scripts/ " + name ) )
2025-02-21 16:23:52 -08:00
2025-03-07 20:38:10 -08:00
for script in getClientesponse ( ) [ " running_scripts " ] :
2025-02-21 16:23:52 -08:00
running . append ( script . removeprefix ( " OpenWF/scripts/ " ) ) #
for file in onlyfiles :
if file in running :
2025-03-07 20:38:10 -08:00
if runningList [ file ] : runningList [ file ] . set ( True )
2025-02-21 16:23:52 -08:00
else :
2025-03-07 20:38:10 -08:00
if runningList [ file ] : runningList [ file ] . set ( False )
else :
if runningList [ name ] : runningList [ name ] . set ( False )
2025-02-21 16:23:52 -08:00
def getSnPath ( file ) :
if Path ( file ) . is_file ( ) :
with open ( file ) as f :
d = json . load ( f )
return d [ " spaceninjapath " ]
else :
return False
2025-03-07 20:38:10 -08:00
def openClientLogs ( self , platform ) :
if platform == " linux " :
print ( " ok " )
helpers . messageBox ( self , " " )
def pushWeapon ( self , string , slot ) :
if type ( string ) is list :
i = 0
for part in string :
print ( i )
pluto = f " gRegion:GetLocalPlayerAvatar():InventoryControl():RemoveItem( { slot [ i ] } , true) gRegion:GetLocalPlayerAvatar():GiveItem(Type( \" { part } \" ), true) "
requests . get ( f " http://localhost:61558/start_script_inline? { pluto } " )
if slot [ i ] == 3 :
level = f " gRegion:GetLocalPlayerAvatar():InventoryControl():GetActivePowerSuit():SetXP(1600000) "
else :
level = f " gRegion:GetLocalPlayerAvatar():InventoryControl():GetWeaponInHand( { slot [ i ] } ):SetXP(1600000) "
requests . get ( f " http://localhost:61558/start_script_inline? { level } " )
i + = 1
else :
pluto = f " gRegion:GetLocalPlayerAvatar():InventoryControl():RemoveItem( { slot } , true) gRegion:GetLocalPlayerAvatar():GiveItem(Type( \" { string } \" ), true) gRegion:GetLocalPlayerAvatar():InventoryControl():GetWeaponInHand( { slot } ):SetXP(1600000) "
requests . get ( f " http://localhost:61558/start_script_inline? { pluto } " )
def pushInline ( self , Area ) :
#format
formatted = Area . get ( 0.0 , " end " ) . replace ( " \n " , ' ' )
requests . get ( f " http://localhost:61558/start_script_inline? { formatted } " )
def getWarframeExports ( self , path ) :
exportList = {
" weapons " : " https://raw.githubusercontent.com/calamity-inc/warframe-public-export/refs/heads/senpai/ExportWeapons_en.json " ,
" powersuits " : " https://raw.githubusercontent.com/calamity-inc/warframe-public-export/refs/heads/senpai/ExportWarframes_en.json "
}
for export in exportList . keys ( ) :
helpers . folderExist ( path )
with open ( path + f " { export } .json " , " wb " ) as out_file :
content = requests . get ( exportList [ export ] , stream = True ) . content
out_file . write ( content )
def getWarframeExportsPlus ( self , path ) :
exportList = {
" weapons " : " https://raw.githubusercontent.com/calamity-inc/warframe-public-export-plus/refs/heads/senpai/ExportWeapons.json " ,
" powersuits " : " https://raw.githubusercontent.com/calamity-inc/warframe-public-export-plus/refs/heads/senpai/ExportWarframes.json "
}
for export in exportList . keys ( ) :
helpers . folderExist ( ( path + " /plus/ " ) . replace ( " // " , " / " ) )
with open ( ( path + f " /plus/ { export } .json " ) . replace ( ' // ' , ' / ' ) , " wb " ) as out_file :
content = requests . get ( exportList [ export ] , stream = True ) . content
out_file . write ( content )
2025-02-21 16:23:52 -08:00
2025-03-07 20:38:10 -08:00
def getIconDownload ( self , path , savePath ) :
if not exists ( " ./cache/items/icons " + savePath . rsplit ( ' / ' , 1 ) [ 0 ] ) :
Path ( " ./cache/items/icons " + savePath . rsplit ( ' / ' , 1 ) [ 0 ] ) . mkdir ( parents = True , exist_ok = True )
2025-02-21 16:23:52 -08:00
2025-03-07 20:38:10 -08:00
with open ( " ./cache/items/icons " + savePath , " wb+ " ) as out_file :
print ( f " https://browse.wf { savePath } " )
out_file . write ( requests . get ( f " https://browse.wf { savePath } " ) . content )
2025-02-21 16:23:52 -08:00
2025-03-07 20:38:10 -08:00
print ( f " Saved { path } Icon " )