Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
generated fromSokuDev/ModTemplate

Commit7f5b70e

Browse files
committed
Initial commit
0 parents  commit7f5b70e

File tree

10 files changed

+359
-0
lines changed

10 files changed

+359
-0
lines changed

‎.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# IDE stuff
35+
.idea
36+
.vs
37+
38+
# Build directories
39+
cmake-build-*
40+
build

‎.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "SokuLib"]
2+
path=SokuLib
3+
url=https://github.com/SokuDev/SokuLib

‎CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cmake_minimum_required(VERSION3.15)
2+
cmake_policy(SETCMP0091NEW)
3+
set(PROJECT_NAMESaveRep)
4+
project("${PROJECT_NAME}"CCXX)
5+
6+
set(CMAKE_C_STANDARD11)
7+
set(CMAKE_CXX_STANDARD17)
8+
9+
set(CMAKE_INSTALL_PREFIX"${CMAKE_CURRENT_BINARY_DIR}/install")
10+
set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreaded$<$<CONFIG:Debug>:Debug>")
11+
12+
add_definitions(-DWINVER=0x0501-D_WIN32_WINNT=0x0501)
13+
if ("${CMAKE_CXX_COMPILER_ID}"STREQUAL"Clang"AND"${CMAKE_CXX_SIMULATE_ID}"STREQUAL"MSVC")
14+
SET(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS} -Wno-c++11-narrowing -Wno-microsoft-cast")
15+
endif ()
16+
SET(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS} /Brepro")
17+
SET(CMAKE_MODULE_LINKER_FLAGS"${CMAKE_MODULE_LINKER_FLAGS} /Brepro")
18+
SET(CMAKE_SHARED_LINKER_FLAGS"${CMAKE_SHARED_LINKER_FLAGS} /Brepro")
19+
20+
# SokuLib
21+
add_subdirectory(SokuLib)
22+
23+
# Module
24+
add_library(
25+
"${PROJECT_NAME}"
26+
MODULE
27+
src/main.cpp
28+
src/version.rc
29+
)
30+
target_compile_options("${PROJECT_NAME}"PRIVATE/Zi)
31+
target_compile_definitions("${PROJECT_NAME}"PRIVATEDIRECTINPUT_VERSION=0x0800CURL_STATICLIB_CRT_SECURE_NO_WARNINGS$<$<CONFIG:Debug>:_DEBUG>)
32+
target_link_directories("${PROJECT_NAME}"PRIVATElib)
33+
target_link_libraries(
34+
"${PROJECT_NAME}"
35+
SokuLib
36+
)

‎LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 SokuDev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#SaveRep mod for Touhou Hisoutensoku
2+
3+
This mod is to save replay when in one of the following situations:
4+
5+
- the user is p1 or p2 in network battle, and:
6+
- p1 or p2 presses ESC to end the game, or
7+
- the game ends before one of the players wins because of desync, or
8+
- the connection is lost
9+
- the user is spectating, and:
10+
- the user presses ESC to stop spectating, or
11+
- the connection is lost
12+
13+
##Build
14+
Requires CMake, git and the VisualStudio compiler (MSVC).
15+
Both git and cmake needs to be in the PATH environment variable.
16+
17+
All the following commands are to be run inside the visual studio 32bits compiler
18+
command prompt (called`x86 Native Tools Command Prompt for VS 20XX` in the start menu), unless stated otherwise.
19+
20+
##Initialization
21+
First go inside the folder you want the repository to be in.
22+
In this example it will be C:\Users\PinkySmile\SokuProjects but remember to replace this
23+
with the path for your machine. If you don't want to type the full path, you can drag and
24+
drop the folder onto the console.
25+
26+
`cd C:\Users\PinkySmile\SokuProjects`
27+
28+
Now let's download the repository and initialize it for the first time
29+
```
30+
git clone https://github.com/Hagb/SaveRep
31+
cd SaveRep
32+
git submodule init
33+
git submodule update
34+
mkdir build
35+
cd build
36+
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug
37+
```
38+
Note that if you want to build in Release, you should replace`-DCMAKE_BUILD_TYPE=Debug` with`-DCMAKE_BUILD_TYPE=Release`.
39+
40+
##Compiling
41+
Now, to build the mod, go to the build directory (if you did the previous step you already are)
42+
`cd C:\Users\PinkySmile\SokuProjects\SaveRep\build` and invoke the compiler by running`cmake --build . --target SaveRep`. If you change the name of the mod (in the add_library statement in CMakeLists.txt), you will need to replace 'SaveRep' by the name of your mod in the previous command.
43+
44+
You should find the resulting SaveRep.dll mod inside the build folder that can be to SWRSToys.ini.
45+
In my case, I would add this line to it`SaveRep=C:/Users/PinkySmile/SokuProjects/SaveRep/build/SaveRep.dll`.

‎SokuLib

SubmoduleSokuLib added ata2372ee

‎lib/d3d9.lib

5.09 KB
Binary file not shown.

‎lib/d3dx9.lib

85.5 KB
Binary file not shown.

