PHP Code:
import socket
import io as StringIO
import csv
import os
import shutil
import winreg as wreg
import sys
import subprocess
import tkinter as tk
import urllib.request
import zipfile
ps_path = "_patchSwitcher"
def hook_cod2():
key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
wreg.SetValueEx(key, 'Debugger', 0, wreg.REG_SZ, "\"pythonw.exe\" \"Versionswitcher.py\"")
key.Close()
def unhook_cod2():
key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
try:
wreg.DeleteValue(key, 'Debugger')
except WindowsError:
pass
key.Close()
def install(frame):
if os.path.exists(ps_path):
shutil.rmtree(ps_path)
os.mkdir(ps_path)
urllib.request.urlretrieve("http://www.iznogod.tweak.nl/cod2ps.zip", os.path.join(ps_path, "cod2ps.zip"))
with zipfile.ZipFile(os.path.join(ps_path, 'cod2ps.zip'), 'r') as zf:
zf.extractall(ps_path)
os.remove(os.path.join(ps_path, "cod2ps.zip"))
hook_cod2()
frame.destroy()
def uninstall(frame):
if os.path.exists(ps_path):
shutil.rmtree(ps_path)
unhook_cod2()
frame.destroy()
sys.exit()
def switch_patch(version, frame):
source = os.path.join(ps_path, version)
files = [os.path.join("main", "iw_15.iwd"), "CoD2MP_s.exe", "gfx_d3d_mp_x86_s.dll", "gfx_d3d_x86_s.dll"]
for file in files:
if os.path.exists(file):
os.remove(file)
if os.path.exists(os.path.join(source, file)):
shutil.copyfile(os.path.join(source, file), file)
if frame is not None:
frame.destroy()
return
version = '0.0'
if len(sys.argv) >= 2:
args = " ".join(sys.argv[2:])
if "+connect" in sys.argv[2:]:
index = sys.argv[2:].index("+connect")
info = sys.argv[2:][index + 1].split(":")
if len(info) >= 2:
ip = info[0]
port = int(info[1])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(3.0)
try:
sock.sendto(b'\xff'b'\xff'b'\xff'b'\xff'b'getstatus', (ip, port))
response = sock.recvfrom(8196)[0]
f = StringIO.StringIO(str(response[4:]))
reader = csv.reader(f, delimiter='\\')
for row in reader:
if 'shortversion' in row:
version = row[row.index("shortversion") + 2]
except:
pass
else:
#user is installing/uninstalling the utility
if os.path.exists(ps_path):
#uninstall and reinstall only
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
tk.Button(root, text="Reinstall", width=25, height=3, command=lambda:install(root)).pack()
tk.Button(root, text="Uninstall", width=25, height=3, command=lambda:uninstall(root)).pack()
root.mainloop()
else:
#install only
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
tk.Button(root, text="Install", width=25, height=3, command=lambda:install(root)).pack()
tk.Button(root, text="Uninstall", state='disabled', width=25, height=3).pack()
root.mainloop()
if version == "0.0":
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
versions = ["1.0", "1.2", "1.3"]
for v in versions:
tk.Button(root, text=v, width=25, height=3, command=lambda v=v:switch_patch(v, root)).pack()
root.mainloop()
else:
switch_patch(version, None)
unhook_cod2()
subprocess.call("CoD2MP_s.exe " + args)
hook_cod2()
Minor update: