/devkitpro")
5 | endif
6 |
7 | TOPDIR ?= $(CURDIR)
8 | include $(DEVKITPRO)/libnx/switch_rules
9 |
10 | TARGET := switch-rich-presence
11 | BUILD := build
12 | SOURCES := source
13 | DATA := data
14 | INCLUDES := include
15 | EXEFS_SRC := exefs_src
16 |
17 | ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
18 |
19 | #CFLAGS := -g -Wall -Wextra -O2 -ffunction-sections \
20 | CFLAGS := -g -Wall -O2 -ffunction-sections \
21 | $(ARCH) $(DEFINES)
22 |
23 | CFLAGS += $(INCLUDE) -D__SWITCH__
24 |
25 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
26 |
27 | ASFLAGS := -g $(ARCH)
28 | LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
29 |
30 | LIBS := -lnx -lm
31 |
32 | LIBDIRS := $(PORTLIBS) $(LIBNX)
33 |
34 | ifneq ($(BUILD),$(notdir $(CURDIR)))
35 |
36 | export OUTPUT := $(CURDIR)/$(TARGET)
37 | export TOPDIR := $(CURDIR)
38 |
39 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
40 | $(foreach dir,$(DATA),$(CURDIR)/$(dir))
41 |
42 | export DEPSDIR := $(CURDIR)/$(BUILD)
43 |
44 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
45 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
46 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
47 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
48 |
49 | ifeq ($(strip $(CPPFILES)),)
50 | export LD := $(CC)
51 | else
52 | export LD := $(CXX)
53 | endif
54 |
55 | export OFILES_BIN := $(addsuffix .o,$(BINFILES))
56 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
57 | export OFILES := $(OFILES_BIN) $(OFILES_SRC)
58 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
59 |
60 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
61 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
62 | -I$(CURDIR)/$(BUILD)
63 |
64 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
65 |
66 | export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
67 |
68 | ifeq ($(strip $(CONFIG_JSON)),)
69 | jsons := $(wildcard *.json)
70 | ifneq (,$(findstring $(TARGET).json,$(jsons)))
71 | export APP_JSON := $(TOPDIR)/$(TARGET).json
72 | else
73 | ifneq (,$(findstring config.json,$(jsons)))
74 | export APP_JSON := $(TOPDIR)/config.json
75 | endif
76 | endif
77 | else
78 | export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
79 | endif
80 |
81 | .PHONY: $(BUILD) clean all
82 |
83 | all: $(BUILD)
84 |
85 | $(BUILD):
86 | @[ -d $@ ] || mkdir -p $@
87 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
88 |
89 | clean:
90 | @echo clean ...
91 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).kip
92 |
93 | else
94 | .PHONY: all
95 |
96 | DEPENDS := $(OFILES:.o=.d)
97 |
98 | all : $(OUTPUT).kip
99 |
100 | $(OUTPUT).kip : $(OUTPUT).elf
101 |
102 | $(OUTPUT).elf : $(OFILES)
103 |
104 | $(OFILES_SRC) : $(HFILES_BIN)
105 |
106 | %.bin.o %_bin.h : %.bin
107 | @echo $(notdir $<)
108 | @$(bin2o)
109 |
110 | -include $(DEPENDS)
111 |
112 | endif
113 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Warning: This Project is very outdated and no longer maintained! Please use this instead: https://github.com/SunTheCourier/SwitchPresence-Rewritten
2 |
3 |
4 | # SwitchPresence
5 |
6 | A Nintendo Switch custom sysmodule for Discord Rich Presence.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # Usage
16 | - Copy `switch-rich-presence.kip` to your sd card and edit the `hekate_ipl.ini` to include the sysmodule.
17 | (You can for example add a configuration like this.)
18 | ```
19 | [Discord Rich Presence]
20 | kip1=switch-rich-presence.kip
21 | ```
22 | - Boot your switch into RCM mode and run hekate on it.
23 | - Launch your hekate configuration with rich presence and wait until your switch turns on completely. (Also make sure that your switch is connected to internet.)
24 | - Open the client (`SwitchRichPresence.exe`) and click the "Connect" button.
25 | - Done!
26 |
27 | # Setup a Rich presence app
28 | *Note : I already made a default application with some games on it but if you don't do this, most of your icons won't show on discord.*
29 | - Go to [this link](https://discordapp.com/developers/applications/me).
30 | - Create a new App and give it the name that will be shown on your profile (usually "Nintendo Switch").
31 | - Enable Rich Presence for you app.
32 | - Launch the sysmodule and connect the client to the switch (see [Usage](https://github.com/Random0666/SwitchRichPresence/blob/master/README.md#usage)).
33 | - Once connected, click on `Utils->Export icons` and choose the path where your icons will be exported with the right name/icon size.
34 | - Go to your rich presence app and add all the icons that you just exported with the name they were given and choose the the type "Large".
35 |

36 | - (optional) add a "Small" asset named "icon". This will used as the small image on your profile. (You can use [this one](https://raw.githubusercontent.com/Random0666/Useless-stuff/master/SwitchRichPresence/images/icon.png).)
37 | - Open the `config.txt` file at the root of the client (If this file doesn't exit, running the client once closing it will create a new one.) and edit the `client_id` line with the client ID of the rich presence app you just created.
38 |
39 | # Known issues
40 | - The switch might hang on when getting into sleep mode or when turning it off. If that happens, hard shutdown your switch by pressing the POWER button for ~15 seconds.
41 |
42 | # Other
43 | Again, huge thanks to everyone who contributed to the amazing documentation on [SwitchBrew](http://switchbrew.org/index.php?title=Main_Page).
44 | If you have any question/problem, please contact me on discord : random#6457
45 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Ce code a été généré par un outil.
4 | // Version du runtime :4.0.30319.42000
5 | //
6 | // Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
7 | // le code est régénéré.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SwitchRichPresence.Properties
12 | {
13 |
14 |
15 | ///
16 | /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
17 | ///
18 | // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
19 | // à l'aide d'un outil, tel que ResGen ou Visual Studio.
20 | // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
21 | // avec l'option /str ou régénérez votre projet VS.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SwitchRichPresence.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Remplace la propriété CurrentUICulture du thread actuel pour toutes
56 | /// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/sysmodule/source/creport_debug_types.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct StackFrame {
5 | u64 fp;
6 | u64 lr;
7 | };
8 |
9 | //8 + 8 + C + 4 + 8
10 | struct AttachProcessInfo {
11 | u64 title_id;
12 | u64 process_id;
13 | char name[0xC];
14 | u32 flags;
15 | u64 user_exception_context_address; /* 5.0.0+ */
16 | };
17 |
18 | struct AttachThreadInfo {
19 | u64 thread_id;
20 | u64 tls_address;
21 | u64 entrypoint;
22 | };
23 |
24 | /* TODO: ExitProcessInfo */
25 | /* TODO: ExitThreadInfo */
26 |
27 | enum class DebugExceptionType : u32 {
28 | UndefinedInstruction = 0,
29 | InstructionAbort = 1,
30 | DataAbort = 2,
31 | AlignmentFault = 3,
32 | DebuggerAttached = 4,
33 | BreakPoint = 5,
34 | UserBreak = 6,
35 | DebuggerBreak = 7,
36 | BadSvc = 8,
37 | UnknownNine = 9,
38 | };
39 |
40 | static inline const char *GetDebugExceptionTypeStr(DebugExceptionType type) {
41 | switch (type) {
42 | case DebugExceptionType::UndefinedInstruction:
43 | return "Undefined Instruction";
44 | case DebugExceptionType::InstructionAbort:
45 | return "Instruction Abort";
46 | case DebugExceptionType::DataAbort:
47 | return "Data Abort";
48 | case DebugExceptionType::AlignmentFault:
49 | return "Alignment Fault";
50 | case DebugExceptionType::DebuggerAttached:
51 | return "Debugger Attached";
52 | case DebugExceptionType::BreakPoint:
53 | return "Break Point";
54 | case DebugExceptionType::UserBreak:
55 | return "User Break";
56 | case DebugExceptionType::DebuggerBreak:
57 | return "Debugger Break";
58 | case DebugExceptionType::BadSvc:
59 | return "Bad Svc";
60 | case DebugExceptionType::UnknownNine:
61 | return "Unknown Nine";
62 | default:
63 | return "Unknown";
64 | }
65 | }
66 |
67 | struct UndefinedInstructionInfo {
68 | u32 insn;
69 | };
70 |
71 | struct DataAbortInfo {
72 | u64 address;
73 | };
74 |
75 | struct AlignmentFaultInfo {
76 | u64 address;
77 | };
78 |
79 | struct UserBreakInfo {
80 | u64 info_0;
81 | u64 address;
82 | u64 size;
83 | };
84 |
85 | struct BadSvcInfo {
86 | u32 id;
87 | };
88 |
89 | union SpecificExceptionInfo {
90 | UndefinedInstructionInfo undefined_instruction;
91 | DataAbortInfo data_abort;
92 | AlignmentFaultInfo alignment_fault;
93 | UserBreakInfo user_break;
94 | BadSvcInfo bad_svc;
95 | u64 raw;
96 | };
97 |
98 | struct ExceptionInfo {
99 | DebugExceptionType type;
100 | u64 address;
101 | SpecificExceptionInfo specific;
102 | };
103 |
104 |
105 | enum class DebugEventType : u32 {
106 | AttachProcess = 0,
107 | AttachThread = 1,
108 | ExitProcess = 2,
109 | ExitThread = 3,
110 | Exception = 4
111 | };
112 |
113 | union DebugInfo {
114 | AttachProcessInfo attach_process;
115 | AttachThreadInfo attach_thread;
116 | ExceptionInfo exception;
117 | };
118 |
119 | //simplify : 4+8+C+4=1C
120 | /*
121 | handle
122 |
123 | tid
124 | name
125 | flags
126 | */
127 | struct DebugEventInfo {
128 | DebugEventType type;
129 | u32 flags;
130 | u64 thread_id;
131 | union {
132 | DebugInfo info;
133 | u64 _[0x40/sizeof(u64)];
134 | };
135 | };
136 |
137 | static_assert(sizeof(DebugEventInfo) >= 0x50, "Incorrect DebugEventInfo definition!");
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/SwitchApps.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace SwitchRichPresence
13 | {
14 |
15 | [Serializable]
16 | public class ServerVersionException : Exception
17 | {
18 | public ServerVersionException() { }
19 | public ServerVersionException(string message) : base(message) { }
20 | public ServerVersionException(string message, Exception inner) : base(message, inner) { }
21 | protected ServerVersionException(
22 | System.Runtime.Serialization.SerializationInfo info,
23 | System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
24 | }
25 |
26 | public class SwitchApps : IDisposable
27 | {
28 | private const int CLIENT_VERSION = 1 << 16 | 0 << 8 | 3; //different than the app version
29 | private Socket client;
30 | public List Applications { get; private set; } = new List();
31 |
32 | public SwitchApps(string ip)
33 | {
34 | if (!IPAddress.TryParse(ip, out IPAddress addr))
35 | throw new Exception(string.Format("Invalid IP address : \"{0}\"", ip));
36 |
37 | client = new Socket(SocketType.Stream, ProtocolType.Tcp);
38 | client.Connect(addr, 0xCAFE);
39 |
40 | int ver = GetServerVersion();
41 | if (ver != CLIENT_VERSION)
42 | {
43 | Dispose();
44 |
45 | if (ver > CLIENT_VERSION)
46 | throw new ServerVersionException("Client and server versions don't match : The client is outdated.\r\nPlease download the latest update of both client and server.");
47 | else
48 | throw new ServerVersionException("Client and server versions don't match : The server is outdated.\r\nPlease download the latest update of both client and server.");
49 | }
50 |
51 | GetApplicationList();
52 | }
53 | public void Dispose()
54 | {
55 | try
56 | {
57 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.Disconnect);
58 | }
59 | catch { }
60 | }
61 |
62 | private void GetApplicationList()
63 | {
64 | //get the list
65 | List apps = new List();
66 |
67 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.ListApps);
68 | int count = TcpCommand.ReceiveInt32(client);
69 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.Confirm);
70 | byte[] buff = TcpCommand.ReceiveBuffer(client, count * 0x18);
71 |
72 | using (MemoryStream ms = new MemoryStream(buff))
73 | {
74 | BinaryReader br = new BinaryReader(ms);
75 | for (int i = 0; i < count; i++)
76 | apps.Add(new ApplicationRecord(br));
77 | }
78 |
79 | Applications = new List();
80 | for (int i = 0; i < count; i++)
81 | {
82 | Applications.Add(new TitleInfo(client, apps[i].TitleID));
83 | }
84 | }
85 | private int GetServerVersion()
86 | {
87 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.GetVersion);
88 | int ver = TcpCommand.ReceiveInt32(client);
89 | return ver;
90 | }
91 |
92 | public TitleInfo GetPlaying()
93 | {
94 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.GetCurrentApp);
95 | ulong tid = TcpCommand.ReceiveUInt64(client);
96 |
97 | foreach (var app in Applications)
98 | {
99 | if (app.TitleID == tid)
100 | {
101 | return app;
102 | }
103 | }
104 | return null;
105 | }
106 | public string GetCurrentUser()
107 | {
108 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.GetActiveUser);
109 | bool selected = TcpCommand.ReceiveBool(client);
110 | if (!selected)
111 | return null;
112 | else
113 | {
114 | TcpCommand.SendCommand(client, TcpCommand.SendCommandType.Confirm);
115 | byte[] buffer = TcpCommand.ReceiveBuffer(client, 0x20);
116 | return Encoding.UTF8.GetString(buffer).Replace("\0", "");
117 | }
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/TcpCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 |
10 | namespace SwitchRichPresence
11 | {
12 | [Serializable]
13 | public class TcpCommandException : Exception
14 | {
15 | public TcpCommandException() { }
16 | public TcpCommandException(string message) : base(message) { }
17 | public TcpCommandException(string message, Exception inner) : base(message, inner) { }
18 | protected TcpCommandException(
19 | System.Runtime.Serialization.SerializationInfo info,
20 | System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
21 | }
22 |
23 | public class TcpCommand
24 | {
25 | private const uint SRV_MAGIC = 0x11223300;// 53 52 56 00 | "SRV" + 1byte info
26 | private const uint CLT_MAGIC = 0x33221100;// 43 4C 54 00 | "CLT" + 1byte info
27 |
28 | public enum SendCommandType : byte
29 | {
30 | SendBuffer = 0,
31 | Confirm = 1,
32 | GetControlData = 2,
33 | ListApps = 3,
34 | GetActiveUser = 4,
35 | GetCurrentApp = 5,
36 | GetVersion = 6,
37 | Disconnect = 0xFF,
38 | }
39 |
40 | private static byte[] ReceiveRaw(Socket client, int size)
41 | {
42 | byte[] buffer = new byte[size];
43 |
44 | int total = 0;
45 | while (total < buffer.Length)
46 | {
47 | int count = client.Receive(buffer, total, buffer.Length - total, SocketFlags.None);
48 | if (count < 0)
49 | throw new Exception("Error while receiving data !");
50 | total += count;
51 | }
52 |
53 | return buffer;
54 | }
55 | private static void SendRaw(Socket client, byte[] data)
56 | {
57 | int total = 0;
58 | while (total < data.Length)
59 | {
60 | int count = client.Send(data, total, data.Length - total, SocketFlags.None);
61 | if (count < 0)
62 | throw new Exception("Error while receiving data !");
63 | total += count;
64 | }
65 | }
66 |
67 | //send cmd id
68 | public static void SendCommand(Socket client, SendCommandType type)
69 | {
70 | byte[] buffer = BitConverter.GetBytes(CLT_MAGIC | (byte)type);
71 | SendRaw(client, buffer);
72 | }
73 | public static void ReceiveConfirm(Socket client)
74 | {
75 | byte[] buffer = ReceiveRaw(client, 4);
76 |
77 | uint magic = BitConverter.ToUInt32(buffer, 0);
78 |
79 | if ((magic & 0xFFFFFF00) != SRV_MAGIC)
80 | throw new TcpCommandException(string.Format("Invalid Response magic : 0x{0} instead of 0x{1}", (magic & 0x00FFFFFF).ToString("X"), SRV_MAGIC.ToString("X")));
81 | }
82 |
83 | //header + data
84 | public static byte[] ReceiveBuffer(Socket client, int size)
85 | {
86 | byte[] header = ReceiveRaw(client, 4);
87 |
88 | //validate command
89 | uint magic = BitConverter.ToUInt32(header, 0);
90 | if ((magic & 0xFFFFFF00) != SRV_MAGIC)
91 | throw new TcpCommandException(string.Format("Invalid Response magic : 0x{0} instead of 0x{1}", ((magic & 0xFFFFFF00)>>8).ToString("X"), (SRV_MAGIC>>8).ToString("X")));
92 |
93 | byte[] data = ReceiveRaw(client, size);
94 |
95 | return data;
96 | }
97 | public static void SendBuffer(Socket client, byte[] data)
98 | {
99 | byte[] header = BitConverter.GetBytes(CLT_MAGIC | (byte)SendCommandType.SendBuffer);
100 | SendRaw(client, header);
101 | SendRaw(client, data);
102 | }
103 |
104 | //wrappers
105 | public static void SendBuffer(Socket client, ulong nb)
106 | {
107 | SendBuffer(client, BitConverter.GetBytes(nb));
108 | }
109 | public static int ReceiveInt32(Socket client)
110 | {
111 | return BitConverter.ToInt32(ReceiveBuffer(client, 4), 0);
112 | }
113 | public static ulong ReceiveUInt64(Socket client)
114 | {
115 | return BitConverter.ToUInt64(ReceiveBuffer(client, 8), 0);
116 | }
117 | public static bool ReceiveBool(Socket client)
118 | {
119 | byte[] buff = ReceiveBuffer(client, 1);
120 | return BitConverter.ToBoolean(buff, 0);
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/sysmodule/source/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | //#include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "TcpCommand.h"
12 | #include "result.h"
13 |
14 | #define PORT 0xCAFE
15 |
16 | #define TITLE_ID 0x420000000000001E
17 |
18 |
19 | extern "C" {
20 | extern u32 __start__;
21 |
22 | u32 __nx_applet_type = AppletType_None;
23 |
24 | #define INNER_HEAP_SIZE 0x260000
25 | size_t nx_inner_heap_size = INNER_HEAP_SIZE;
26 | char nx_inner_heap[INNER_HEAP_SIZE];
27 |
28 | void __libnx_initheap(void);
29 | void __appInit(void);
30 | void __appExit(void);
31 | }
32 |
33 | void fatalLater(Result err) {
34 | Handle srv;
35 | #ifdef DEBUG
36 | while (R_FAILED(smGetServiceOriginal(&srv, smEncodeName("fatal:u")))) {
37 | // wait one sec and retry
38 | svcSleepThread(1000000000L);
39 | }
40 | IpcCommand c;
41 | ipcInitialize(&c);
42 | ipcSendPid(&c);
43 | struct {
44 | u64 magic;
45 | u64 cmd_id;
46 | u64 result;
47 | u64 unknown;
48 | } *raw;
49 |
50 | (void*)raw = ipcPrepareHeader(&c, sizeof(*raw));
51 |
52 | raw->magic = SFCI_MAGIC;
53 | raw->cmd_id = 1;
54 | raw->result = err;
55 | raw->unknown = 0;
56 |
57 | ipcDispatch(srv);
58 | svcCloseHandle(srv);
59 | #endif
60 | (void)err;
61 | svcExitProcess();
62 | __builtin_unreachable();
63 | }
64 |
65 |
66 | // we override libnx internals to do a minimal init
67 | void __libnx_initheap(void) {
68 | void* addr = nx_inner_heap;
69 | size_t size = nx_inner_heap_size;
70 |
71 | /* Newlib */
72 | extern char* fake_heap_start;
73 | extern char* fake_heap_end;
74 |
75 | fake_heap_start = (char*)addr;
76 | fake_heap_end = (char*)addr + size;
77 | }
78 |
79 | void registerFspLr()
80 | {
81 | if (kernelAbove400())
82 | return;
83 |
84 | Result rc = fsprInitialize();
85 | if (R_FAILED(rc))
86 | fatalLater(rc);
87 |
88 | u64 pid;
89 | svcGetProcessId(&pid, CUR_PROCESS_HANDLE);
90 |
91 | rc = fsprRegisterProgram(pid, TITLE_ID, FsStorageId_NandSystem, NULL, 0, NULL, 0);
92 | if (R_FAILED(rc))
93 | fatalLater(rc);
94 | fsprExit();
95 | }
96 |
97 | void __appInit(void)
98 | {
99 | Result rc;
100 | svcSleepThread(10000000000L);
101 | rc = smInitialize();
102 | if (R_FAILED(rc))
103 | fatalLater(rc);
104 |
105 | rc = fsInitialize();
106 | if (R_FAILED(rc))
107 | fatalLater(rc);
108 |
109 | registerFspLr();
110 |
111 | rc = fsdevMountSdmc();
112 | if (R_FAILED(rc))
113 | fatalLater(rc);
114 | }
115 |
116 | void __appExit(void)
117 | {
118 | fsdevUnmountAll();
119 | fsExit();
120 | smExit();
121 | audoutExit();
122 | }
123 |
124 | Result socket_init(int* server_fd, sockaddr_in* address)
125 | {
126 | int yes = 1;
127 | Result rc;
128 |
129 | rc = socketInitializeDefault();
130 | if(rc != 0)
131 | {
132 | return rc;
133 | }
134 | // create socket
135 | if ((*server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
136 | {
137 | return -1;
138 | }
139 | // Forcefully attaching socket to port
140 | rc = setsockopt(*server_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
141 | if (rc != 0)
142 | {
143 | return rc;
144 | }
145 | address->sin_family = AF_INET;
146 | address->sin_addr.s_addr = INADDR_ANY;
147 | address->sin_port = htons( PORT );
148 |
149 | //attach socket to port
150 | if (bind(*server_fd, (struct sockaddr *)address, sizeof(*address))<0)
151 | {
152 | return -1;
153 | }
154 |
155 | return 0;
156 | }
157 |
158 |
159 | int main(int argc, char **argv)
160 | {
161 | (void)argc;
162 | (void)argv;
163 |
164 | int server_fd, new_socket;
165 | struct sockaddr_in address;
166 | int addrlen = sizeof(address);
167 |
168 | //init socket
169 | if (R_FAILED(socket_init(&server_fd, &address)))
170 | {
171 | fatalSimple(MAKERESULT(Module_Discord, Error_InitSocket));
172 | }
173 |
174 | //waiting for connection
175 | if (listen(server_fd, 3) < 0)
176 | {
177 | fatalSimple(MAKERESULT(Module_Discord, Error_Listen));
178 | }
179 | while(true)
180 | {
181 |
182 | //Accepting;
183 | if ((new_socket = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen))<0)
184 | {
185 | if (listen(server_fd, 3) < 0)
186 | {
187 | fatalSimple(MAKERESULT(Module_Discord, Error_Listen));
188 | }
189 | }
190 |
191 | StartReceiving(new_socket);
192 | close(new_socket);
193 | }
194 |
195 |
196 | socketExit();
197 | return 0;
198 | }
199 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Forms/UpdateForm.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SwitchRichPresence
2 | {
3 | partial class UpdateForm
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdateForm));
32 | this.label_update = new System.Windows.Forms.Label();
33 | this.textBox1 = new System.Windows.Forms.TextBox();
34 | this.button_ok = new System.Windows.Forms.Button();
35 | this.label2 = new System.Windows.Forms.Label();
36 | this.linkLabel1 = new System.Windows.Forms.LinkLabel();
37 | this.SuspendLayout();
38 | //
39 | // label_update
40 | //
41 | this.label_update.AutoSize = true;
42 | this.label_update.Location = new System.Drawing.Point(12, 23);
43 | this.label_update.Name = "label_update";
44 | this.label_update.Size = new System.Drawing.Size(130, 13);
45 | this.label_update.TabIndex = 0;
46 | this.label_update.Text = "A new Update is available";
47 | //
48 | // textBox1
49 | //
50 | this.textBox1.Location = new System.Drawing.Point(18, 86);
51 | this.textBox1.Multiline = true;
52 | this.textBox1.Name = "textBox1";
53 | this.textBox1.ReadOnly = true;
54 | this.textBox1.Size = new System.Drawing.Size(248, 194);
55 | this.textBox1.TabIndex = 1;
56 | //
57 | // button_ok
58 | //
59 | this.button_ok.Location = new System.Drawing.Point(105, 288);
60 | this.button_ok.Name = "button_ok";
61 | this.button_ok.Size = new System.Drawing.Size(75, 23);
62 | this.button_ok.TabIndex = 2;
63 | this.button_ok.Text = "Ok";
64 | this.button_ok.UseVisualStyleBackColor = true;
65 | this.button_ok.Click += new System.EventHandler(this.button_ok_Click);
66 | //
67 | // label2
68 | //
69 | this.label2.AutoSize = true;
70 | this.label2.Location = new System.Drawing.Point(21, 71);
71 | this.label2.Name = "label2";
72 | this.label2.Size = new System.Drawing.Size(70, 13);
73 | this.label2.TabIndex = 3;
74 | this.label2.Text = "Informations :";
75 | //
76 | // linkLabel1
77 | //
78 | this.linkLabel1.AutoSize = true;
79 | this.linkLabel1.Location = new System.Drawing.Point(15, 38);
80 | this.linkLabel1.Name = "linkLabel1";
81 | this.linkLabel1.Size = new System.Drawing.Size(82, 13);
82 | this.linkLabel1.TabIndex = 4;
83 | this.linkLabel1.TabStop = true;
84 | this.linkLabel1.Text = "Download page";
85 | this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
86 | //
87 | // UpdateForm
88 | //
89 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
90 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
91 | this.ClientSize = new System.Drawing.Size(285, 321);
92 | this.Controls.Add(this.linkLabel1);
93 | this.Controls.Add(this.label2);
94 | this.Controls.Add(this.button_ok);
95 | this.Controls.Add(this.textBox1);
96 | this.Controls.Add(this.label_update);
97 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
98 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
99 | this.MaximizeBox = false;
100 | this.MinimizeBox = false;
101 | this.Name = "UpdateForm";
102 | this.Text = "Update";
103 | this.ResumeLayout(false);
104 | this.PerformLayout();
105 |
106 | }
107 |
108 | #endregion
109 |
110 | private System.Windows.Forms.Label label_update;
111 | private System.Windows.Forms.TextBox textBox1;
112 | private System.Windows.Forms.Button button_ok;
113 | private System.Windows.Forms.Label label2;
114 | private System.Windows.Forms.LinkLabel linkLabel1;
115 | }
116 | }
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/SwitchRichPresence.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {88FC8B2F-B105-4700-8767-0F04B08FED5E}
8 | WinExe
9 | SwitchRichPresence
10 | SwitchRichPresence
11 | v4.6.1
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 | discord sysmodule icon5.ico
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Form
53 |
54 |
55 | AboutForm.cs
56 |
57 |
58 |
59 |
60 |
61 | Component
62 |
63 |
64 | Form
65 |
66 |
67 | MainForm.cs
68 |
69 |
70 | Form
71 |
72 |
73 | UpdateForm.cs
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | AboutForm.cs
84 |
85 |
86 | MainForm.cs
87 |
88 |
89 | UpdateForm.cs
90 |
91 |
92 | ResXFileCodeGenerator
93 | Resources.Designer.cs
94 | Designer
95 |
96 |
97 | True
98 | Resources.resx
99 |
100 |
101 | SettingsSingleFileGenerator
102 | Settings.Designer.cs
103 |
104 |
105 | True
106 | Settings.settings
107 | True
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Title/NACP.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.IO;
7 |
8 | namespace Random0666_s_ToolBox.Modules.NintendoArchive
9 | {
10 | public class NACP
11 | {
12 | public const int LANG_COUNT = 15;
13 |
14 | public enum NACPLangID
15 | {
16 | AmericanEnglish,
17 | BritishEnglish,
18 | Japanese,
19 | French,
20 | German,
21 | LatinAmericanSpanish,
22 | Spanish,
23 | Italian,
24 | Dutch,
25 | CanadianFrench,
26 | Portuguese,
27 | Russian,
28 | Korean,
29 | Taiwanese,
30 | Chinese
31 | }
32 |
33 | public class Language
34 | {
35 | public NACPLangID ID;
36 | public string ApplicationName;
37 | public string ApplicationDev;
38 |
39 | public Language(BinaryReader br, NACPLangID lang)
40 | {
41 | ID = lang;
42 | ApplicationName = Encoding.UTF8.GetString(br.ReadBytes(0x200)).Replace("\0", "");
43 | ApplicationDev = Encoding.UTF8.GetString(br.ReadBytes(0x100)).Replace("\0", "");
44 | }
45 | }
46 |
47 | public List Languages;
48 | public string BaseTitleId;
49 | public string TitleId;
50 | public string ProductCode;
51 | public string AppVersion;
52 | public string Passphrase;
53 |
54 | private bool tryLang(NACPLangID langID, out Language retLang)
55 | {
56 | foreach (var lang in Languages)
57 | {
58 | if (lang.ID == langID && lang.ApplicationName != "")
59 | {
60 | retLang = lang;
61 | return true;
62 | }
63 | }
64 | retLang = null;
65 | return false;
66 | }
67 |
68 | public Language GetLanguage()
69 | {
70 | Language lang;
71 |
72 | //most to less common alphabet
73 | if (tryLang(NACPLangID.AmericanEnglish, out lang))
74 | return lang;
75 | if (tryLang(NACPLangID.BritishEnglish, out lang))
76 | return lang;
77 | if (tryLang(NACPLangID.CanadianFrench, out lang))
78 | return lang;
79 | if (tryLang(NACPLangID.Dutch, out lang))
80 | return lang;
81 | if (tryLang(NACPLangID.French, out lang))
82 | return lang;
83 | if (tryLang(NACPLangID.German, out lang))
84 | return lang;
85 | if (tryLang(NACPLangID.Spanish, out lang))
86 | return lang;
87 | if (tryLang(NACPLangID.LatinAmericanSpanish, out lang))
88 | return lang;
89 | if (tryLang(NACPLangID.Italian, out lang))
90 | return lang;
91 | if (tryLang(NACPLangID.Portuguese, out lang))
92 | return lang;
93 | if (tryLang(NACPLangID.Taiwanese, out lang))
94 | return lang;
95 | if (tryLang(NACPLangID.Japanese, out lang))
96 | return lang;
97 | if (tryLang(NACPLangID.Korean, out lang))
98 | return lang;
99 | if (tryLang(NACPLangID.Chinese, out lang))
100 | return lang;
101 | if (tryLang(NACPLangID.Russian, out lang))
102 | return lang;
103 |
104 | throw new Exception("Can't find common title lang !");
105 | }
106 |
107 | private void ParseFile(BinaryReader br)
108 | {
109 | br.BaseStream.Position = 0;
110 |
111 | Languages = new List();
112 | for (int i = 0; i < LANG_COUNT; i++)
113 | {
114 | Languages.Add(new Language(br, (NACPLangID)i));
115 | }
116 |
117 | br.BaseStream.Seek(0x3038, SeekOrigin.Begin);
118 | BaseTitleId = br.ReadUInt64().ToString("X16");
119 |
120 | br.BaseStream.Seek(0x3078, SeekOrigin.Begin);
121 | TitleId = br.ReadUInt64().ToString("X16");
122 |
123 | br.BaseStream.Seek(0x3060, SeekOrigin.Begin);
124 | AppVersion = Encoding.ASCII.GetString(br.ReadBytes(0x10)).Replace("\0", "");
125 |
126 | br.BaseStream.Seek(0x30A8, SeekOrigin.Begin);
127 | ProductCode = Encoding.ASCII.GetString(br.ReadBytes(8)).Replace("\0", "");
128 | if (ProductCode == "") ProductCode = "null";
129 |
130 | br.BaseStream.Seek(0x3100, SeekOrigin.Begin);
131 | Passphrase = Encoding.ASCII.GetString(br.ReadBytes(0x40));
132 | }
133 | public NACP(string path)
134 | {
135 | using (FileStream fs = File.OpenRead(path))
136 | {
137 | ParseFile(new BinaryReader(fs));
138 | }
139 | }
140 | public NACP(Stream stream)
141 | {
142 | using (stream)
143 | {
144 | ParseFile(new BinaryReader(stream));
145 | }
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 |
56 | # StyleCop
57 | StyleCopReport.xml
58 |
59 | # Files built by Visual Studio
60 | *_i.c
61 | *_p.c
62 | *_h.h
63 | *.ilk
64 | *.meta
65 | *.obj
66 | *.iobj
67 | *.pch
68 | *.pdb
69 | *.ipdb
70 | *.pgc
71 | *.pgd
72 | *.rsp
73 | *.sbr
74 | *.tlb
75 | *.tli
76 | *.tlh
77 | *.tmp
78 | *.tmp_proj
79 | *.log
80 | *.vspscc
81 | *.vssscc
82 | .builds
83 | *.pidb
84 | *.svclog
85 | *.scc
86 |
87 | # Chutzpah Test files
88 | _Chutzpah*
89 |
90 | # Visual C++ cache files
91 | ipch/
92 | *.aps
93 | *.ncb
94 | *.opendb
95 | *.opensdf
96 | *.sdf
97 | *.cachefile
98 | *.VC.db
99 | *.VC.VC.opendb
100 |
101 | # Visual Studio profiler
102 | *.psess
103 | *.vsp
104 | *.vspx
105 | *.sap
106 |
107 | # Visual Studio Trace Files
108 | *.e2e
109 |
110 | # TFS 2012 Local Workspace
111 | $tf/
112 |
113 | # Guidance Automation Toolkit
114 | *.gpState
115 |
116 | # ReSharper is a .NET coding add-in
117 | _ReSharper*/
118 | *.[Rr]e[Ss]harper
119 | *.DotSettings.user
120 |
121 | # JustCode is a .NET coding add-in
122 | .JustCode
123 |
124 | # TeamCity is a build add-in
125 | _TeamCity*
126 |
127 | # DotCover is a Code Coverage Tool
128 | *.dotCover
129 |
130 | # AxoCover is a Code Coverage Tool
131 | .axoCover/*
132 | !.axoCover/settings.json
133 |
134 | # Visual Studio code coverage results
135 | *.coverage
136 | *.coveragexml
137 |
138 | # NCrunch
139 | _NCrunch_*
140 | .*crunch*.local.xml
141 | nCrunchTemp_*
142 |
143 | # MightyMoose
144 | *.mm.*
145 | AutoTest.Net/
146 |
147 | # Web workbench (sass)
148 | .sass-cache/
149 |
150 | # Installshield output folder
151 | [Ee]xpress/
152 |
153 | # DocProject is a documentation generator add-in
154 | DocProject/buildhelp/
155 | DocProject/Help/*.HxT
156 | DocProject/Help/*.HxC
157 | DocProject/Help/*.hhc
158 | DocProject/Help/*.hhk
159 | DocProject/Help/*.hhp
160 | DocProject/Help/Html2
161 | DocProject/Help/html
162 |
163 | # Click-Once directory
164 | publish/
165 |
166 | # Publish Web Output
167 | *.[Pp]ublish.xml
168 | *.azurePubxml
169 | # Note: Comment the next line if you want to checkin your web deploy settings,
170 | # but database connection strings (with potential passwords) will be unencrypted
171 | *.pubxml
172 | *.publishproj
173 |
174 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
175 | # checkin your Azure Web App publish settings, but sensitive information contained
176 | # in these scripts will be unencrypted
177 | PublishScripts/
178 |
179 | # NuGet Packages
180 | *.nupkg
181 | # The packages folder can be ignored because of Package Restore
182 | **/[Pp]ackages/*
183 | # except build/, which is used as an MSBuild target.
184 | !**/[Pp]ackages/build/
185 | # Uncomment if necessary however generally it will be regenerated when needed
186 | #!**/[Pp]ackages/repositories.config
187 | # NuGet v3's project.json files produces more ignorable files
188 | *.nuget.props
189 | *.nuget.targets
190 |
191 | # Microsoft Azure Build Output
192 | csx/
193 | *.build.csdef
194 |
195 | # Microsoft Azure Emulator
196 | ecf/
197 | rcf/
198 |
199 | # Windows Store app package directories and files
200 | AppPackages/
201 | BundleArtifacts/
202 | Package.StoreAssociation.xml
203 | _pkginfo.txt
204 | *.appx
205 |
206 | # Visual Studio cache files
207 | # files ending in .cache can be ignored
208 | *.[Cc]ache
209 | # but keep track of directories ending in .cache
210 | !*.[Cc]ache/
211 |
212 | # Others
213 | ClientBin/
214 | ~$*
215 | *~
216 | *.dbmdl
217 | *.dbproj.schemaview
218 | *.jfm
219 | *.pfx
220 | *.publishsettings
221 | orleans.codegen.cs
222 |
223 | # Including strong name files can present a security risk
224 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
225 | #*.snk
226 |
227 | # Since there are multiple workflows, uncomment next line to ignore bower_components
228 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
229 | #bower_components/
230 |
231 | # RIA/Silverlight projects
232 | Generated_Code/
233 |
234 | # Backup & report files from converting an old project file
235 | # to a newer Visual Studio version. Backup files are not needed,
236 | # because we have git ;-)
237 | _UpgradeReport_Files/
238 | Backup*/
239 | UpgradeLog*.XML
240 | UpgradeLog*.htm
241 | ServiceFabricBackup/
242 | *.rptproj.bak
243 |
244 | # SQL Server files
245 | *.mdf
246 | *.ldf
247 | *.ndf
248 |
249 | # Business Intelligence projects
250 | *.rdl.data
251 | *.bim.layout
252 | *.bim_*.settings
253 | *.rptproj.rsuser
254 |
255 | # Microsoft Fakes
256 | FakesAssemblies/
257 |
258 | # GhostDoc plugin setting file
259 | *.GhostDoc.xml
260 |
261 | # Node.js Tools for Visual Studio
262 | .ntvs_analysis.dat
263 | node_modules/
264 |
265 | # Visual Studio 6 build log
266 | *.plg
267 |
268 | # Visual Studio 6 workspace options file
269 | *.opt
270 |
271 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
272 | *.vbw
273 |
274 | # Visual Studio LightSwitch build output
275 | **/*.HTMLClient/GeneratedArtifacts
276 | **/*.DesktopClient/GeneratedArtifacts
277 | **/*.DesktopClient/ModelManifest.xml
278 | **/*.Server/GeneratedArtifacts
279 | **/*.Server/ModelManifest.xml
280 | _Pvt_Extensions
281 |
282 | # Paket dependency manager
283 | .paket/paket.exe
284 | paket-files/
285 |
286 | # FAKE - F# Make
287 | .fake/
288 |
289 | # JetBrains Rider
290 | .idea/
291 | *.sln.iml
292 |
293 | # CodeRush
294 | .cr/
295 |
296 | # Python Tools for Visual Studio (PTVS)
297 | __pycache__/
298 | *.pyc
299 |
300 | # Cake - Uncomment if you are using it
301 | # tools/**
302 | # !tools/packages.config
303 |
304 | # Tabs Studio
305 | *.tss
306 |
307 | # Telerik's JustMock configuration file
308 | *.jmconfig
309 |
310 | # BizTalk build output
311 | *.btp.cs
312 | *.btm.cs
313 | *.odx.cs
314 | *.xsd.cs
315 |
316 | # OpenCover UI analysis results
317 | OpenCover/
318 |
319 | # Azure Stream Analytics local run output
320 | ASALocalRun/
321 |
322 | # MSBuild Binary and Structured Log
323 | *.binlog
324 |
325 | # NVidia Nsight GPU debugger configuration file
326 | *.nvuser
327 |
328 | # MFractors (Xamarin productivity tool) working folder
329 | .mfractor/
330 |
331 | # Local History for Visual Studio
332 | .localhistory/
333 | #C++
334 | *.elf
335 | *.kip
336 | build/
337 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Forms/AboutForm.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SwitchRichPresence
2 | {
3 | partial class AboutForm
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
32 | this.label1 = new System.Windows.Forms.Label();
33 | this.pictureBox1 = new System.Windows.Forms.PictureBox();
34 | this.button_ok = new System.Windows.Forms.Button();
35 | this.linkLabel_twitter = new System.Windows.Forms.LinkLabel();
36 | this.linkLabel_github = new System.Windows.Forms.LinkLabel();
37 | this.linkLabel_youtube = new System.Windows.Forms.LinkLabel();
38 | this.textBox_discord = new System.Windows.Forms.TextBox();
39 | this.label2 = new System.Windows.Forms.Label();
40 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
41 | this.SuspendLayout();
42 | //
43 | // label1
44 | //
45 | this.label1.AutoSize = true;
46 | this.label1.Location = new System.Drawing.Point(123, 22);
47 | this.label1.Name = "label1";
48 | this.label1.Size = new System.Drawing.Size(125, 13);
49 | this.label1.TabIndex = 0;
50 | this.label1.Text = "Created by Random0666";
51 | //
52 | // pictureBox1
53 | //
54 | this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
55 | this.pictureBox1.Location = new System.Drawing.Point(15, 12);
56 | this.pictureBox1.Name = "pictureBox1";
57 | this.pictureBox1.Size = new System.Drawing.Size(100, 100);
58 | this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
59 | this.pictureBox1.TabIndex = 1;
60 | this.pictureBox1.TabStop = false;
61 | //
62 | // button_ok
63 | //
64 | this.button_ok.Location = new System.Drawing.Point(98, 181);
65 | this.button_ok.Name = "button_ok";
66 | this.button_ok.Size = new System.Drawing.Size(75, 23);
67 | this.button_ok.TabIndex = 2;
68 | this.button_ok.Text = "Ok";
69 | this.button_ok.UseVisualStyleBackColor = true;
70 | this.button_ok.Click += new System.EventHandler(this.button_ok_Click);
71 | //
72 | // linkLabel_twitter
73 | //
74 | this.linkLabel_twitter.AutoSize = true;
75 | this.linkLabel_twitter.Location = new System.Drawing.Point(124, 46);
76 | this.linkLabel_twitter.Name = "linkLabel_twitter";
77 | this.linkLabel_twitter.Size = new System.Drawing.Size(39, 13);
78 | this.linkLabel_twitter.TabIndex = 3;
79 | this.linkLabel_twitter.TabStop = true;
80 | this.linkLabel_twitter.Text = "Twitter";
81 | this.linkLabel_twitter.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_twitter_LinkClicked);
82 | //
83 | // linkLabel_github
84 | //
85 | this.linkLabel_github.AutoSize = true;
86 | this.linkLabel_github.Location = new System.Drawing.Point(124, 61);
87 | this.linkLabel_github.Name = "linkLabel_github";
88 | this.linkLabel_github.Size = new System.Drawing.Size(38, 13);
89 | this.linkLabel_github.TabIndex = 4;
90 | this.linkLabel_github.TabStop = true;
91 | this.linkLabel_github.Text = "Github";
92 | this.linkLabel_github.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_github_LinkClicked);
93 | //
94 | // linkLabel_youtube
95 | //
96 | this.linkLabel_youtube.AutoSize = true;
97 | this.linkLabel_youtube.Location = new System.Drawing.Point(124, 77);
98 | this.linkLabel_youtube.Name = "linkLabel_youtube";
99 | this.linkLabel_youtube.Size = new System.Drawing.Size(47, 13);
100 | this.linkLabel_youtube.TabIndex = 5;
101 | this.linkLabel_youtube.TabStop = true;
102 | this.linkLabel_youtube.Text = "Youtube";
103 | this.linkLabel_youtube.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_youtube_LinkClicked);
104 | //
105 | // textBox_discord
106 | //
107 | this.textBox_discord.Location = new System.Drawing.Point(14, 145);
108 | this.textBox_discord.Name = "textBox_discord";
109 | this.textBox_discord.ReadOnly = true;
110 | this.textBox_discord.Size = new System.Drawing.Size(79, 20);
111 | this.textBox_discord.TabIndex = 6;
112 | this.textBox_discord.Text = "random#6457";
113 | //
114 | // label2
115 | //
116 | this.label2.AutoSize = true;
117 | this.label2.Location = new System.Drawing.Point(12, 116);
118 | this.label2.Name = "label2";
119 | this.label2.Size = new System.Drawing.Size(202, 26);
120 | this.label2.TabIndex = 7;
121 | this.label2.Text = "If you have any question/problem, please\r\ncontact me on discord : ";
122 | //
123 | // AboutForm
124 | //
125 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
126 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
127 | this.ClientSize = new System.Drawing.Size(271, 210);
128 | this.Controls.Add(this.textBox_discord);
129 | this.Controls.Add(this.label2);
130 | this.Controls.Add(this.linkLabel_youtube);
131 | this.Controls.Add(this.linkLabel_github);
132 | this.Controls.Add(this.linkLabel_twitter);
133 | this.Controls.Add(this.button_ok);
134 | this.Controls.Add(this.pictureBox1);
135 | this.Controls.Add(this.label1);
136 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
137 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
138 | this.MaximizeBox = false;
139 | this.MinimizeBox = false;
140 | this.Name = "AboutForm";
141 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
142 | this.Text = "About";
143 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
144 | this.ResumeLayout(false);
145 | this.PerformLayout();
146 |
147 | }
148 |
149 | #endregion
150 |
151 | private System.Windows.Forms.Label label1;
152 | private System.Windows.Forms.PictureBox pictureBox1;
153 | private System.Windows.Forms.Button button_ok;
154 | private System.Windows.Forms.LinkLabel linkLabel_twitter;
155 | private System.Windows.Forms.LinkLabel linkLabel_github;
156 | private System.Windows.Forms.LinkLabel linkLabel_youtube;
157 | private System.Windows.Forms.TextBox textBox_discord;
158 | private System.Windows.Forms.Label label2;
159 | }
160 | }
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Forms/MainForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Diagnostics;
6 | using System.Drawing;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Net;
10 | using System.Net.Sockets;
11 | using System.Text;
12 | using System.Threading;
13 | using System.Threading.Tasks;
14 | using System.Windows.Forms;
15 |
16 | namespace SwitchRichPresence
17 | {
18 | public partial class MainForm : Form
19 | {
20 | public static string TEMP_PATH = Path.GetTempPath() + @"\SwitchRichPresence\";
21 |
22 | string appID;
23 | DiscordController discord = new DiscordController();
24 | Thread UpdatePlaying;
25 | SwitchApps apps = null;
26 | TitleInfo CurrentPlaying = null;
27 | ulong CurrentTid = 0;
28 | long startTime;
29 | string CurrentUser = null;
30 |
31 |
32 | private void UpdateInfo()
33 | {
34 | bool newTitle = (CurrentPlaying != null && CurrentPlaying.TitleID != CurrentTid);
35 |
36 | if (CurrentPlaying != null)
37 | {
38 | if (newTitle)
39 | {
40 | if (pictureBox_icon.Image != null)
41 | pictureBox_icon.Image.Dispose();
42 | pictureBox_icon.Image = new Bitmap(CurrentPlaying.Icon);
43 |
44 | startTime = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
45 | CurrentTid = CurrentPlaying.TitleID;
46 |
47 | discord.presence = new DiscordRpc.RichPresence()
48 | {
49 | details = "Playing " + CurrentPlaying.Metadata.GetLanguage().ApplicationName,
50 | smallImageKey = "icon",
51 | smallImageText = "Rich Presense Sysmodule",
52 | largeImageKey = CurrentPlaying.Metadata.BaseTitleId.ToLower(),
53 | largeImageText = CurrentPlaying.Metadata.GetLanguage().ApplicationName,
54 | startTimestamp = startTime,
55 | };
56 |
57 | }
58 |
59 | //update user
60 | checkBox_showUser_CheckedChanged(null, null);
61 | //update time
62 | checkBox_showTime_CheckedChanged(null, null);
63 |
64 | //layout
65 | label_game.Text = string.Format("Game : {0}\r\nTitle ID : {1}\r\nVersion : {2}\r\n{3}",
66 | CurrentPlaying.Metadata.GetLanguage().ApplicationName,
67 | CurrentPlaying.Metadata.TitleId,
68 | CurrentPlaying.Metadata.AppVersion,
69 | discord.presence.state
70 | );
71 |
72 | }
73 | else
74 | {
75 | if (pictureBox_icon.Image != null)
76 | pictureBox_icon.Image.Dispose();
77 | pictureBox_icon.Image = null;
78 |
79 | discord.presence = new DiscordRpc.RichPresence()
80 | {
81 | details = "Not Playing",
82 | state = "",
83 | smallImageKey = "",
84 | smallImageText = "",
85 | largeImageKey = "",
86 | largeImageText = "",
87 | };
88 | label_game.Text = "Not playing";
89 | CurrentTid = 0;
90 | }
91 | DiscordRpc.UpdatePresence(discord.presence);
92 | }
93 | private void SaveConfig()
94 | {
95 | Config config = new Config()
96 | {
97 | Ip = textBox_ip.Text,
98 | ClientID = textBox_clientId.Text,
99 | ShowTimer = checkBox_showTime.Checked,
100 | ShowUser = checkBox_showUser.Checked,
101 | };
102 | config.Save();
103 | }
104 | private void LoadConfig()
105 | {
106 | Config config = new Config();
107 | appID = config.ClientID;
108 | textBox_ip.Text = config.Ip;
109 | textBox_clientId.Text = config.ClientID;
110 | checkBox_showTime.Checked = config.ShowTimer;
111 | checkBox_showUser.Checked = config.ShowUser;
112 | }
113 |
114 | public MainForm()
115 | {
116 | InitializeComponent();
117 |
118 | LoadConfig();
119 |
120 | Updater.GetUpdate();
121 |
122 | if (!Directory.Exists(TEMP_PATH))
123 | {
124 | Directory.CreateDirectory(TEMP_PATH);
125 | }
126 |
127 | discord.Initialize(appID);
128 | DiscordRpc.UpdatePresence(discord.presence);
129 |
130 | }
131 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
132 | {
133 | if (button_connect.Text != "Connect")
134 | {
135 | //close safely
136 | button_connect_Click(null, null);
137 | }
138 |
139 | DiscordRpc.Shutdown();
140 | }
141 |
142 | private void button_connect_Click(object sender, EventArgs e)
143 | {
144 | if (button_connect.Text == "Connect")
145 | {
146 | try
147 | {
148 | apps = new SwitchApps(textBox_ip.Text);
149 | }
150 | catch (SocketException)
151 | {
152 | MessageBox.Show("No switch found !\r\nMake sure that the ip you entered is correct.");
153 | return;
154 | }
155 | catch (ServerVersionException ex)
156 | {
157 | MessageBox.Show(ex.Message);
158 | return;
159 | }
160 |
161 | SaveConfig();
162 |
163 | textBox_ip.Enabled = false;
164 | textBox_clientId.Enabled = false;
165 | utilsToolStripMenuItem.Visible = true;
166 | button_connect.Text = "Abort";
167 |
168 | UpdatePlaying = new Thread(() => {
169 | while (true)
170 | {
171 | CurrentPlaying = apps.GetPlaying();
172 | CurrentUser = apps.GetCurrentUser();
173 | Invoke(new Action(() => UpdateInfo()));
174 |
175 | Thread.Sleep(1000 * 2);
176 | }
177 | });
178 | UpdatePlaying.IsBackground = true;
179 | UpdatePlaying.Start();
180 | }
181 | else //abort
182 | {
183 | textBox_ip.Enabled = true;
184 | textBox_clientId.Enabled = true;
185 | utilsToolStripMenuItem.Visible = false;
186 | button_connect.Text = "Connect";
187 |
188 | UpdatePlaying.Abort();
189 | apps.Dispose();
190 | UpdatePlaying = null;
191 | CurrentPlaying = null;
192 | apps = null;
193 | UpdateInfo();
194 | }
195 | }
196 |
197 | private void exportIconsToolStripMenuItem_Click(object sender, EventArgs e)
198 | {
199 | FolderSelectDialog fbox = new FolderSelectDialog();
200 | if (fbox.ShowDialog() == DialogResult.OK)
201 | {
202 | foreach (var app in apps.Applications)
203 | {
204 | using (Bitmap bmp = new Bitmap(app.Icon, 512, 512))
205 | {
206 | bmp.Save(fbox.SelectedPath + @"\" + app.TitleID.ToString("X16") + ".png");
207 | }
208 | }
209 |
210 | MessageBox.Show("Done!");
211 | }
212 | }
213 |
214 | private void checkBox_showUser_CheckedChanged(object sender, EventArgs e)
215 | {
216 | if (apps != null)
217 | {
218 |
219 | if (checkBox_showUser.Checked)
220 | discord.presence.state = (CurrentUser == null)
221 | ? "No user selected."
222 | : "User : " + CurrentUser;
223 |
224 | else
225 | discord.presence.state = "";
226 |
227 | DiscordRpc.UpdatePresence(discord.presence);
228 | }
229 | }
230 |
231 | private void checkBox_showTime_CheckedChanged(object sender, EventArgs e)
232 | {
233 | if (apps != null)
234 | {
235 | discord.presence.startTimestamp = (checkBox_showTime.Checked) ? startTime : 0;
236 | DiscordRpc.UpdatePresence(discord.presence);
237 | }
238 | }
239 |
240 | private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
241 | {
242 | AboutForm form = new AboutForm();
243 | form.ShowDialog();
244 | }
245 |
246 | }
247 | }
--------------------------------------------------------------------------------
/sysmodule/source/TcpCommand.cpp:
--------------------------------------------------------------------------------
1 | #include "TcpCommand.h"
2 |
3 | const int SRV_MAGIC = 0x11223300;
4 | const int CLT_MAGIC = 0x33221100;
5 | const int CONTROL_NACP_SIZE = 0x4000;
6 | const int CONTROL_FULL_SIZE = 0x24000;
7 |
8 | const int SERVER_VERSION = 1 << 16 | 0 << 8 | 3;
9 |
10 |
11 | void SendRaw(int socket, void* buff, size_t size)
12 | {
13 | size_t total = 0;
14 | while (total < size)
15 | {
16 | size_t count = send(socket, (char*)buff + total, size - total, 0);
17 | if (count <= 0)
18 | fatalSimple(MAKERESULT(Module_Discord, Error_SendData));
19 | total += count;
20 | }
21 | }
22 | void ReceiveRaw(int socket, void* buff, size_t size)
23 | {
24 | size_t total = 0;
25 | while (total < size)
26 | {
27 | size_t count = recv(socket, (char*)buff + total, size - total, 0);
28 | if (count <= 0)
29 | fatalSimple(MAKERESULT(Module_Discord, Error_RecData));
30 | total += count;
31 | }
32 | }
33 |
34 | ClientCommand ReceiveCommand(int socket)
35 | {
36 | int ret;
37 | ReceiveRaw(socket, &ret, 4);
38 | if ((ret & 0xFFFFFF00) != CLT_MAGIC)
39 | {
40 | return ClientCommand::Disconnect;
41 | }
42 | return (ClientCommand)(ret & 0xFF);
43 | }
44 |
45 | void SendBuffer(int socket, void* data, size_t size)
46 | {
47 | int header = SRV_MAGIC | (u8)ServerCommand::Normal;
48 |
49 | SendRaw(socket, &header, 4);
50 | if (data != NULL)
51 | SendRaw(socket, data, size);
52 | }
53 |
54 | void SendConfirm(int socket)
55 | {
56 | int header = SRV_MAGIC | (u8)ServerCommand::Confirm;
57 | SendRaw(socket, &header, 4);
58 | }
59 |
60 | void ReceiveBuffer(int socket, void* out_buff, size_t size)
61 | {
62 | int ret;
63 | ReceiveRaw(socket, &ret, 4);
64 |
65 | if ((ret & 0xFFFFFF00) != CLT_MAGIC)
66 | {
67 | fatalSimple(MAKERESULT(Module_Discord, Error_InvalidMagic));
68 | }
69 |
70 | if ((ret & 0xFF) != (int)ClientCommand::SendBuffer)
71 | {
72 | fatalSimple(MAKERESULT(Module_Discord, Error_CmdIdNotSendBuff));
73 | }
74 |
75 | ReceiveRaw(socket, out_buff, size);
76 | }
77 |
78 | void ReceiveConfirm(int socket)
79 | {
80 | int ret;
81 | ReceiveRaw(socket, &ret, 4);
82 |
83 | if ((ret & 0xFFFFFF00) != CLT_MAGIC)
84 | {
85 | fatalSimple(MAKERESULT(Module_Discord, Error_InvalidMagic));
86 | }
87 |
88 | if ((ret & 0xFF) != (int)ClientCommand::Confirm)
89 | {
90 | fatalSimple(MAKERESULT(Module_Discord, Error_CmdIdNotConfirm));
91 | }
92 | }
93 |
94 |
95 |
96 |
97 | void SendAppList(int socket)
98 | {
99 | Result rc;
100 | NsApplicationRecord* list = new NsApplicationRecord[255];
101 | int count = 0;
102 |
103 | rc = nsListApplicationRecord(list, sizeof(NsApplicationRecord)*255, &count);
104 | if (R_FAILED(rc))
105 | {
106 | fatalSimple(MAKERESULT(Module_Discord, Error_ListAppFailed));
107 | }
108 |
109 | SendBuffer(socket, &count, 4);
110 | ReceiveConfirm(socket);
111 | SendBuffer(socket, list, sizeof(NsApplicationRecord) * count);
112 |
113 | delete[] list;
114 | }
115 |
116 | void SendCurrentApp(int socket)
117 | {
118 | Result rc;
119 | u64 pid;
120 | u64 tid = 0;
121 | int count;
122 |
123 | u64* pids = new u64[256];
124 | u32 pid_count;
125 | Handle debug_handle;
126 | DebugEventInfo *d = new DebugEventInfo;
127 |
128 | /*
129 | rc = pmdmntGetApplicationPid(&pid);
130 | if (R_SUCCEEDED(rc))
131 | {
132 | rc = pminfoGetTitleId(&tid, pid);
133 | if (R_FAILED(rc))
134 | fatalSimple(MAKERESULT(Module_Discord, Error_GetProcessTid));
135 | }*/
136 |
137 | /*
138 | ------------------------------------------------------------------------------------------------------------------------------
139 | for some reasons, the code above doesn't work on fws >= 5.x.x (pmdmntGetApplicationPid gives wrong infos) so I have to use a hackjob
140 | also if you know what the issue is, PLEASE TELL ME, I'd really like to not do it like this
141 | ------------------------------------------------------------------------------------------------------------------------------
142 | */
143 |
144 | rc = svcGetProcessList(&pid_count, pids, 256);
145 | if (R_FAILED(rc))
146 | {
147 | fatalSimple(MAKERESULT(Module_Discord, Error_GetPidList));
148 | }
149 |
150 | for(int i = 0; i < pid_count; i++)
151 | {
152 | //applications processes always have PIDs > 0x80
153 | //but atmosphere's pm don't recalculates the pids when a process is removed from the boot list
154 | //so I put 70 to be safe (it now only might bne a problem is more than 10 processes are not booted or were killed)
155 | if (pids[i] >= 0x70)
156 | {
157 | //try debugging each application process
158 | rc = svcDebugActiveProcess(&debug_handle, pids[i]);
159 | if (R_SUCCEEDED(rc))
160 | {
161 | pid = pids[i];
162 |
163 | //attach process
164 | while (R_SUCCEEDED(svcGetDebugEvent((u8 *)d, debug_handle)))
165 | {
166 | if(d->type == DebugEventType::AttachProcess)
167 | {
168 | break;
169 | }
170 | }
171 |
172 | tid = d->info.attach_process.title_id;
173 |
174 | rc = svcCloseHandle(debug_handle);
175 | if(R_FAILED(rc))
176 | {
177 | fatalSimple(MAKERESULT(Module_Discord, Error_CloseHandle));
178 | }
179 |
180 | //avoid non-game titles like applets
181 | if (tid < 0x0100000000010000)
182 | {
183 | tid = 0;
184 | continue;
185 | }
186 | else break;
187 | }
188 | }
189 | }
190 |
191 | exit_send_current:
192 | SendBuffer(socket, &tid, 8);
193 |
194 | delete[] pids;
195 | }
196 |
197 | void SendVersion(int socket)
198 | {
199 | int ver = SERVER_VERSION;
200 | SendBuffer(socket, &ver, 4);
201 | }
202 |
203 | void SendActiveUser(int socket)
204 | {
205 | Result rc;
206 | u128 userID=0;
207 | bool account_selected=0;
208 | AccountProfile profile;
209 | AccountProfileBase profilebase;
210 |
211 | rc = accountGetActiveUser(&userID, &account_selected);
212 | if(R_FAILED(rc))
213 | fatalSimple(MAKERESULT(Module_Discord, Error_GetAciveUser));
214 |
215 | SendBuffer(socket, &account_selected, 1);
216 |
217 | if(account_selected)
218 | {
219 | ReceiveConfirm(socket);
220 |
221 | rc = accountGetProfile(&profile, userID);
222 | if(R_FAILED(rc))
223 | fatalSimple(MAKERESULT(Module_Discord, Error_GetProfile));
224 |
225 | rc = accountProfileGet(&profile, NULL, &profilebase);
226 | if(R_FAILED(rc))
227 | fatalSimple(MAKERESULT(Module_Discord, Error_ProfileGet));
228 |
229 | accountProfileClose(&profile);
230 |
231 | SendBuffer(socket, profilebase.username, 0x20);
232 | }
233 | }
234 |
235 | void SendControlData(int socket)
236 | {
237 | u64 tid;
238 | size_t outsize;
239 | Result rc;
240 | NsApplicationControlData* control = new NsApplicationControlData;
241 |
242 | SendConfirm(socket);
243 | ReceiveBuffer(socket, &tid, 8);
244 |
245 | rc = nsGetApplicationControlData(1, tid, control, sizeof(NsApplicationControlData), &outsize);
246 | if (R_FAILED(rc))
247 | {
248 | fatalSimple(MAKERESULT(Module_Discord, Error_GetControlData));
249 | }
250 |
251 | if(outsize < CONTROL_NACP_SIZE)
252 | {
253 | fatalSimple(MAKERESULT(Module_Discord, Error_InvalidControlSize));
254 | }
255 |
256 | SendBuffer(socket, control, sizeof(NsApplicationControlData));
257 |
258 | delete control;
259 | }
260 |
261 | void StartReceiving(int client)
262 | {
263 | //initialise ns
264 | Result rc = nsInitialize();
265 | if (R_FAILED(rc))
266 | fatalSimple(MAKERESULT(789, Error_InitNS));
267 |
268 | //initialise acc
269 | rc = accountInitialize();
270 | if (R_FAILED(rc))
271 | fatalSimple(MAKERESULT(789, Error_InitACC));
272 |
273 | //initialise pm:dmnt
274 | rc = pmdmntInitialize();
275 | if (R_FAILED(rc))
276 | fatalSimple(MAKERESULT(789, Error_InitPMDMNT));
277 |
278 | //initialise pm:info
279 | rc = pminfoInitialize();
280 | if (R_FAILED(rc))
281 | fatalSimple(MAKERESULT(789, Error_InitPMINFO));
282 |
283 | ClientCommand cmd_id;
284 | while(true)
285 | {
286 | cmd_id = ReceiveCommand(client);
287 |
288 | switch (cmd_id)
289 | {
290 | case ClientCommand::GetControlData:
291 | SendControlData(client);
292 | break;
293 | case ClientCommand::ListApps:
294 | SendAppList(client);
295 | break;
296 | case ClientCommand::GetActiveUser:
297 | SendActiveUser(client);
298 | break;
299 | case ClientCommand::GetCurrentApp:
300 | SendCurrentApp(client);
301 | break;
302 | case ClientCommand::GetVersion:
303 | SendVersion(client);
304 | break;
305 | case ClientCommand::Disconnect:
306 | goto exit_receiving;
307 | default:
308 | break;
309 | }
310 | }
311 |
312 | exit_receiving:
313 | nsExit();
314 | accountExit();
315 | pmdmntExit();
316 | pminfoExit();
317 | }
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/DiscordRpc.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SwitchRichPresence
8 | {
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Runtime.InteropServices;
12 | using System.Text;
13 |
14 | public class DiscordRpc
15 | {
16 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
17 | public delegate void ReadyCallback();
18 |
19 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
20 | public delegate void DisconnectedCallback(int errorCode, string message);
21 |
22 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
23 | public delegate void ErrorCallback(int errorCode, string message);
24 |
25 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
26 | public delegate void JoinCallback(string secret);
27 |
28 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29 | public delegate void SpectateCallback(string secret);
30 |
31 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32 | public delegate void RequestCallback(ref JoinRequest request);
33 |
34 | public struct EventHandlers
35 | {
36 | public ReadyCallback readyCallback;
37 | public DisconnectedCallback disconnectedCallback;
38 | public ErrorCallback errorCallback;
39 | public JoinCallback joinCallback;
40 | public SpectateCallback spectateCallback;
41 | public RequestCallback requestCallback;
42 | }
43 |
44 | [Serializable, StructLayout(LayoutKind.Sequential)]
45 | public struct RichPresenceStruct
46 | {
47 | public IntPtr state; /* max 128 bytes */
48 | public IntPtr details; /* max 128 bytes */
49 | public long startTimestamp;
50 | public long endTimestamp;
51 | public IntPtr largeImageKey; /* max 32 bytes */
52 | public IntPtr largeImageText; /* max 128 bytes */
53 | public IntPtr smallImageKey; /* max 32 bytes */
54 | public IntPtr smallImageText; /* max 128 bytes */
55 | public IntPtr partyId; /* max 128 bytes */
56 | public int partySize;
57 | public int partyMax;
58 | public IntPtr matchSecret; /* max 128 bytes */
59 | public IntPtr joinSecret; /* max 128 bytes */
60 | public IntPtr spectateSecret; /* max 128 bytes */
61 | public bool instance;
62 | }
63 |
64 | [Serializable]
65 | public struct JoinRequest
66 | {
67 | public string userId;
68 | public string username;
69 | public string discriminator;
70 | public string avatar;
71 | }
72 |
73 | public enum Reply
74 | {
75 | No = 0,
76 | Yes = 1,
77 | Ignore = 2
78 | }
79 |
80 | [DllImport("discord-rpc", EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
81 | public static extern void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
82 |
83 | [DllImport("discord-rpc", EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)]
84 | public static extern void Shutdown();
85 |
86 | [DllImport("discord-rpc", EntryPoint = "Discord_RunCallbacks", CallingConvention = CallingConvention.Cdecl)]
87 | public static extern void RunCallbacks();
88 |
89 | [DllImport("discord-rpc", EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
90 | private static extern void UpdatePresenceNative(ref RichPresenceStruct presence);
91 |
92 | [DllImport("discord-rpc", EntryPoint = "Discord_ClearPresence", CallingConvention = CallingConvention.Cdecl)]
93 | public static extern void ClearPresence();
94 |
95 | [DllImport("discord-rpc", EntryPoint = "Discord_Respond", CallingConvention = CallingConvention.Cdecl)]
96 | public static extern void Respond(string userId, Reply reply);
97 |
98 | public static void UpdatePresence(RichPresence presence)
99 | {
100 | var presencestruct = presence.GetStruct();
101 | UpdatePresenceNative(ref presencestruct);
102 | presence.FreeMem();
103 | }
104 |
105 | public class RichPresence
106 | {
107 | private RichPresenceStruct _presence;
108 | private readonly List _buffers = new List(10);
109 |
110 | public string state; /* max 128 bytes */
111 | public string details; /* max 128 bytes */
112 | public long startTimestamp;
113 | public long endTimestamp;
114 | public string largeImageKey; /* max 32 bytes */
115 | public string largeImageText; /* max 128 bytes */
116 | public string smallImageKey; /* max 32 bytes */
117 | public string smallImageText; /* max 128 bytes */
118 | public string partyId; /* max 128 bytes */
119 | public int partySize;
120 | public int partyMax;
121 | public string matchSecret; /* max 128 bytes */
122 | public string joinSecret; /* max 128 bytes */
123 | public string spectateSecret; /* max 128 bytes */
124 | public bool instance;
125 |
126 | ///
127 | /// Get the reprensentation of this instance
128 | ///
129 | /// reprensentation of this instance
130 | internal RichPresenceStruct GetStruct()
131 | {
132 | if (_buffers.Count > 0)
133 | {
134 | FreeMem();
135 | }
136 |
137 | _presence.state = StrToPtr(state, 128);
138 | _presence.details = StrToPtr(details, 128);
139 | _presence.startTimestamp = startTimestamp;
140 | _presence.endTimestamp = endTimestamp;
141 | _presence.largeImageKey = StrToPtr(largeImageKey, 32);
142 | _presence.largeImageText = StrToPtr(largeImageText, 128);
143 | _presence.smallImageKey = StrToPtr(smallImageKey, 32);
144 | _presence.smallImageText = StrToPtr(smallImageText, 128);
145 | _presence.partyId = StrToPtr(partyId, 128);
146 | _presence.partySize = partySize;
147 | _presence.partyMax = partyMax;
148 | _presence.matchSecret = StrToPtr(matchSecret, 128);
149 | _presence.joinSecret = StrToPtr(joinSecret, 128);
150 | _presence.spectateSecret = StrToPtr(spectateSecret, 128);
151 | _presence.instance = instance;
152 |
153 | return _presence;
154 | }
155 |
156 | ///
157 | /// Returns a pointer to a representation of the given string with a size of maxbytes
158 | ///
159 | /// String to convert
160 | /// Max number of bytes to use
161 | /// Pointer to the UTF-8 representation of
162 | private IntPtr StrToPtr(string input, int maxbytes)
163 | {
164 | if (string.IsNullOrEmpty(input)) return IntPtr.Zero;
165 | var convstr = StrClampBytes(input, maxbytes);
166 | var convbytecnt = Encoding.UTF8.GetByteCount(convstr);
167 | var buffer = Marshal.AllocHGlobal(convbytecnt);
168 | _buffers.Add(buffer);
169 | Marshal.Copy(Encoding.UTF8.GetBytes(convstr), 0, buffer, convbytecnt);
170 | return buffer;
171 | }
172 |
173 | ///
174 | /// Convert string to UTF-8 and add null termination
175 | ///
176 | /// string to convert
177 | /// UTF-8 representation of with added null termination
178 | private static string StrToUtf8NullTerm(string toconv)
179 | {
180 | var str = toconv.Trim();
181 | var bytes = Encoding.Default.GetBytes(str);
182 | if (bytes.Length > 0 && bytes[bytes.Length - 1] != 0)
183 | {
184 | str += "\0\0";
185 | }
186 | return Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(str));
187 | }
188 |
189 | ///
190 | /// Clamp the string to the given byte length preserving null termination
191 | ///
192 | /// string to clamp
193 | /// max bytes the resulting string should have (including null termination)
194 | /// null terminated string with a byte length less or equal to
195 | private static string StrClampBytes(string toclamp, int maxbytes)
196 | {
197 | var str = StrToUtf8NullTerm(toclamp);
198 | var strbytes = Encoding.UTF8.GetBytes(str);
199 |
200 | if (strbytes.Length <= maxbytes)
201 | {
202 | return str;
203 | }
204 |
205 | var newstrbytes = new byte[] { };
206 | Array.Copy(strbytes, 0, newstrbytes, 0, maxbytes - 1);
207 | newstrbytes[newstrbytes.Length - 1] = 0;
208 | newstrbytes[newstrbytes.Length - 2] = 0;
209 |
210 | return Encoding.UTF8.GetString(newstrbytes);
211 | }
212 |
213 | ///
214 | /// Free the allocated memory for conversion to
215 | ///
216 | internal void FreeMem()
217 | {
218 | for (var i = _buffers.Count - 1; i >= 0; i--)
219 | {
220 | Marshal.FreeHGlobal(_buffers[i]);
221 | _buffers.RemoveAt(i);
222 | }
223 | }
224 | }
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/Forms/MainForm.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SwitchRichPresence
2 | {
3 | partial class MainForm
4 | {
5 | ///
6 | /// Variable nécessaire au concepteur.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Nettoyage des ressources utilisées.
12 | ///
13 | /// true si les ressources managées doivent être supprimées ; sinon, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Code généré par le Concepteur Windows Form
24 |
25 | ///
26 | /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
27 | /// le contenu de cette méthode avec l'éditeur de code.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
32 | this.pictureBox_icon = new System.Windows.Forms.PictureBox();
33 | this.textBox_ip = new System.Windows.Forms.TextBox();
34 | this.label1 = new System.Windows.Forms.Label();
35 | this.button_connect = new System.Windows.Forms.Button();
36 | this.label2 = new System.Windows.Forms.Label();
37 | this.label_game = new System.Windows.Forms.Label();
38 | this.menuStrip1 = new System.Windows.Forms.MenuStrip();
39 | this.utilsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
40 | this.exportIconsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
41 | this.checkBox_showUser = new System.Windows.Forms.CheckBox();
42 | this.checkBox_showTime = new System.Windows.Forms.CheckBox();
43 | this.linkLabel1 = new System.Windows.Forms.LinkLabel();
44 | this.label3 = new System.Windows.Forms.Label();
45 | this.textBox_clientId = new System.Windows.Forms.TextBox();
46 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox_icon)).BeginInit();
47 | this.menuStrip1.SuspendLayout();
48 | this.SuspendLayout();
49 | //
50 | // pictureBox_icon
51 | //
52 | this.pictureBox_icon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
53 | this.pictureBox_icon.Location = new System.Drawing.Point(12, 146);
54 | this.pictureBox_icon.Name = "pictureBox_icon";
55 | this.pictureBox_icon.Size = new System.Drawing.Size(100, 100);
56 | this.pictureBox_icon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
57 | this.pictureBox_icon.TabIndex = 0;
58 | this.pictureBox_icon.TabStop = false;
59 | //
60 | // textBox_ip
61 | //
62 | this.textBox_ip.Location = new System.Drawing.Point(88, 53);
63 | this.textBox_ip.Name = "textBox_ip";
64 | this.textBox_ip.Size = new System.Drawing.Size(118, 20);
65 | this.textBox_ip.TabIndex = 1;
66 | //
67 | // label1
68 | //
69 | this.label1.AutoSize = true;
70 | this.label1.Location = new System.Drawing.Point(65, 56);
71 | this.label1.Name = "label1";
72 | this.label1.Size = new System.Drawing.Size(23, 13);
73 | this.label1.TabIndex = 2;
74 | this.label1.Text = "IP :";
75 | //
76 | // button_connect
77 | //
78 | this.button_connect.Location = new System.Drawing.Point(98, 77);
79 | this.button_connect.Name = "button_connect";
80 | this.button_connect.Size = new System.Drawing.Size(75, 23);
81 | this.button_connect.TabIndex = 3;
82 | this.button_connect.Text = "Connect";
83 | this.button_connect.UseVisualStyleBackColor = true;
84 | this.button_connect.Click += new System.EventHandler(this.button_connect_Click);
85 | //
86 | // label2
87 | //
88 | this.label2.AutoSize = true;
89 | this.label2.Location = new System.Drawing.Point(118, 146);
90 | this.label2.Name = "label2";
91 | this.label2.Size = new System.Drawing.Size(47, 13);
92 | this.label2.TabIndex = 4;
93 | this.label2.Text = "Playing :";
94 | //
95 | // label_game
96 | //
97 | this.label_game.AutoSize = true;
98 | this.label_game.Location = new System.Drawing.Point(118, 163);
99 | this.label_game.Name = "label_game";
100 | this.label_game.Size = new System.Drawing.Size(16, 13);
101 | this.label_game.TabIndex = 5;
102 | this.label_game.Text = "...";
103 | //
104 | // menuStrip1
105 | //
106 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
107 | this.utilsToolStripMenuItem});
108 | this.menuStrip1.Location = new System.Drawing.Point(0, 0);
109 | this.menuStrip1.Name = "menuStrip1";
110 | this.menuStrip1.Size = new System.Drawing.Size(270, 24);
111 | this.menuStrip1.TabIndex = 6;
112 | this.menuStrip1.Text = "menuStrip1";
113 | //
114 | // utilsToolStripMenuItem
115 | //
116 | this.utilsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
117 | this.exportIconsToolStripMenuItem});
118 | this.utilsToolStripMenuItem.Name = "utilsToolStripMenuItem";
119 | this.utilsToolStripMenuItem.Size = new System.Drawing.Size(42, 20);
120 | this.utilsToolStripMenuItem.Text = "Utils";
121 | this.utilsToolStripMenuItem.Visible = false;
122 | //
123 | // exportIconsToolStripMenuItem
124 | //
125 | this.exportIconsToolStripMenuItem.Name = "exportIconsToolStripMenuItem";
126 | this.exportIconsToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
127 | this.exportIconsToolStripMenuItem.Text = "Export icons";
128 | this.exportIconsToolStripMenuItem.Click += new System.EventHandler(this.exportIconsToolStripMenuItem_Click);
129 | //
130 | // checkBox_showUser
131 | //
132 | this.checkBox_showUser.AutoSize = true;
133 | this.checkBox_showUser.Checked = true;
134 | this.checkBox_showUser.CheckState = System.Windows.Forms.CheckState.Checked;
135 | this.checkBox_showUser.Location = new System.Drawing.Point(12, 108);
136 | this.checkBox_showUser.Name = "checkBox_showUser";
137 | this.checkBox_showUser.Size = new System.Drawing.Size(119, 17);
138 | this.checkBox_showUser.TabIndex = 7;
139 | this.checkBox_showUser.Text = "Show selected user";
140 | this.checkBox_showUser.UseVisualStyleBackColor = true;
141 | this.checkBox_showUser.CheckedChanged += new System.EventHandler(this.checkBox_showUser_CheckedChanged);
142 | //
143 | // checkBox_showTime
144 | //
145 | this.checkBox_showTime.AutoSize = true;
146 | this.checkBox_showTime.Checked = true;
147 | this.checkBox_showTime.CheckState = System.Windows.Forms.CheckState.Checked;
148 | this.checkBox_showTime.Location = new System.Drawing.Point(12, 124);
149 | this.checkBox_showTime.Name = "checkBox_showTime";
150 | this.checkBox_showTime.Size = new System.Drawing.Size(78, 17);
151 | this.checkBox_showTime.TabIndex = 8;
152 | this.checkBox_showTime.Text = "Show timer";
153 | this.checkBox_showTime.UseVisualStyleBackColor = true;
154 | this.checkBox_showTime.CheckedChanged += new System.EventHandler(this.checkBox_showTime_CheckedChanged);
155 | //
156 | // linkLabel1
157 | //
158 | this.linkLabel1.AutoSize = true;
159 | this.linkLabel1.Location = new System.Drawing.Point(231, 242);
160 | this.linkLabel1.Name = "linkLabel1";
161 | this.linkLabel1.Size = new System.Drawing.Size(35, 13);
162 | this.linkLabel1.TabIndex = 9;
163 | this.linkLabel1.TabStop = true;
164 | this.linkLabel1.Text = "About";
165 | this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
166 | //
167 | // label3
168 | //
169 | this.label3.AutoSize = true;
170 | this.label3.Location = new System.Drawing.Point(35, 35);
171 | this.label3.Name = "label3";
172 | this.label3.Size = new System.Drawing.Size(53, 13);
173 | this.label3.TabIndex = 11;
174 | this.label3.Text = "Client ID :";
175 | //
176 | // textBox_clientId
177 | //
178 | this.textBox_clientId.Location = new System.Drawing.Point(88, 32);
179 | this.textBox_clientId.Name = "textBox_clientId";
180 | this.textBox_clientId.Size = new System.Drawing.Size(118, 20);
181 | this.textBox_clientId.TabIndex = 10;
182 | //
183 | // MainForm
184 | //
185 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
186 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
187 | this.ClientSize = new System.Drawing.Size(270, 262);
188 | this.Controls.Add(this.label3);
189 | this.Controls.Add(this.textBox_clientId);
190 | this.Controls.Add(this.linkLabel1);
191 | this.Controls.Add(this.checkBox_showTime);
192 | this.Controls.Add(this.checkBox_showUser);
193 | this.Controls.Add(this.label_game);
194 | this.Controls.Add(this.label2);
195 | this.Controls.Add(this.button_connect);
196 | this.Controls.Add(this.label1);
197 | this.Controls.Add(this.textBox_ip);
198 | this.Controls.Add(this.pictureBox_icon);
199 | this.Controls.Add(this.menuStrip1);
200 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
201 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
202 | this.MainMenuStrip = this.menuStrip1;
203 | this.MaximizeBox = false;
204 | this.Name = "MainForm";
205 | this.Text = "Sys-Discord Client";
206 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
207 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox_icon)).EndInit();
208 | this.menuStrip1.ResumeLayout(false);
209 | this.menuStrip1.PerformLayout();
210 | this.ResumeLayout(false);
211 | this.PerformLayout();
212 |
213 | }
214 |
215 | #endregion
216 |
217 | private System.Windows.Forms.PictureBox pictureBox_icon;
218 | private System.Windows.Forms.TextBox textBox_ip;
219 | private System.Windows.Forms.Label label1;
220 | private System.Windows.Forms.Button button_connect;
221 | private System.Windows.Forms.Label label2;
222 | private System.Windows.Forms.Label label_game;
223 | private System.Windows.Forms.MenuStrip menuStrip1;
224 | private System.Windows.Forms.ToolStripMenuItem utilsToolStripMenuItem;
225 | private System.Windows.Forms.ToolStripMenuItem exportIconsToolStripMenuItem;
226 | private System.Windows.Forms.CheckBox checkBox_showUser;
227 | private System.Windows.Forms.CheckBox checkBox_showTime;
228 | private System.Windows.Forms.LinkLabel linkLabel1;
229 | private System.Windows.Forms.Label label3;
230 | private System.Windows.Forms.TextBox textBox_clientId;
231 | }
232 | }
233 |
234 |
--------------------------------------------------------------------------------
/SwitchRichPresence/SwitchRichPresence/FolderSelectDialog.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.Reflection;
3 |
4 | namespace System.Windows.Forms
5 | {
6 | ///
7 | /// Wraps System.Windows.Forms.OpenFileDialog to make it present
8 | /// a vista-style dialog.
9 | ///
10 | [EditorBrowsable(EditorBrowsableState.Never)]
11 | [Browsable(false)]
12 | [DesignTimeVisible(false)]
13 | public partial class FolderSelectDialog : Component
14 | {
15 | // Wrapped dialog
16 | System.Windows.Forms.OpenFileDialog ofd = null;
17 |
18 | ///
19 | /// Default constructor
20 | ///
21 | public FolderSelectDialog()
22 | {
23 | ofd = new System.Windows.Forms.OpenFileDialog();
24 |
25 | ofd.Filter = "Folders|\n";
26 | ofd.AddExtension = false;
27 | ofd.CheckFileExists = false;
28 | ofd.DereferenceLinks = true;
29 | ofd.Multiselect = false;
30 | }
31 |
32 | #region Properties
33 |
34 | ///
35 | /// Gets/Sets the initial folder to be selected. A null value selects the current directory.
36 | ///
37 | public string InitialDirectory
38 | {
39 | get { return ofd.InitialDirectory; }
40 | set { ofd.InitialDirectory = value == null || value.Length == 0 ? Environment.CurrentDirectory : value; }
41 | }
42 |
43 | ///
44 | /// Gets/Sets the title to show in the dialog
45 | ///
46 | public string Title
47 | {
48 | get { return ofd.Title; }
49 | set { ofd.Title = value == null ? "Select a folder" : value; }
50 | }
51 |
52 | ///
53 | /// Gets the selected folder
54 | ///
55 | public string SelectedPath
56 | {
57 | get { return ofd.FileName; }
58 | }
59 |
60 | #endregion
61 |
62 | #region Methods
63 |
64 | ///
65 | /// Shows the dialog
66 | ///
67 | /// DialogResult.OK if user presses OK, else DialogResult.Cancel
68 | public DialogResult ShowDialog()
69 | {
70 | return ShowDialog(IntPtr.Zero);
71 | }
72 |
73 | ///
74 | /// Shows the dialog
75 | ///
76 | /// Handle of the control to be parent
77 | /// DialogResult.OK if user presses OK, else DialogResult.Cancel
78 | public DialogResult ShowDialog(IntPtr hWndOwner)
79 | {
80 | bool flag = false;
81 |
82 | if (Environment.OSVersion.Version.Major >= 6)
83 | {
84 | var r = new Reflector("System.Windows.Forms");
85 |
86 | uint num = 0;
87 | Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
88 | object dialog = r.Call(ofd, "CreateVistaDialog");
89 | r.Call(ofd, "OnBeforeVistaDialog", dialog);
90 |
91 | uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions");
92 | options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
93 | r.CallAs(typeIFileDialog, dialog, "SetOptions", options);
94 |
95 | object pfde = r.New("FileDialog.VistaDialogEvents", ofd);
96 | object[] parameters = new object[] { pfde, num };
97 | r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
98 | num = (uint)parameters[1];
99 | try
100 | {
101 | int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner);
102 | flag = 0 == num2;
103 | }
104 | finally
105 | {
106 | r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
107 | GC.KeepAlive(pfde);
108 | }
109 | }
110 | else
111 | {
112 | var fbd = new FolderBrowserDialog();
113 | fbd.Description = this.Title;
114 | fbd.SelectedPath = this.InitialDirectory;
115 | fbd.ShowNewFolderButton = false;
116 | if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) return DialogResult.Cancel;
117 | ofd.FileName = fbd.SelectedPath;
118 | flag = true;
119 | }
120 |
121 | return flag ? DialogResult.OK : DialogResult.Cancel;
122 | }
123 |
124 | #endregion
125 | }
126 |
127 | ///
128 | /// Creates IWin32Window around an IntPtr
129 | ///
130 | public class WindowWrapper : System.Windows.Forms.IWin32Window
131 | {
132 | ///
133 | /// Constructor
134 | ///
135 | /// Handle to wrap
136 | public WindowWrapper(IntPtr handle)
137 | {
138 | _hwnd = handle;
139 | }
140 |
141 | ///
142 | /// Original ptr
143 | ///
144 | public IntPtr Handle
145 | {
146 | get { return _hwnd; }
147 | }
148 |
149 | private IntPtr _hwnd;
150 | }
151 |
152 | ///
153 | /// This class is from the Front-End for Dosbox and is used to present a 'vista' dialog box to select folders.
154 | /// Being able to use a vista style dialog box to select folders is much better then using the shell folder browser.
155 | /// http://code.google.com/p/fed/
156 | ///
157 | /// Example:
158 | /// var r = new Reflector("System.Windows.Forms");
159 | ///
160 | public class Reflector
161 | {
162 | #region variables
163 |
164 | string m_ns;
165 | Assembly m_asmb;
166 |
167 | #endregion
168 |
169 | #region Constructors
170 |
171 | ///
172 | /// Constructor
173 | ///
174 | /// The namespace containing types to be used
175 | public Reflector(string ns)
176 | : this(ns, ns)
177 | { }
178 |
179 | ///
180 | /// Constructor
181 | ///
182 | /// A specific assembly name (used if the assembly name does not tie exactly with the namespace)
183 | /// The namespace containing types to be used
184 | public Reflector(string an, string ns)
185 | {
186 | m_ns = ns;
187 | m_asmb = null;
188 | foreach (AssemblyName aN in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
189 | {
190 | if (aN.FullName.StartsWith(an))
191 | {
192 | m_asmb = Assembly.Load(aN);
193 | break;
194 | }
195 | }
196 | }
197 |
198 | #endregion
199 |
200 | #region Methods
201 |
202 | ///
203 | /// Return a Type instance for a type 'typeName'
204 | ///
205 | /// The name of the type
206 | /// A type instance
207 | public Type GetType(string typeName)
208 | {
209 | Type type = null;
210 | string[] names = typeName.Split('.');
211 |
212 | if (names.Length > 0)
213 | type = m_asmb.GetType(m_ns + "." + names[0]);
214 |
215 | for (int i = 1; i < names.Length; ++i)
216 | {
217 | type = type.GetNestedType(names[i], BindingFlags.NonPublic);
218 | }
219 | return type;
220 | }
221 |
222 | ///
223 | /// Create a new object of a named type passing along any params
224 | ///
225 | /// The name of the type to create
226 | ///
227 | /// An instantiated type
228 | public object New(string name, params object[] parameters)
229 | {
230 | Type type = GetType(name);
231 |
232 | ConstructorInfo[] ctorInfos = type.GetConstructors();
233 | foreach (ConstructorInfo ci in ctorInfos)
234 | {
235 | try
236 | {
237 | return ci.Invoke(parameters);
238 | }
239 | catch { }
240 | }
241 |
242 | return null;
243 | }
244 |
245 | ///
246 | /// Calls method 'func' on object 'obj' passing parameters 'parameters'
247 | ///
248 | /// The object on which to excute function 'func'
249 | /// The function to execute
250 | /// The parameters to pass to function 'func'
251 | /// The result of the function invocation
252 | public object Call(object obj, string func, params object[] parameters)
253 | {
254 | return Call2(obj, func, parameters);
255 | }
256 |
257 | ///
258 | /// Calls method 'func' on object 'obj' passing parameters 'parameters'
259 | ///
260 | /// The object on which to excute function 'func'
261 | /// The function to execute
262 | /// The parameters to pass to function 'func'
263 | /// The result of the function invocation
264 | public object Call2(object obj, string func, object[] parameters)
265 | {
266 | return CallAs2(obj.GetType(), obj, func, parameters);
267 | }
268 |
269 | ///
270 | /// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters'
271 | ///
272 | /// The type of 'obj'
273 | /// The object on which to excute function 'func'
274 | /// The function to execute
275 | /// The parameters to pass to function 'func'
276 | /// The result of the function invocation
277 | public object CallAs(Type type, object obj, string func, params object[] parameters)
278 | {
279 | return CallAs2(type, obj, func, parameters);
280 | }
281 |
282 | ///
283 | /// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters'
284 | ///
285 | /// The type of 'obj'
286 | /// The object on which to excute function 'func'
287 | /// The function to execute
288 | /// The parameters to pass to function 'func'
289 | /// The result of the function invocation
290 | public object CallAs2(Type type, object obj, string func, object[] parameters)
291 | {
292 | MethodInfo methInfo = type.GetMethod(func, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
293 | return methInfo.Invoke(obj, parameters);
294 | }
295 |
296 | ///
297 | /// Returns the value of property 'prop' of object 'obj'
298 | ///
299 | /// The object containing 'prop'
300 | /// The property name
301 | /// The property value
302 | public object Get(object obj, string prop)
303 | {
304 | return GetAs(obj.GetType(), obj, prop);
305 | }
306 |
307 | ///
308 | /// Returns the value of property 'prop' of object 'obj' which has type 'type'
309 | ///
310 | /// The type of 'obj'
311 | /// The object containing 'prop'
312 | /// The property name
313 | /// The property value
314 | public static object GetAs(Type type, object obj, string prop)
315 | {
316 | PropertyInfo propInfo = type.GetProperty(prop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
317 | return propInfo.GetValue(obj, null);
318 | }
319 |
320 | ///
321 | /// Returns an enum value
322 | ///
323 | /// The name of enum type
324 | /// The name of the value
325 | /// The enum value
326 | public object GetEnum(string typeName, string name)
327 | {
328 | Type type = GetType(typeName);
329 | FieldInfo fieldInfo = type.GetField(name);
330 | return fieldInfo.GetValue(null);
331 | }
332 |
333 | #endregion
334 |
335 | }
336 | }
337 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------