Create your AI Cum Slut -70% for Mother's Day
x

Ren'Py [Request] Help some personal patch issue

eike2000

Member
May 9, 2017
158
83
I got some problem with my patch (created for myself). I was post this threat before but just an idiot guy jump in and bla bla ... nothing solved, until I find out for myself by steal some code from other game and patched.
-- 1st : I made a patch that translate word (post include my file). It work very good but with some case it appear not. Example : bang us then it appear bang us with red color same with banged us, banging us but if bang me, bang them, bang her. it just appear bang me, bang them, bang her. (same with creampie us is good , not for creampie me, creampie her or estrusing animal are good but estrusing animals is not). What's wrong in my codes?
-- 2nd : How could hack into a label ingame? I mean I'm not change the orginal file, I made some patch, in script of game there are labels, if get in to this label (basic, in orginal file there is not have a variable, then I use a patch add variable into this label). Example : Main character is a lost boy, he meet a woman, he call her by name and later, he knew that woman is his aunt, then he start to address her name is auntie. Yes, my patch made he address her name is auntie but it stuck with some label before (when he still unknown she is his aunt). I tried for renpy.seen_label but if load saved before, it make all woman's name turn into aunt, so these is not solve.
-- 3th : key 'p' action [ToggleVariable("quick_menu",False,True)] work good but with some game, press p is unactive, if try for key 'K_p' action [ToggleVariable("quick_menu",False,True)] is work, but some game from (a-z) key is unwork, just only F1,F2, ...F12. And I learn that renpy function : CycleVariable , but it always make error.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,807
18,241
I got some problem with my patch
Wow... What the hell is this?

I have the answer to your question, but first a bit of code 101, it will be useful for the future. If you don't want to learn, just jump at the end of the post...


First thing first, why the fuck this:
Code:
        for i in ['[player_name]','[player_name!c]','[player_name!t]','[player_name!ct]','[player_name!tc]'] :
            text = text.replace( i , "pielustous".capitalize())
        text = text.replace('[player_name!u]', "pielustous".upper())
You replace all occurrence of Ren'Py displaying the content of the variable named "player_name", by a text, that will always be the same...

Therefore I have a question for you:
Why something so complex when a basic player_name = "pielustous" in the console would have the exact same result, and wouldn't need to be done more than once by playthrough?

It's not like enabling the console is more complex than adding config.console = True in your rpy file.

Note that the same apply for the three following lines, that address "xlasname".


There's also this part:
Code:
        for i in [
            "Cum inside me","cum inside me","Cumming inside me","cumming inside me", [...] "Bang us", "bang us", "Bang me", ] :
            text = text.replace( i , randxcolor+(i).title()+ "{/b}{/color}")
That have a hell big list...
Since you already use title(), you can perfectly make it way smaller by normalizing the input:
Code:
        for i.lower() in [
            "cum inside me", "cumming inside me", [...] "bang us", "bang me", ] :
            text = text.replace( i , randxcolor+(i).title()+ "{/b}{/color}")
But this is secondary, because I guess that it's your fix for the issue you describe. Just know that it's totally possible and can significantly lower your lists.


And this part:
Code:
            x_cl = renpy.random.randint(1,5)
            if x_cl == 1:
                prefix = "{color=#EF1221}{b}"
            elif x_cl == 2:
                prefix = "{color=#FE12EF}{b}"
            elif x_cl == 3:
                prefix = "{color=#12FEEF}{b}"
            elif x_cl == 4:
                prefix = "{color=#FF7712}{b}"
            else:
                prefix = "{color=#12EF21}{b}"
            suffix = "{/b}{/color}"
Why something so complex, when you already did this:
Code:
        randxcolor = renpy.random.choice(['{color=#EF1221}{b}', '{color=#FE12EF}{b}', '{color=#12FEEF}{b}', '{color=#FF7712}{b}', '{color=#12EF21}{b}'],)
[...]
            text = text.replace( i , randxcolor+(i)+ "{/b}{/color}")
That you want another color than the one already picked, okay, why not, but why pass through an if structure since you already know a better way to do it?


And there this part:
Code:
    replace_dict = {
        'pielustous': "pielustous",
        'weincestt': "weincestt",
        'the goddesses': "the goddesses",
        'the goddess': "the goddess",
[...]
            if match.group(0).isupper():
                value = replace_dict[key].upper()
            elif match.group(0).istitle():
                value = replace_dict[key].title()
            else:
                value = replace_dict[key].title()
I can have missed some, but in your near to 2000 entries dictionary, there's less than two dozen times where the value do not correspond to the key...

Make them an exception, and use a list for the rest:
Code:
    replace_list = [
        'pielustous',  'weincestt',
        'the goddesses', 'the goddess',
        [...]
    replace_dict = {
        'brother and sisters': "siblings",
        'brother and sister': "siblings",
        'sisters and brother': "siblings",
        'sister and brother': "siblings",
        [...]
Then you modify a bit your "translate" function:
Code:
        def translate(match):
            key = match.group(0).lower()
            x_cl = renpy.random.choice( [...]
            suffix = "{/b}{/color}"
            value = ""

            if match.group(0).isupper():
                if key in replace_dict:  # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.upper()
            elif match.group(0).istitle():
                if key in replace_dict: # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.title()
            else:
                if key in replace_dict: # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.title()
            return prefix + value + suffix
Then you use this:
Code:
        #  Proceed to the default substitutions
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_list)), re.I)
        text = rc.sub(translate, text)

        #  Then deal with the exceptions.
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict)), re.I)
        return rc.sub(translate, text)

Regarding the "replace_dict", there's also the struggle with all those:
Code:
    ### ----------------------------------------------------
        'the queens': "the queens",
        'your queens': "your queens",
        'our queens': "our queens",
        'his queens': "his queens",
        'my queens': "my queens",
        'queens': "queens",
        ### ----------------------------------------------------
        'the queen': "the queen",
        'your queen': "your queen",
        'our queen': "our queen",
        'his queen': "his queen",
        'my queen': "my queen",
        'queen': "queen",
    ### ----------------------------------------------------
        'the princesses': "the princesses",
        'your princesses': "your princesses",
        'our princesses': "our princesses",
        'his princesses': "his princesses",
        'my princesses': "my princesses",
        'princesses': "princesses",
    ### ----------------------------------------------------
        'the princess': "the princess",
        'your princess': "your princess",
        'our princess': "our princess",
        'his princess': "his princess",
        'my princess': "my princess",
        'princess': "princess",
Since you use regEx, and like you don't need a dict here, use the regEx totally.
Code:
    "(?:(?:the|y?our|his|my) )?queen(?:s)?"
    "(?:(?:the|y?our|his|my) )?princess(?:es)?"
1 line for each group of 12 entries...

It would help to clear up a bit your code and, despite the fact that the regEx is now more complex, it would be a bit faster. This without changing the result since you'll still get, and works with, the string as it is written.


All this being said...
A translation file should do exactly the same than your long list, while also getting rid of your problem:
Code:
translate None strings:

    old 'the goddesses'
    new "{color=#EF1221}{b}the goddesses{/b}{/color}"

    old 'the goddess'
    new "{color=#EF1221}{b}the goddess{/b}{/color}"

    old 'my goddesses'
    new "{color=#EF1221}{b}my goddesses{/b}{/color}"

    old 'brother and sisters'
    new "{color=#EF1221}{b}siblings{/b}{/color}"
[...]
Name it "myFix.rpy", drop it in the "game" directory (I don't see why it would need to be in the "tl" one), and normally it should works.
It remove the randomness for the color, but is it really this important? Anyway there's a way to also deal with this, but it's more advanced.



Now, for the problem you encounter...

It work very good but with some case it appear not. Example : bang us then it appear bang us with red color same with banged us, banging us but if bang me, bang them, bang her. it just appear bang me, bang them, bang her.
You use a dictionary as entry, and the fact is that dictionaries are not ordered.
You've this:
Code:
        'banged you': "banged you",
        'banged her': "banged her",
        'banged me': "banged me",
        'bang you': "bang you",
        'bang her': "bang her",
        'bang me': "bang me",
        'banging': "banging",
        'banged': "banged",
        'bangs': "bangs",
        'bang': "bang",
In the source, it looks good, "bang" will be the last tested value. But it happen that when the code will come to:
Code:
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict)), re.I)
The order will be different. This will make "bang" appear sooner in the list, before the entries for "bang me", "bang them" and "bang her". Therefore, the regEx will never test those three, because it already have a match for "bang".

It's the reason why using a list is preferable, in addition to the fact that a dictionary isn't needed.
As well as the reason why using actual regEx in place of just a list of word is also preferable, in addition to the fact that it lower the number of entries.

List are ordoned, therefore "bang me", "bang them", and "bang her" will always appear before "bang", what solve your issue.
And something like "bang(?:(?:ing|ed) )?(?:you|her|me)?" will always catch the biggest match, therefore it will catch "bang me" and "bang her" when they are present.

Side note: You have no entries for "bang them", whatever the declinaison for "bang".
 
  • Like
Reactions: gojira667

eike2000

Member
May 9, 2017
158
83
Wow... What the hell is this?

I have the answer to your question, but first a bit of code 101, it will be useful for the future. If you don't want to learn, just jump at the end of the post...


First thing first, why the fuck this:
Code:
        for i in ['[player_name]','[player_name!c]','[player_name!t]','[player_name!ct]','[player_name!tc]'] :
            text = text.replace( i , "pielustous".capitalize())
        text = text.replace('[player_name!u]', "pielustous".upper())
You replace all occurrence of Ren'Py displaying the content of the variable named "player_name", by a text, that will always be the same...

Therefore I have a question for you:
Why something so complex when a basic player_name = "pielustous" in the console would have the exact same result, and wouldn't need to be done more than once by playthrough?

It's not like enabling the console is more complex than adding config.console = True in your rpy file.

Note that the same apply for the three following lines, that address "xlasname".


There's also this part:
Code:
        for i in [
            "Cum inside me","cum inside me","Cumming inside me","cumming inside me", [...] "Bang us", "bang us", "Bang me", ] :
            text = text.replace( i , randxcolor+(i).title()+ "{/b}{/color}")
That have a hell big list...
Since you already use title(), you can perfectly make it way smaller by normalizing the input:
Code:
        for i.lower() in [
            "cum inside me", "cumming inside me", [...] "bang us", "bang me", ] :
            text = text.replace( i , randxcolor+(i).title()+ "{/b}{/color}")
But this is secondary, because I guess that it's your fix for the issue you describe. Just know that it's totally possible and can significantly lower your lists.


And this part:
Code:
            x_cl = renpy.random.randint(1,5)
            if x_cl == 1:
                prefix = "{color=#EF1221}{b}"
            elif x_cl == 2:
                prefix = "{color=#FE12EF}{b}"
            elif x_cl == 3:
                prefix = "{color=#12FEEF}{b}"
            elif x_cl == 4:
                prefix = "{color=#FF7712}{b}"
            else:
                prefix = "{color=#12EF21}{b}"
            suffix = "{/b}{/color}"
Why something so complex, when you already did this:
Code:
        randxcolor = renpy.random.choice(['{color=#EF1221}{b}', '{color=#FE12EF}{b}', '{color=#12FEEF}{b}', '{color=#FF7712}{b}', '{color=#12EF21}{b}'],)
[...]
            text = text.replace( i , randxcolor+(i)+ "{/b}{/color}")
That you want another color than the one already picked, okay, why not, but why pass through an if structure since you already know a better way to do it?


And there this part:
Code:
    replace_dict = {
        'pielustous': "pielustous",
        'weincestt': "weincestt",
        'the goddesses': "the goddesses",
        'the goddess': "the goddess",
[...]
            if match.group(0).isupper():
                value = replace_dict[key].upper()
            elif match.group(0).istitle():
                value = replace_dict[key].title()
            else:
                value = replace_dict[key].title()
I can have missed some, but in your near to 2000 entries dictionary, there's less than two dozen times where the value do not correspond to the key...

Make them an exception, and use a list for the rest:
Code:
    replace_list = [
        'pielustous',  'weincestt',
        'the goddesses', 'the goddess',
        [...]
    replace_dict = {
        'brother and sisters': "siblings",
        'brother and sister': "siblings",
        'sisters and brother': "siblings",
        'sister and brother': "siblings",
        [...]
Then you modify a bit your "translate" function:
Code:
        def translate(match):
            key = match.group(0).lower()
            x_cl = renpy.random.choice( [...]
            suffix = "{/b}{/color}"
            value = ""

            if match.group(0).isupper():
                if key in replace_dict:  # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.upper()
            elif match.group(0).istitle():
                if key in replace_dict: # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.title()
            else:
                if key in replace_dict: # Update the value if it's parts of the exceptions.
                    key = replace_dict[key]
                value = key.title()
            return prefix + value + suffix
Then you use this:
Code:
        #  Proceed to the default substitutions
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_list)), re.I)
        text = rc.sub(translate, text)

        #  Then deal with the exceptions.
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict)), re.I)
        return rc.sub(translate, text)

Regarding the "replace_dict", there's also the struggle with all those:
Code:
    ### ----------------------------------------------------
        'the queens': "the queens",
        'your queens': "your queens",
        'our queens': "our queens",
        'his queens': "his queens",
        'my queens': "my queens",
        'queens': "queens",
        ### ----------------------------------------------------
        'the queen': "the queen",
        'your queen': "your queen",
        'our queen': "our queen",
        'his queen': "his queen",
        'my queen': "my queen",
        'queen': "queen",
    ### ----------------------------------------------------
        'the princesses': "the princesses",
        'your princesses': "your princesses",
        'our princesses': "our princesses",
        'his princesses': "his princesses",
        'my princesses': "my princesses",
        'princesses': "princesses",
    ### ----------------------------------------------------
        'the princess': "the princess",
        'your princess': "your princess",
        'our princess': "our princess",
        'his princess': "his princess",
        'my princess': "my princess",
        'princess': "princess",
Since you use regEx, and like you don't need a dict here, use the regEx totally.
Code:
    "(?:(?:the|y?our|his|my) )?queen(?:s)?"
    "(?:(?:the|y?our|his|my) )?princess(?:es)?"
1 line for each group of 12 entries...

It would help to clear up a bit your code and, despite the fact that the regEx is now more complex, it would be a bit faster. This without changing the result since you'll still get, and works with, the string as it is written.


All this being said...
A translation file should do exactly the same than your long list, while also getting rid of your problem:
Code:
translate None strings:

    old 'the goddesses'
    new "{color=#EF1221}{b}the goddesses{/b}{/color}"

    old 'the goddess'
    new "{color=#EF1221}{b}the goddess{/b}{/color}"

    old 'my goddesses'
    new "{color=#EF1221}{b}my goddesses{/b}{/color}"

    old 'brother and sisters'
    new "{color=#EF1221}{b}siblings{/b}{/color}"
[...]
Name it "myFix.rpy", drop it in the "game" directory (I don't see why it would need to be in the "tl" one), and normally it should works.
It remove the randomness for the color, but is it really this important? Anyway there's a way to also deal with this, but it's more advanced.



Now, for the problem you encounter...



You use a dictionary as entry, and the fact is that dictionaries are not ordered.
You've this:
Code:
        'banged you': "banged you",
        'banged her': "banged her",
        'banged me': "banged me",
        'bang you': "bang you",
        'bang her': "bang her",
        'bang me': "bang me",
        'banging': "banging",
        'banged': "banged",
        'bangs': "bangs",
        'bang': "bang",
In the source, it looks good, "bang" will be the last tested value. But it happen that when the code will come to:
Code:
        rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict)), re.I)
The order will be different. This will make "bang" appear sooner in the list, before the entries for "bang me", "bang them" and "bang her". Therefore, the regEx will never test those three, because it already have a match for "bang".

It's the reason why using a list is preferable, in addition to the fact that a dictionary isn't needed.
As well as the reason why using actual regEx in place of just a list of word is also preferable, in addition to the fact that it lower the number of entries.

List are ordoned, therefore "bang me", "bang them", and "bang her" will always appear before "bang", what solve your issue.
And something like "bang(?:(?:ing|ed) )?(?:you|her|me)?" will always catch the biggest match, therefore it will catch "bang me" and "bang her" when they are present.

Side note: You have no entries for "bang them", whatever the declinaison for "bang".
First, I must say both thank and no thank to you.
----------------------------------------------------------------------------------------------------------------------
-- 1st -- I say No thanks because, I was post this threat 2 times and all you just told me something bla bla .. like it can't be done, must use notepad search and replace ... while I trully need solution not a negative reason. I DON'T fix orginal script, I made patch for myself. Last post I still used text.replace and get problem with mom and momment (mom and momment, momo or sis and sissy). And after that i tried for some post and learn myself, then i made this patch for myself, in find out use dict (i don't know RegEX, I am not a coder, never learn anything about coding, just read and think and try). I ignored your post and waited for more answer while still tried more with read other member's attach files, thinks, and try. And this time, when I saw your answer, I wanna scream "WTF, you again?".
----------------------------------------------------------------------------------------------------------------------
-- 2nd -- This time, I say THANKS. trully, I SAY THANK YOU. But it still not solve my issues. There are some reason :
1 -- I'm not a coder so ... I trully don't understand what you posted in this threat, or understand but not much, maybe 1%.
2 -- I using dict because : 1st it's the way I find out, actually I don't understand what I coded, include "re.complie" is meaning and how its formular? However I find out that the dict translate top to bottom, that way I use bang me, bang us, ... bang with banging > banged > bang because banging = bang + ing, banged = bang+ed, bang = bang+[none], so it work good, and as you said, the dict is too many then make it not work good. I know it, That's why I post this threat.
----------------------------------------------------------------------------------------------------------------------
for i in ['[player_name]','[player_name!c]','[player_name!t]','[player_name!ct]','[player_name!tc]'] :
text = text.replace( i , "pielustous".capitalize())
text = text.replace('[player_name!u]', "pielustous".upper())
Well, I made this because it not use for one game. Example the game "The lust city (1&2)", creator made game with name="jack", then he lowcase the [name], and in script, he used [mc!c], [mc!ct], [mc!tc] bla, bla ... With my patch use to recolor the text so [mc] is has color, but if tried for your ways then [mc!c] is not, same for [mc!ct]. And for other games, sometime they use [mc!u] in scream. Have you got any better idear? plz guide me
----------------------------------------------------------------------------------------------------------------------
for i.lower() in [cum inside me", "cumming inside me", [...] "bang us", "bang me", ] :
text = text.replace( i , randxcolor+(i).title()+ "{/b}{/color}")
This was I think early but what if text is CUM INSIDE ME? (i mean "cum inside me" with uppcase?) And I tried for some case other like "cum inside me" (in textline), Cum inside me (first in textline) and CUM INSIDE ME (All caps). If use dict like my patch then it solve the problem of UPPER CASE, lower case and Sentence case. UPPER CASE still upper, lower and Sentence are tittle. Have you got any better idear? plz guide me
----------------------------------------------------------------------------------------------------------------------
def translate(match):
key = match.group(0).lower()
x_cl = renpy.random.choice( [...]
suffix = "{/b}{/color}"
value = ""

if match.group(0).isupper():
if key in replace_dict: # Update the value if it's parts of the exceptions.
key = replace_dict[key]
value = key.upper()
elif match.group(0).istitle():
if key in replace_dict: # Update the value if it's parts of the exceptions.
key = replace_dict[key]
value = key.title()
else:
if key in replace_dict: # Update the value if it's parts of the exceptions.
key = replace_dict[key]
value = key.title()
return prefix + value + suffix
Well, this trully a good answer, I like it, Thank you. But it made a little I don't like. example "I'm your whore, please bang me and creampie me, master", with my code, it appear random color for each word in dict : "Whore","Bang me", "Creampie me" got color for each one like "I'm Your Whore, please Bang Me and Creampie Me, Master". Use you code, (Not use x_cl) it solve the problem I can deleted line replace text "Bang me, bang me..." but this phrase is "I'm Your Whore, please Bang Me and Creampie Me, Master", all words in phrase with same color. THANK YOU.
----------------------------------------------------------------------------------------------------------------------
"(?:(?:the|y?our|his|my) )?queen(?:s)?"
"(?:(?:the|y?our|his|my) )?princess(?:es)?"
I'm trully not got idea how to use it, where I put this line, i tried fix in dict ... unwork, try
search = "(?:(?:the|y?our|his|my) )?queen(?:s)?"
if search in text :
text=text.replace(search, randcolor + search + "{/b}{/color}")
return text
... Unwork. But if I don't wrong, It just replace text lower case, useless in Sentence case and UPPER CASE, right? Then I think, just think, if use dict i just need 5 line for completed, but your code need 9 line for The|Y?Our|His|My) )?Queen(?:s)?" and "(?:(?:THE|Y?OUR|HIS|MY) )?QUEEN(?:s)?". However, It will so good with my biological mother|father|sister|brother|sis|bro|cousin|aunt|auntie ... well it save a lot of lines. I need learn for this code more.
THANK YOU. AND PLEASE GUIDE ME MORE.
----------------------------------------------------------------------------------------------------------------------
translate None strings:

old 'the goddesses'
new "{color=#EF1221}{b}the goddesses{/b}{/color}"

old 'the goddess'
new "{color=#EF1221}{b}the goddess{/b}{/color}"

old 'my goddesses'
new "{color=#EF1221}{b}my goddesses{/b}{/color}"

old 'brother and sisters'
new "{color=#EF1221}{b}siblings{/b}{/color}"
[...]
I'm NOT understand anything. I see you post you attact file "myFix" but I don't see it, I don't find out link to download.
----------------------------------------------------------------------------------------------------------------------
rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict)), re.I)
rc = re.compile('\\b|\\b'.join(map(re.escape, replace_dict_2)), re.I)
I tried with you said, sperated dict into replace_dict and replace_dict_2, and define dev replace_dict and dev replace_dict_2. but if text in replace_dict and text in replace_dict_2 appear in a textline, just one work, left are not.
----------------------------------------------------------------------------------------------------------------------
My Problem 1 is solving, how about problem 2 and 3? Okey, problem 3 is not necessary, but I want solution for problem 2.
I'm playing "The Lust City 2", main is an explore with his group, find out a accient clan, they was helped by a goddess name Desiha, well she is god of lust, passionate and fertilizer, she was imprisoning and the tribe got enemy is general... At last, script turn into the goddess is enemy, not the general, it start with label final_combat_3. I use my patch to fix because fist the protagonist group is helped by goddess, they address her with best regards like "goddess mother" and in label final_combat_3 and later, protagonist group call her by name with unregards (She still a goddess, not demoness).
With line mc "At last, I find you, [des!u]" if i use my patch it still mc call her as "Goddess mother" while she trying to kill him, it so unreasonable. Then I tried with :
text.replace("At last, I find you, [des!u]", "At last, I find you, [des!u]", SetVariable("call_des_off", True)) >> well it wrong, I know it, but I don't know how to fix it by using patch.