‎src/main.cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// Created by PinkySmile on 31/10/2020
3+
//
4+
5+
// #include <SokuLib.hpp>
6+
// clang-format off
7+
8+
#include<string>
9+
#include<type_traits>
10+
// clang-format on
11+
#include"BattleManager.hpp"
12+
#include"BattleMode.hpp"
13+
#include"InputManager.hpp"
14+
#include<iostream>
15+
// #include "Net"
16+
#include"Hash.hpp"
17+
#include"NetObject.hpp"
18+
#include"Scenes.hpp"
19+
#include"Tamper.hpp"
20+
#include"VTables.hpp"
21+
22+
staticint/*SokuLib::Scene*/ (SokuLib::BattleWatch::*ogBattleWatchOnProcess)();
23+
staticint/*SokuLib::Scene*/ (SokuLib::BattleClient::*ogBattleClientOnProcess)();
24+
staticint/*SokuLib::Scene*/ (SokuLib::BattleServer::*ogBattleServerOnProcess)();
25+
staticconstauto spectatingSaveReplayIfAllow = (void(__thiscall *)(SokuLib::NetObject *))(0x454240);
26+
staticconstauto battleSaveReplay = (void (*)())(0x43ebe0);
27+
staticconstauto get00899840 = (char *(*)())(0x0043df40);
28+
// static const auto getReplayPath
29+
// = (void(__thiscall *)(SokuLib::InputManager *, char *replay_path, const char *profile1name, const char *profile2name))(0x42cb30);
30+
// static const auto writeReplay = (void(__thiscall *)(SokuLib::InputManager *, const char *path))(0x42b2d0);
31+
32+
staticint/*SokuLib::Scene*/ __fastcallCBattleWatch_OnProcess(SokuLib::BattleWatch *This) {
33+
int ret = (This->*ogBattleWatchOnProcess)();
34+
if (ret == SokuLib::SCENE_TITLE) {
35+
std::cout <<"Disconnect when spectating. Save replay if allowed." << std::endl;
36+
spectatingSaveReplayIfAllow(&SokuLib::getNetObject());
37+
}
38+
return ret;
39+
}
40+
41+
staticvoidbattleSaveReplayIfAllow() {
42+
std::cout <<"Save replay if allowed." << std::endl;
43+
switch (get00899840()[0x73]) {
44+
case0:// always save replay
45+
case1:// save replay when as player
46+
battleSaveReplay();
47+
case2:// save replay when as spectator
48+
case3:// never save replay
49+
case4:// always ask
50+
break;
51+
}
52+
}
53+
54+
template<typename T,int (T::**ogBattlePlayOnProcess)()>staticint/*SokuLib::Scene*/ __fastcallCBattlePlay_OnProcess(T *This) {
55+
int ret = (This->**ogBattlePlayOnProcess)();
56+
if (ret == SokuLib::SCENE_TITLE) {
57+
std::cout <<"Disconnect.";
58+
battleSaveReplayIfAllow();
59+
}
60+
return ret;
61+
}
62+
63+
template<SokuLib::Scene retcode>staticvoid__declspec(naked) gameEndTooEarly() {
64+
staticconst SokuLib::Scene retcode_ = retcode;// workaround for the template parameter is unusable in inline asm (why?)
65+
std::cout <<"Esc or desync causes the game ends too early.";
66+
battleSaveReplayIfAllow();
67+
__asm {
68+
pop edi;
69+
mov eax, retcode_;
70+
pop esi;
71+
ret;
72+
}
73+
}
74+
75+
staticvoid__declspec(naked) gameEndTooEarly2() {
76+
staticauto gameEndTooEarlyAddr = gameEndTooEarly<SokuLib::SCENE_SELECTSV>;
77+
staticconstvoid *fun004282d0 = (void *)0x004282d0;
78+
__asm {
79+
call fun004282d0;
80+
jmp gameEndTooEarlyAddr;
81+
}
82+
}
83+
staticvoid__declspec(naked) gameEndTooEarly3() {
84+
staticconstvoid *addr004283a2 = (void *)0x004283a2;
85+
__asm {
86+
push esi;
87+
}
88+
std::cout <<"Esc or desync causes the game ends too early.";
89+
battleSaveReplayIfAllow();
90+
__asm {
91+
pop esi;
92+
cmp [esi+0x6c8],0;
93+
jmp addr004283a2;
94+
}
95+
}
96+
97+
// We check if the game version is what we target (in our case, Soku 1.10a).
98+
extern"C" __declspec(dllexport)boolCheckVersion(const BYTE hash[16]) {
99+
returnmemcmp(hash, SokuLib::targetHash,sizeof(SokuLib::targetHash)) ==0;
100+
}
101+
102+
// Called when the mod loader is ready to initialize this module.
103+
// All hooks should be placed here. It's also a good moment to load settings
104+
// from the ini.
105+
extern"C" __declspec(dllexport)boolInitialize(HMODULE hMyModule, HMODULE hParentModule) {
106+
DWORD old;
107+
108+
#ifdef _DEBUG
109+
FILE *_;
110+
111+
AllocConsole();
112+
freopen_s(&_,"CONOUT$","w", stdout);
113+
freopen_s(&_,"CONOUT$","w", stderr);
114+
#endif
115+
VirtualProtect((PVOID)RDATA_SECTION_OFFSET, RDATA_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
116+
ogBattleWatchOnProcess =SokuLib::TamperDword(&SokuLib::VTable_BattleWatch.onProcess, CBattleWatch_OnProcess);
117+
ogBattleServerOnProcess
118+
=SokuLib::TamperDword(&SokuLib::VTable_BattleServer.onProcess, CBattlePlay_OnProcess<SokuLib::BattleServer, &ogBattleServerOnProcess>);
119+
ogBattleClientOnProcess
120+
=SokuLib::TamperDword(&SokuLib::VTable_BattleClient.onProcess, CBattlePlay_OnProcess<SokuLib::BattleClient, &ogBattleClientOnProcess>);
121+
VirtualProtect((PVOID)RDATA_SECTION_OFFSET, RDATA_SECTION_SIZE, old, &old);
122+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
123+
SokuLib::TamperNearJmp(0x428663, gameEndTooEarly<SokuLib::SCENE_SELECTCL>);
124+
SokuLib::TamperNearJmp(0x428680, gameEndTooEarly<SokuLib::SCENE_SELECTCL>);
125+
SokuLib::TamperNearJmp(0x4283b0, gameEndTooEarly<SokuLib::SCENE_SELECTSV>);
126+
SokuLib::TamperNearJmp(0x42838e, gameEndTooEarly2);
127+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, old, &old);
128+
129+
FlushInstructionCache(GetCurrentProcess(),nullptr,0);
130+
returntrue;
131+
}
132+
133+
extern"C"int APIENTRYDllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved) {
134+
returnTRUE;
135+
}
136+
137+
// New mod loader functions
138+
// Loading priority. Mods are loaded in order by ascending level of priority
139+
// (the highest first). When 2 mods define the same loading priority the loading
140+
// order is undefined.
141+
extern"C" __declspec(dllexport)intgetPriority() {
142+
return0;
143+
}
144+
145+
// Not yet implemented in the mod loader, subject to change
146+
// SokuModLoader::IValue **getConfig();
147+
// void freeConfig(SokuModLoader::IValue **v);
148+
// bool commitConfig(SokuModLoader::IValue *);
149+
// const char *getFailureReason();
150+
// bool hasChainedHooks();
151+
// void unHook();

