Skip to content

Instantly share code, notes, and snippets.

@himika
Created April 3, 2015 22:35
Show Gist options
  • Save himika/bb4e4e1e33c873f21023 to your computer and use it in GitHub Desktop.
Save himika/bb4e4e1e33c873f21023 to your computer and use it in GitHub Desktop.
Skyrim 日本語パッチ
/*------------------------------------------------------------------------
Copyright 2013,2014 himika
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------*/
#include <skse.h>
#include <skse/skse_version.h>
#include <skse/PluginAPI.h>
#include <skse/GameAPI.h>
#include <skse/Utilities.h>
#include <skse/SafeWrite.h>
#include <memory>
PluginHandle g_pluginHandle = kPluginHandle_Invalid;
struct _BGSSaveLoadManager
{
void FilterString(char* str)
{
int size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
std::unique_ptr<wchar_t> buff(new wchar_t[size]);
MultiByteToWideChar(CP_UTF8, 0, str, -1, buff.get(), size);
for (wchar_t* p = buff.get(); *p; p++)
{
static const wchar_t ec[] = L",\\/:*;=<>?|\"";
if (wcsrchr(ec, *p))
*p = L' ';
if (iswcntrl(*p))
*p = L' ';
}
size = WideCharToMultiByte(CP_OEMCP, 0, buff.get(), size, str, 260, NULL, NULL);
}
};
char* UTF8_to_OEM(const char* strUTF8)
{
// UTF8 => Unicode
int size;
size = MultiByteToWideChar(CP_OEMCP, 0, strUTF8, -1, NULL, 0);
std::unique_ptr<wchar_t> buff(new wchar_t[size]);
MultiByteToWideChar(CP_OEMCP, 0, strUTF8, -1, buff.get(), size);
// Unicode => OEM
size = WideCharToMultiByte(CP_UTF8, 0, buff.get(), size, NULL, 0, NULL, NULL);
char* strOEM = (char*)FormHeap_Allocate(size);
WideCharToMultiByte(CP_UTF8, 0, buff.get(), size, strOEM, size, NULL, NULL);
return strOEM;
}
void __declspec(naked) Hook_00677953(void)
{
static const UInt32 addr = 0x00677985;
__asm
{
mov edx, dword ptr [esi]
push edx
call UTF8_to_OEM
add esp, 4
mov dword ptr [esi+0x0C], eax
jmp addr
}
}
extern "C"
{
bool SKSEPlugin_Query(const SKSEInterface * skse, PluginInfo * info)
{
info->infoVersion = PluginInfo::kInfoVersion;
info->name = "jp_patch";
info->version = 2;
g_pluginHandle = skse->GetPluginHandle();
if(skse->isEditor)
{
return false;
}
int addr = 0;
switch (skse->runtimeVersion)
{
case RUNTIME_VERSION_1_8_151_0:
addr = 0x0086043E;
break;
case RUNTIME_VERSION_1_9_26_0:
addr = 0x0085FEDE;
break;
case RUNTIME_VERSION_1_9_29_0:
addr = 0x0086006E;
break;
case RUNTIME_VERSION_1_9_32_0:
addr = 0x0085FE4E;
break;
default:
return false;
}
if (addr)
{
SafeWrite8(addr, 0x51); // PUSH ECX
SafeWrite8(addr + 1, 0x50); // PUSH EAX
}
return (skse->runtimeVersion == RUNTIME_VERSION_1_9_32_0);
}
bool SKSEPlugin_Load(const SKSEInterface * skse)
{
WriteRelCall(0x00680EC9, GetFnAddr(&_BGSSaveLoadManager::FilterString));
WriteRelJump(0x00677953, (UInt32)Hook_00677953);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment