Browse Source

Init repo

tags/v0.2
Тим 7 months ago
commit
0a82c6da3e
7 changed files with 132 additions and 0 deletions
  1. 9
    0
      .gitmodules
  2. 1
    0
      HOOK-d
  3. 20
    0
      Makefile
  4. 1
    0
      VorbisFile-d
  5. 23
    0
      config.d
  6. 1
    0
      inifiled
  7. 77
    0
      loader.d

+ 9
- 0
.gitmodules View File

@@ -0,0 +1,9 @@
1
+[submodule "inifiled"]
2
+	path = inifiled
3
+	url = https://github.com/burner/inifiled
4
+[submodule "HOOK-d"]
5
+	path = HOOK-d
6
+	url = https://git.prime-hack.net/SR_team/HOOK-d
7
+[submodule "VorbisFile-d"]
8
+	path = VorbisFile-d
9
+	url = https://git.prime-hack.net/AsiLoader/VorbisFile-d

+ 1
- 0
HOOK-d

@@ -0,0 +1 @@
1
+Subproject commit af759eb83f30438c14f3a8817cf9c7d3d1d76d18

+ 20
- 0
Makefile View File

@@ -0,0 +1,20 @@
1
+D=ldc2
2
+PROJECT=VorbisFile
3
+EXT=dll
4
+SOURCES=*.d VorbisFile-d/*.d HOOK-d/*.d inifiled/source/*.d
5
+TARGET=bin
6
+
7
+all: clean build
8
+
9
+build:
10
+	$(D) $(SOURCES) -shared -m32 -Os -of=$(TARGET)/$(PROJECT).$(EXT)
11
+
12
+clean:
13
+	rm -rf $(TARGET)/*.obj
14
+
15
+full-clean: clean
16
+	rm -rf $(TARGET)
17
+	
18
+help:
19
+	@echo "Change variable D, to select compiler."
20
+	@echo "For example compile with dmd: \`make D=dmd\`"

+ 1
- 0
VorbisFile-d

@@ -0,0 +1 @@
1
+Subproject commit 4dd106450cc9ef2f3f2e9beab9f38ab4d0b82d0b

+ 23
- 0
config.d View File

@@ -0,0 +1,23 @@
1
+module config;
2
+
3
+import std.file;
4
+import inifiled;
5
+
6
+@INI("AsiLoader settings", "AsiLoader")
7
+struct stAsiLoader{
8
+	@INI("Enable builtin asi loader") bool enable = true;
9
+};
10
+
11
+@INI("Main settings", "Config")
12
+struct stConfig(string inifile){
13
+	void load(){
14
+		if (inifile.exists && inifile.isFile)
15
+			this.readINIFile(inifile);
16
+	}
17
+	void save(){
18
+		this.writeINIFile(inifile);
19
+	}
20
+	
21
+	@INI("Proxy library for asi loader") string proxy;
22
+	@INI stAsiLoader asiLoader;
23
+};

+ 1
- 0
inifiled

@@ -0,0 +1 @@
1
+Subproject commit cecaff8037a60db2a51c9bded4802c87d938a44e

+ 77
- 0
loader.d View File

@@ -0,0 +1,77 @@
1
+import std.string, std.file;
2
+import core.sys.windows.windows, core.sys.windows.dll, core.runtime;
3
+import hook.call, hook.asm86;
4
+import vorbisfile;
5
+import config;
6
+
7
+alias Callback = extern (C) void function() @nogc nothrow pure @safe;
8
+__gshared static stConfig!"VorbisFile.ini" ini;
9
+
10
+void hook_mainloop()
11
+{
12
+	auto asm86 = new Asm86Hook();
13
+	asm86.pushad;
14
+	asm86.pushfd;
15
+	asm86.call(&mainloop);
16
+	asm86.popfd;
17
+	asm86.popad;
18
+	asm86.insert(0x748DA3, 6);
19
+	asm86.ret;
20
+	call_hook(0x748DA3, 6, cast(void*)asm86.createFunc);
21
+	asm86.destroy;
22
+}
23
+
24
+extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
25
+{
26
+	switch (ulReason)
27
+	{
28
+		case DLL_PROCESS_ATTACH:
29
+			Runtime.initialize();
30
+			hook_mainloop();
31
+			ini.load;
32
+			if (!ini.proxy.empty)
33
+				setVorbisFile(ini.proxy);
34
+			dll_process_attach(hInstance, true);
35
+			break;
36
+		case DLL_PROCESS_DETACH:
37
+			ini.save;
38
+			Runtime.terminate();
39
+			dll_process_detach(hInstance, true);
40
+			break;
41
+		case DLL_THREAD_ATTACH:
42
+			dll_thread_attach(true, true);
43
+			break;
44
+		case DLL_THREAD_DETACH:
45
+			dll_thread_detach(true, true);
46
+			break;
47
+		
48
+		default:
49
+			break;
50
+	}
51
+	return true;
52
+}
53
+
54
+extern(Windows) void mainloop()
55
+{
56
+	__gshared static bool asiLoaded = false;
57
+	__gshared static bool dllLoaded = false;
58
+	
59
+	if (!asiLoaded && ini.asiLoader.enable){
60
+		asiLoaded = true;
61
+		foreach (string plugin; dirEntries(getcwd, "*.asi", SpanMode.shallow))
62
+			LoadLibraryA(plugin.toStringz);
63
+	}
64
+	
65
+	if (!dllLoaded){
66
+		dllLoaded = true;
67
+		if ((getcwd ~ "/plugins").exists && (getcwd ~ "/plugins").isDir){
68
+			foreach (string plugin; dirEntries(getcwd ~ "/plugins", "*.dll", SpanMode.shallow)){
69
+				auto dll = LoadLibraryA(plugin.toStringz);
70
+				auto callback = cast(Callback)GetProcAddress(dll, "load");
71
+				if (!(callback is null))
72
+					callback();
73
+			}
74
+		}
75
+		else (getcwd ~ "/plugins").mkdir;
76
+	}
77
+}

Loading…
Cancel
Save