‎src/version.rc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <windows.h>
2+
#define VER_FILEVERSION 0,1,0,0
3+
#define VER_FILEVERSION_STR "0.1\0"
4+
5+
#define VER_PRODUCTVERSION 0,1,0,0
6+
#define VER_PRODUCTVERSION_STR "0.1\0"
7+
8+
#define VER_COMPANYNAME_STR "SokuDev\0"
9+
#define VER_FILEDESCRIPTION_STR "Mod for Touhou 12.3 to save replay when the battle ends too early (such as esc or desync)\0"
10+
#define VER_INTERNALNAME_STR "SaveRep\0"
11+
#define VER_LEGALCOPYRIGHT_STR "Hagb\0"
12+
#define VER_LEGALTRADEMARKS1_STR "\0"
13+
#define VER_LEGALTRADEMARKS2_STR "\0"
14+
#define VER_ORIGINALFILENAME_STR "SaveRep.dll\0"
15+
#define VER_PRODUCTNAME_STR "SaveRep\0"
16+
17+
// Define this to 0 if not a pre release
18+
#define VER_PRERELEASE VS_FF_PRERELEASE
19+
20+
#ifndef DEBUG
21+
#define VER_DEBUG 0
22+
#else
23+
#define VER_DEBUG VS_FF_DEBUG
24+
#endif
25+
26+
VS_VERSION_INFO VERSIONINFO
27+
FILEVERSION VER_FILEVERSION
28+
PRODUCTVERSION VER_PRODUCTVERSION
29+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
30+
FILEFLAGS (VER_PRERELEASE|VER_DEBUG)
31+
FILEOS VOS__WINDOWS32
32+
FILETYPE VFT_DLL
33+
FILESUBTYPE VFT2_UNKNOWN
34+
BEGIN
35+
BLOCK "StringFileInfo"
36+
BEGIN
37+
BLOCK "040904E4"
38+
BEGIN
39+
VALUE "CompanyName", VER_COMPANYNAME_STR
40+
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
41+
VALUE "FileVersion", VER_FILEVERSION_STR
42+
VALUE "InternalName", VER_INTERNALNAME_STR
43+
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
44+
VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR
45+
VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR
46+
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
47+
VALUE "ProductName", VER_PRODUCTNAME_STR
48+
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
49+
END
50+
END
51+
52+
BLOCK "VarFileInfo"
53+
BEGIN
54+
/* The following line should only be modified for localized versions. */
55+
/* It consists of any number of WORD,WORD pairs, with each pair */
56+
/* describing a language,codepage combination supported by the file. */
57+
/* */
58+
/* For example, a file might have values "0x409,1252" indicating that it */
59+
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
60+
VALUE "Translation", 0x409, 1252
61+
END
62+
END

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp